From efa76ce17b19918d8de4df8d764fe79604aa6d4e Mon Sep 17 00:00:00 2001 From: lyrathorpe Date: Fri, 21 Aug 2026 14:50:08 +0100 Subject: [PATCH] fix: do not fail the release when pyproject.toml is already current (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## The defect The release step added in #17 commits the computed version unconditionally: ```sh git add pyproject.toml git commit -m "chore(release): v${VERSION}" ``` If `pyproject.toml` already carries that version — a re-run of a release, or a version corrected by hand — nothing is staged, `git commit` exits non-zero, and `set -euo pipefail` fails the job. By that point the image has already been pushed, so the release is half-done: published container, no tag. The next run then computes the same version again from the same commits. ## The fix Skip the commit and its branch push when there is nothing staged; tag either way. ## Verification The step was extracted from the workflow and run against a scratch repository with a real `origin`: - `VERSION` equal to the file's version → logs `pyproject.toml is already at 0.1.0`, pushes the tag, no commit. - `VERSION` different → commits `chore(release): v0.2.0`, pushes the branch, then the tag. Both paths leave `main` and the tags consistent. `bash -n` clean. Found while porting this same release scheme to `music-mirror`, which carries the guarded version from the start. --------- Co-authored-by: Emma Thorpe Reviewed-on: https://code.emmathe.dev/lyrathorpe/legacy-email-proxy/pulls/18 --- .gitea/workflows/build-and-publish.yaml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/build-and-publish.yaml b/.gitea/workflows/build-and-publish.yaml index c40b899..19570a0 100644 --- a/.gitea/workflows/build-and-publish.yaml +++ b/.gitea/workflows/build-and-publish.yaml @@ -188,11 +188,19 @@ jobs: git config user.name "${{ github.actor }}" git config user.email "${{ github.actor }}@users.noreply.${REGISTRY}" git add pyproject.toml - git commit -m "chore(release): v${VERSION}" - # Push the branch before the tag. If main has moved on and this push - # is rejected, the job fails without having left a tag pointing at a - # commit that is not on main. - git push origin "HEAD:${GITHUB_REF_NAME}" + # The file may already carry this version, in which case there is + # nothing to commit and `git commit` would fail the job after the + # image has already been pushed. + if git diff --cached --quiet; then + echo "pyproject.toml is already at ${VERSION}" + else + git commit -m "chore(release): v${VERSION}" + # Push the branch before the tag. If main has moved on and this push + # is rejected, the job fails without having left a tag pointing at a + # commit that is not on main. + git push origin "HEAD:${GITHUB_REF_NAME}" + fi + git tag -a "v${VERSION}" -m "v${VERSION}" git push origin "v${VERSION}"