From a0aee6ddbd8fff0189f1b01bb334e7dda84af9e9 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Thu, 19 Feb 2026 20:03:19 +1100 Subject: [PATCH] feat: add version bumping and release update functionality in build workflow --- .gitea/workflows/build.yml | 118 ++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 700511f..7f446bf 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -15,8 +15,56 @@ env: RUSTUP_MAX_RETRIES: 10 jobs: + increment-version: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, '[skip ci]') + outputs: + version: ${{ steps.bump.outputs.VERSION }} + should_build: ${{ steps.bump.outputs.SHOULD_BUILD }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Bump patch version + id: bump + run: | + # Get current version + CURRENT=$(grep -Po '"version":\s*"\K[^"]+' src-tauri/tauri.conf.json | head -1) + echo "Current version: $CURRENT" + + # Split and increment patch + MAJOR=$(echo $CURRENT | cut -d. -f1) + MINOR=$(echo $CURRENT | cut -d. -f2) + PATCH=$(echo $CURRENT | cut -d. -f3) + NEW_PATCH=$((PATCH + 1)) + NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" + echo "New version: $NEW_VERSION" + + # Update tauri.conf.json + sed -i "s/\"version\": \"${CURRENT}\"/\"version\": \"${NEW_VERSION}\"/" src-tauri/tauri.conf.json + + # Verify the change + grep '"version"' src-tauri/tauri.conf.json | head -1 + + echo "VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "SHOULD_BUILD=true" >> $GITHUB_OUTPUT + + - name: Commit and push version bump + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add src-tauri/tauri.conf.json + git commit -m "chore: bump version to ${{ steps.bump.outputs.VERSION }} [skip ci]" + git push + build-windows: runs-on: windows + needs: increment-version + if: always() && (needs.increment-version.outputs.should_build == 'true' || needs.increment-version.result == 'skipped') env: CARGO_TARGET_DIR: C:\cargo-cache\cinny-desktop @@ -28,6 +76,11 @@ jobs: ref: ${{ github.ref_name }} clean: false + - name: Pull latest (after version bump) + if: github.ref == 'refs/heads/main' + shell: powershell + run: git pull origin main + - name: Checkout submodules (Windows workaround) shell: powershell run: | @@ -91,6 +144,8 @@ jobs: build-linux: runs-on: ubuntu-latest + needs: increment-version + if: always() && (needs.increment-version.outputs.should_build == 'true' || needs.increment-version.result == 'skipped') env: CARGO_TARGET_DIR: /home/runner/cargo-cache/cinny-desktop @@ -101,6 +156,10 @@ jobs: submodules: recursive ref: ${{ github.ref_name }} + - name: Pull latest (after version bump) + if: github.ref == 'refs/heads/main' + run: git pull origin main + - name: Setup Node.js uses: actions/setup-node@v4 with: @@ -174,6 +233,8 @@ jobs: build-android: runs-on: windows + needs: increment-version + if: always() && (needs.increment-version.outputs.should_build == 'true' || needs.increment-version.result == 'skipped') env: CARGO_TARGET_DIR: C:\cargo-cache\cinny-desktop-android @@ -185,6 +246,11 @@ jobs: ref: ${{ github.ref_name }} clean: false + - name: Pull latest (after version bump) + if: github.ref == 'refs/heads/main' + shell: powershell + run: git pull origin main + - name: Checkout submodules (Windows workaround) shell: powershell run: | @@ -310,7 +376,7 @@ jobs: create-release: runs-on: ubuntu-latest - needs: [build-windows, build-linux, build-android] + needs: [increment-version, build-windows, build-linux, build-android] if: always() && (needs.build-windows.result == 'success' || needs.build-linux.result == 'success') steps: @@ -318,11 +384,21 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ github.ref_name }} + + - name: Pull latest (after version bump) + if: github.ref == 'refs/heads/main' + run: git pull origin main - name: Get version id: version run: | - VERSION=$(grep -Po '"version":\s*"\K[^"]+' src-tauri/tauri.conf.json | head -1) + # Use version from increment-version job if available, otherwise read from file + if [ -n "${{ needs.increment-version.outputs.version }}" ]; then + VERSION="${{ needs.increment-version.outputs.version }}" + else + VERSION=$(grep -Po '"version":\s*"\K[^"]+' src-tauri/tauri.conf.json | head -1) + fi echo "VERSION=$VERSION" >> $GITHUB_OUTPUT echo "Version: $VERSION" @@ -437,3 +513,41 @@ jobs: done echo "Release complete!" + + # Also update 'latest' release with update.json for auto-updater + echo "Updating 'latest' release..." + LATEST_TAG="latest" + LATEST_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \ + "${API_BASE}/repos/${REPO}/releases/tags/${LATEST_TAG}" | jq -r '.id // empty') + + if [ -z "$LATEST_ID" ]; then + echo "Creating 'latest' release..." + LATEST_ID=$(curl -s -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"${LATEST_TAG}\", \"name\": \"Latest Release\", \"body\": \"Always points to the most recent version (${VERSION})\", \"draft\": false, \"prerelease\": false}" \ + "${API_BASE}/repos/${REPO}/releases" | jq -r '.id') + else + # Update release body + curl -s -X PATCH \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"body\": \"Always points to the most recent version (${VERSION})\"}" \ + "${API_BASE}/repos/${REPO}/releases/${LATEST_ID}" + # Delete existing update.json asset + LATEST_ASSETS=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \ + "${API_BASE}/repos/${REPO}/releases/${LATEST_ID}/assets" | jq -r '.[] | select(.name=="update.json") | .id') + for ASSET_ID in $LATEST_ASSETS; do + curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" \ + "${API_BASE}/repos/${REPO}/releases/${LATEST_ID}/assets/${ASSET_ID}" + done + fi + + # Upload update.json to latest + curl -s -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@release-files/update.json" \ + "${API_BASE}/repos/${REPO}/releases/${LATEST_ID}/assets?name=update.json" + + echo "Latest release updated!"