ci: auto-detect patch vs full release in workflow
Build and Release / build-and-release (push) Successful in 37s
Build and Release / build-and-release (push) Successful in 37s
This commit is contained in:
@@ -4,6 +4,17 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- 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:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -14,18 +25,24 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Check if version already released
|
- name: Check if version already released
|
||||||
id: version-check
|
id: version-check
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/')
|
VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/')
|
||||||
TAG="v$VERSION"
|
TAG="v$VERSION"
|
||||||
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
echo "TAG=$TAG" >> "$GITHUB_OUTPUT"
|
echo "TAG=$TAG" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
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 "Release $TAG already exists, skipping build"
|
||||||
echo "SKIP=true" >> "$GITHUB_OUTPUT"
|
echo "SKIP=true" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
@@ -33,14 +50,64 @@ jobs:
|
|||||||
echo "SKIP=false" >> "$GITHUB_OUTPUT"
|
echo "SKIP=false" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
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) build
|
||||||
|
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
|
- name: Setup Node.js
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false'
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '22'
|
||||||
|
|
||||||
|
# Full build needs wine + system deps for electron-builder
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'full'
|
||||||
run: |
|
run: |
|
||||||
sudo dpkg --add-architecture i386
|
sudo dpkg --add-architecture i386
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
@@ -56,60 +123,147 @@ jobs:
|
|||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false'
|
||||||
run: npm ci --legacy-peer-deps
|
run: npm ci --legacy-peer-deps
|
||||||
|
|
||||||
|
# ── Patch release: asar only ──
|
||||||
|
|
||||||
|
- name: Build asar
|
||||||
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'patch'
|
||||||
|
run: npm run build:asar
|
||||||
|
|
||||||
|
# ── Full release: installer + asar ──
|
||||||
|
|
||||||
- name: Build source
|
- name: Build source
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'full'
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Build Windows distributables
|
- name: Build Windows distributables
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'full'
|
||||||
env:
|
env:
|
||||||
WINEDEBUG: "-all"
|
WINEDEBUG: "-all"
|
||||||
run: npx electron-builder --win -c.electronDist=node_modules/electron/dist-win --publish never
|
run: npx electron-builder --win -c.electronDist=node_modules/electron/dist-win --publish never
|
||||||
|
|
||||||
- name: Build Linux distributables
|
- name: Build Linux distributables
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'full'
|
||||||
run: npx electron-builder --linux -c.electronDist=node_modules/electron/dist-linux --publish never
|
run: npx electron-builder --linux -c.electronDist=node_modules/electron/dist-linux --publish never
|
||||||
|
|
||||||
|
- name: Build asar for full release
|
||||||
|
if: steps.version-check.outputs.SKIP == 'false' && steps.release-type.outputs.TYPE == 'full'
|
||||||
|
run: npm run build:asar
|
||||||
|
|
||||||
- name: Report build sizes
|
- name: Report build sizes
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false'
|
||||||
run: |
|
run: |
|
||||||
echo "=== Build output sizes ==="
|
echo "=== Release type: ${{ steps.release-type.outputs.TYPE }} ==="
|
||||||
ls -lh out/*.exe out/*.AppImage out/*.deb 2>/dev/null || true
|
if [ "${{ steps.release-type.outputs.TYPE }}" = "full" ]; then
|
||||||
|
ls -lh out/*.exe out/*.AppImage out/*.deb 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
ls -lh out/asar/* 2>/dev/null || true
|
||||||
|
|
||||||
- name: Generate release notes
|
- name: Generate release notes
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false'
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
git fetch --unshallow 2>/dev/null || true
|
|
||||||
chmod +x scripts/generate-release-notes.sh
|
chmod +x scripts/generate-release-notes.sh
|
||||||
scripts/generate-release-notes.sh "${{ steps.version-check.outputs.TAG }}" > /tmp/release-notes.md
|
|
||||||
|
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 ---"
|
echo "--- Generated release notes ---"
|
||||||
cat /tmp/release-notes.md
|
cat /tmp/release-notes.md
|
||||||
|
|
||||||
- name: Create GitHub release and upload assets
|
- name: Create release and upload assets
|
||||||
if: steps.version-check.outputs.SKIP == 'false'
|
if: steps.version-check.outputs.SKIP == 'false'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.DEST_GITEA_TOKEN }}
|
||||||
|
TAG: ${{ steps.version-check.outputs.TAG }}
|
||||||
|
RELEASE_TYPE: ${{ steps.release-type.outputs.TYPE }}
|
||||||
run: |
|
run: |
|
||||||
# Collect built artifacts
|
GITEA_BASE="https://gitea.crjlab.net"
|
||||||
ASSETS=()
|
REPO="bigjakk/Krunker-Civilian-Client-Test"
|
||||||
for file in out/*.exe out/*.AppImage out/*.deb; do
|
|
||||||
[ -f "$file" ] || continue
|
|
||||||
ASSETS+=("$file")
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ${#ASSETS[@]} -eq 0 ]; then
|
# Create tag
|
||||||
echo "ERROR: No build artifacts found in out/"
|
curl -s -X POST "$GITEA_BASE/api/v1/repos/$REPO/tags" \
|
||||||
ls -la out/ 2>/dev/null || echo "out/ directory does not exist"
|
-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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Uploading ${#ASSETS[@]} assets:"
|
# Upload asar + checksums (both patch and full releases)
|
||||||
printf ' %s\n' "${ASSETS[@]}"
|
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
|
||||||
|
|
||||||
gh release create "${{ steps.version-check.outputs.TAG }}" \
|
# Upload installer artifacts (full release only)
|
||||||
--repo "$GITHUB_REPOSITORY" \
|
if [ "$RELEASE_TYPE" = "full" ]; then
|
||||||
--title "${{ steps.version-check.outputs.TAG }}" \
|
for file in out/*.exe out/*.AppImage out/*.deb; do
|
||||||
--notes-file /tmp/release-notes.md \
|
[ -f "$file" ] || continue
|
||||||
--draft=false \
|
FILENAME=$(basename "$file")
|
||||||
--latest \
|
SAFE_NAME=$(echo "$FILENAME" | tr ' ' '_')
|
||||||
"${ASSETS[@]}"
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All assets uploaded (release type: $RELEASE_TYPE)"
|
||||||
|
|
||||||
|
- 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user