From 80bc6793c7d76267e45995bd7e6a9fb8b34e98e8 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Fri, 29 Aug 2025 13:45:14 -0600 Subject: [PATCH] ci: Updated the release flow to also update the Cargo.toml version automatically --- .actrc | 1 + .github/workflows/release.yml | 61 ++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/.actrc b/.actrc index 7066e96..151033e 100644 --- a/.actrc +++ b/.actrc @@ -1,3 +1,4 @@ --artifact-server-path=./.act/artifacts --cache-server-path=./.act/cache +--container-options --privileged --env ACT=true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37da514..ae3e4db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -87,11 +87,44 @@ jobs: echo "prev_version=$PREV_TAG" >> $GITHUB_ENV - name: Bump Cargo.toml version + shell: bash + working-directory: ${{ github.workspace }} + env: + VERSION: ${{ env.version }} run: | - sed -E -i '/^name = "managarr"$/ { n; s|^version = "[^"]*"|version = "'"${{ env.version }}"'"| }' Cargo.toml - cargo update - git add Cargo.toml Cargo.lock - git commit -m "chore: Bump the version in Cargo.toml" + set -euo pipefail + : "${VERSION:?env.version is empty}" + + # Ignore Act's local artifact dir noise + echo artifacts/ >> .git/info/exclude || true + + # Edit the version line right after name="managarr" + sed -E -i ' + /^[[:space:]]*name[[:space:]]*=[[:space:]]*"managarr"[[:space:]]*$/ { + n + s|^[[:space:]]*version[[:space:]]*=[[:space:]]*"[^"]*"|version = "'"$VERSION"'"| + } + ' Cargo.toml + + cargo update || true + + # Git config that helps in containers (Act) + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + # Debug: show what changed + git status --porcelain + git diff --name-only -- Cargo.toml Cargo.lock || true + + # Only commit if one of these files actually changed + if ! git diff --quiet -- Cargo.toml Cargo.lock; then + # Stage only modifications of already tracked files (won't pick up artifacts/) + git add -u -- Cargo.toml Cargo.lock + git commit -m "chore: bump Cargo.toml to $VERSION" + else + echo "No changes to commit (already at $VERSION)" + fi - name: Generate changelog for the version bump id: changelog @@ -112,6 +145,15 @@ jobs: with: path: artifacts + - name: Upload the changed Cargo files (Act) + if: env.ACT == 'true' + uses: actions/upload-artifact@v4 + with: + name: bumped-cargo-files + path: | + Cargo.toml + Cargo.lock + build-release-artifacts: name: build-release needs: [bump-version] @@ -150,10 +192,18 @@ jobs: fetch-depth: 1 - name: Ensure repository is up-to-date + if: env.ACT != 'true' run: | git fetch --all git pull + - name: Get bumped Cargo files (Act) + if: env.ACT == 'true' + uses: actions/download-artifact@v4 + with: + name: bumped-cargo-files + path: ${{ github.workspace }} + - uses: actions/cache@v3 name: Cache Cargo registry with: @@ -268,6 +318,7 @@ jobs: merge-multiple: true - name: Ensure repository is up-to-date + if: env.ACT != 'true' run: | git fetch --all git pull @@ -450,6 +501,7 @@ jobs: merge-multiple: true - name: Ensure repository is up-to-date + if: env.ACT != 'true' run: | git fetch --all git pull @@ -502,6 +554,7 @@ jobs: fetch-depth: 0 - name: Ensure repository is up-to-date + if: env.ACT != 'true' run: | git fetch --all git pull