261 lines
9.8 KiB
YAML
261 lines
9.8 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
release_type:
|
|
description: 'Override release type (auto-detected by default)'
|
|
required: false
|
|
default: 'auto'
|
|
type: choice
|
|
options:
|
|
- auto
|
|
- patch
|
|
- full
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build-and-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Check if version already released
|
|
id: version-check
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
|
run: |
|
|
VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/')
|
|
TAG="v$VERSION"
|
|
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "TAG=$TAG" >> "$GITHUB_OUTPUT"
|
|
|
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
"https://gitea.crjlab.net/api/v1/repos/bigjakk/Krunker-Civilian-Client-Test/releases/tags/$TAG" \
|
|
-H "Authorization: token $GITEA_TOKEN")
|
|
|
|
if [ "$STATUS" = "200" ]; then
|
|
echo "Release $TAG already exists, skipping build"
|
|
echo "SKIP=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "No release for $TAG, proceeding with build"
|
|
echo "SKIP=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Detect release type
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
id: release-type
|
|
run: |
|
|
OVERRIDE="${{ github.event.inputs.release_type || 'auto' }}"
|
|
|
|
if [ "$OVERRIDE" != "auto" ]; then
|
|
echo "Release type overridden to: $OVERRIDE"
|
|
echo "TYPE=$OVERRIDE" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
# Auto-detect: find what changed since the last release tag
|
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
|
|
|
|
if [ -z "$PREV_TAG" ]; then
|
|
echo "No previous tag found — defaulting to full build"
|
|
echo "TYPE=full" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Comparing changes since $PREV_TAG"
|
|
CHANGED=$(git diff --name-only "$PREV_TAG"..HEAD)
|
|
echo "$CHANGED"
|
|
|
|
# Files that require a full (installer-only) release
|
|
FULL_TRIGGERS="electron-builder.yml|scripts/download-electron.js"
|
|
|
|
if echo "$CHANGED" | grep -qE "^($FULL_TRIGGERS)$"; then
|
|
echo "Full build trigger detected in changed files"
|
|
echo "TYPE=full" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
# Check if package.json deps changed (not just version field)
|
|
if echo "$CHANGED" | grep -q "^package.json$"; then
|
|
DEP_DIFF=$(git diff "$PREV_TAG"..HEAD -- package.json \
|
|
| grep -E '^\+' | grep -vE '^\+\+\+' \
|
|
| grep -E '"(dependencies|devDependencies|electron|electron-nightly)"' || true)
|
|
if [ -n "$DEP_DIFF" ]; then
|
|
echo "Dependency changes detected in package.json"
|
|
echo "TYPE=full" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
echo "Only source changes detected — patch release"
|
|
echo "TYPE=patch" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Setup Node.js
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
|
|
- name: Install system dependencies
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
run: |
|
|
sudo dpkg --add-architecture i386
|
|
sudo apt-get update -qq
|
|
sudo apt-get install -y --no-install-recommends \
|
|
wine wine32 wine64 \
|
|
libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2t64 \
|
|
libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
|
|
libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 \
|
|
libcairo2 libasound2t64 libgtk-3-0
|
|
WINEDEBUG=-all wine wineboot --init || true
|
|
|
|
- name: Install dependencies
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Build source
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
run: npm run build
|
|
|
|
- name: Build Windows distributables
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
env:
|
|
WINEDEBUG: "-all"
|
|
run: npx electron-builder --win -c.electronDist=node_modules/electron/dist-win --publish never
|
|
|
|
- name: Build Linux distributables
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
run: npx electron-builder --linux -c.electronDist=node_modules/electron/dist-linux --publish never
|
|
|
|
- name: Build asar for patch updates
|
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'patch'
|
|
run: npm run build:asar
|
|
|
|
- name: Report build sizes
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
run: |
|
|
echo "=== Release type: ${{ steps.release-type.outputs.TYPE }} ==="
|
|
ls -lh out/*.exe out/*.AppImage out/*.deb 2>/dev/null || true
|
|
ls -lh out/asar/* 2>/dev/null || true
|
|
|
|
- name: Generate release notes
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
|
run: |
|
|
chmod +x scripts/generate-release-notes.sh
|
|
|
|
PREV_SHA=$(curl -s "https://gitea.crjlab.net/api/v1/repos/bigjakk/Krunker-Civilian-Client-Test/releases?limit=1" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
| jq -r '.[0].target_commitish // empty' 2>/dev/null || true)
|
|
|
|
echo "Previous release SHA: ${PREV_SHA:-none}"
|
|
scripts/generate-release-notes.sh "${{ steps.version-check.outputs.TAG }}" "$PREV_SHA" > /tmp/release-notes.md
|
|
echo "--- Generated release notes ---"
|
|
cat /tmp/release-notes.md
|
|
|
|
- name: Create release and upload assets
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
|
TAG: ${{ steps.version-check.outputs.TAG }}
|
|
RELEASE_TYPE: ${{ steps.release-type.outputs.TYPE }}
|
|
run: |
|
|
GITEA_BASE="https://gitea.crjlab.net"
|
|
REPO="bigjakk/Krunker-Civilian-Client-Test"
|
|
|
|
# Create tag
|
|
curl -s -X POST "$GITEA_BASE/api/v1/repos/$REPO/tags" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"$TAG\", \"message\": \"$TAG\", \"target\": \"$GITHUB_SHA\"}"
|
|
|
|
# Read release notes
|
|
NOTES=$(cat /tmp/release-notes.md)
|
|
BODY=$(echo "$NOTES" | python3 -c 'import sys,json; print(json.dumps(sys.stdin.read()))')
|
|
|
|
# Create release
|
|
RESPONSE=$(curl -s -X POST "$GITEA_BASE/api/v1/repos/$REPO/releases" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"$TAG\",
|
|
\"name\": \"$TAG\",
|
|
\"body\": $BODY,
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
|
echo "Created release ID: $RELEASE_ID"
|
|
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Upload asar + checksums (patch releases only — signals client to use fast path)
|
|
if [ "$RELEASE_TYPE" = "patch" ]; then
|
|
for file in out/asar/app.asar out/asar/checksums.sha256; do
|
|
[ -f "$file" ] || continue
|
|
FILENAME=$(basename "$file")
|
|
echo "Uploading: $FILENAME ($(du -h "$file" | cut -f1))"
|
|
curl -s -X POST \
|
|
"$GITEA_BASE/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILENAME" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-F "attachment=@$file" \
|
|
| jq -r '" -> \(.name) (\(.size) bytes)"'
|
|
done
|
|
else
|
|
echo "Full release — skipping asar upload (forces installer update)"
|
|
fi
|
|
|
|
# Upload installers (always — for new users and major updates)
|
|
for file in out/*.exe out/*.AppImage out/*.deb; do
|
|
[ -f "$file" ] || continue
|
|
FILENAME=$(basename "$file")
|
|
SAFE_NAME=$(echo "$FILENAME" | tr ' ' '_')
|
|
echo "Uploading: $SAFE_NAME ($(du -h "$file" | cut -f1))"
|
|
curl -s -X POST \
|
|
"$GITEA_BASE/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$SAFE_NAME" \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-F "attachment=@$file" \
|
|
| jq -r '" -> \(.name) (\(.size) bytes)"'
|
|
done
|
|
|
|
echo "All assets uploaded"
|
|
|
|
- name: Prune old releases
|
|
if: steps.version-check.outputs.SKIP == 'false'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
|
KEEP: 5
|
|
run: |
|
|
GITEA_BASE="https://gitea.crjlab.net"
|
|
REPO="bigjakk/Krunker-Civilian-Client-Test"
|
|
echo "=== Pruning $REPO (keeping last $KEEP) ==="
|
|
RELEASES=$(curl -s "$GITEA_BASE/api/v1/repos/$REPO/releases?limit=50" \
|
|
-H "Authorization: token $GITEA_TOKEN")
|
|
|
|
DELETE_IDS=$(echo "$RELEASES" | jq -r "sort_by(.created_at) | reverse | .[$KEEP:][] | .id")
|
|
|
|
for ID in $DELETE_IDS; do
|
|
TAG_NAME=$(echo "$RELEASES" | jq -r ".[] | select(.id == $ID) | .tag_name")
|
|
echo "Deleting release $TAG_NAME (id=$ID)"
|
|
curl -s -X DELETE "$GITEA_BASE/api/v1/repos/$REPO/releases/$ID" \
|
|
-H "Authorization: token $GITEA_TOKEN"
|
|
curl -s -X DELETE "$GITEA_BASE/api/v1/repos/$REPO/tags/$TAG_NAME" \
|
|
-H "Authorization: token $GITEA_TOKEN"
|
|
done
|
|
echo "Prune complete"
|