3434 echo "author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT
3535 echo "message=$(git log -1 --pretty=format:'%s')" >> $GITHUB_OUTPUT
3636
37- # Your three steps, kept here:
3837 - name : Get previous tag
3938 id : previoustag
4039 uses : WyriHaximus/github-action-get-previous-tag@v1
@@ -60,19 +59,23 @@ jobs:
6059 prev='${{ steps.previoustag.outputs.tag }}'
6160 next='${{ steps.version.outputs.next-version }}'
6261
62+ # Normalize version strings (strip optional leading 'v')
63+ prev_norm="${prev#v}"
64+ next_norm="${next#v}"
65+
6366 # Skip on bot housekeeping commits
6467 if [[ "$author" == "opsmill-bot" ]] && [[ "$msg" =~ ^chore(:|\(release\):) ]]; then
6568 skip=true
6669 reason="bot-commit"
6770 fi
6871
6972 # Skip when there is no new version to cut
70- if [[ "$next " == "$prev " || -z "$next " ]]; then
73+ if [[ "$next_norm " == "$prev_norm " || -z "$next_norm " ]]; then
7174 skip=true
7275 reason="${reason:+$reason,}no-new-version"
7376 fi
7477
75- echo "skip=$skip" >> $GITHUB_OUTPUT
78+ echo "skip=$skip" >> $GITHUB_OUTPUT
7679 echo "reason=$reason" >> $GITHUB_OUTPUT
7780
7881 prepare_release :
@@ -111,21 +114,36 @@ jobs:
111114 - name : Update lock file
112115 run : poetry lock
113116
114- - name : Commit version bump (skip CI)
117+ - name : Commit version bump (skip CI) only if there are changes
118+ id : commit_bump
115119 env :
116120 VERSION : ${{ needs.check_commit.outputs.next_version }}
121+ BRANCH : ${{ github.ref_name }}
117122 run : |
123+ set -euo pipefail
118124 git config user.name "opsmill-bot"
119125 git config user.email "github-bot@opsmill.com"
120- git add pyproject.toml poetry.lock
121- git commit -m "chore(release): v${VERSION} [skip ci]"
122- git push origin HEAD:main
123126
124- - name : Get new HEAD of main after push
127+ # Stage expected files
128+ git add pyproject.toml poetry.lock || true
129+
130+ # Commit only if there are staged changes
131+ if git diff --cached --quiet; then
132+ echo "No changes detected; skipping commit."
133+ echo "changed=false" >> "$GITHUB_OUTPUT"
134+ else
135+ git commit -m "chore(release): v${VERSION} [skip ci]"
136+ git push origin "HEAD:${BRANCH}"
137+ echo "changed=true" >> "$GITHUB_OUTPUT"
138+ fi
139+
140+ - name : Get new HEAD of branch after push
125141 id : head
142+ env :
143+ BRANCH : ${{ github.ref_name }}
126144 run : |
127- git fetch origin main
128- echo "sha=$(git rev-parse origin/main )" >> $GITHUB_OUTPUT
145+ git fetch origin "${BRANCH}"
146+ echo "sha=$(git rev-parse " origin/${BRANCH}" )" >> " $GITHUB_OUTPUT"
129147
130148 - name : Expose next_version for downstream jobs
131149 id : expose
0 commit comments