fix: release workflow to detect version change#1026
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the GitHub Actions release workflow to avoid running the multi-arch build/release pipeline when pyproject.toml changes but the version = "..." line does not, reducing unnecessary releases.
Changes:
- Adds a
git diff-based check to detect whether theversionline changed between the previous and current commit onpush. - Sets
skip_release=true(and exits early) when no version-line change is detected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if git diff --unified=0 "$BEFORE_SHA" "${{ github.sha }}" -- pyproject.toml | grep -E '^[+-]version = "' >/dev/null; then | ||
| VERSION_CHANGED="true" | ||
| else | ||
| VERSION_CHANGED="false" |
There was a problem hiding this comment.
The VERSION_CHANGED detection currently checks whether the diff contains any added/removed version = "..." line, but it doesn’t verify that the version value actually changed (e.g., whitespace-only edits to the version line would still trigger a release). To match the goal of skipping releases when the version hasn’t changed, consider extracting the previous version from $BEFORE_SHA:pyproject.toml and comparing it to the current VERSION.
| if git diff --unified=0 "$BEFORE_SHA" "${{ github.sha }}" -- pyproject.toml | grep -E '^[+-]version = "' >/dev/null; then | |
| VERSION_CHANGED="true" | |
| else | |
| VERSION_CHANGED="false" | |
| PREVIOUS_VERSION=$(git show "$BEFORE_SHA:pyproject.toml" 2>/dev/null | grep '^version = ' | cut -d '"' -f 2 || true) | |
| if [[ -n "$PREVIOUS_VERSION" && "$PREVIOUS_VERSION" == "$VERSION" ]]; then | |
| VERSION_CHANGED="false" | |
| else | |
| VERSION_CHANGED="true" |
| fi | ||
| fi | ||
| fi | ||
| echo "version_changed=$VERSION_CHANGED" >> $GITHUB_OUTPUT |
There was a problem hiding this comment.
version_changed is written to $GITHUB_OUTPUT but it isn’t exposed via the job’s outputs: and doesn’t appear to be consumed elsewhere in this workflow. Consider either adding it to jobs.check-version.outputs (if you want it for downstream jobs) or removing it to avoid a misleading/unused output.
| echo "version_changed=$VERSION_CHANGED" >> $GITHUB_OUTPUT |
| if [[ "${{ github.event_name }}" == "push" ]]; then | ||
| BEFORE_SHA="${{ github.event.before }}" | ||
| if [[ -n "$BEFORE_SHA" && "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then | ||
| if git diff --unified=0 "$BEFORE_SHA" "${{ github.sha }}" -- pyproject.toml | grep -E '^[+-]version = "' >/dev/null; then | ||
| VERSION_CHANGED="true" |
There was a problem hiding this comment.
git diff "$BEFORE_SHA" ${{ github.sha }} relies on the runner having the previous commit available locally. With actions/checkout@v4 defaults (shallow clone), BEFORE_SHA (and tags used by the later git rev-parse "v$VERSION") may not be present, causing this step to fail or to incorrectly conclude the version didn’t change. Consider setting actions/checkout to fetch enough history (e.g., fetch-depth: 2 or 0) and ensure tags are fetched so both the diff and tag-existence checks work reliably.
There was a problem hiding this comment.
(a) [Critical] The git diff call will silently fail on every run because a shallow clone is performed by default
- The Copilot feedback is legit
- Problem: The
git diff "$BEFORE_SHA" "${{ github.sha }}"call will silently fail on every run becauseactions/checkout@v4performs a shallow clone (fetch-depth: 1) by default.BEFORE_SHA(fromgithub.event.before) is not present in the shallow-cloned history, so git outputs a fatal error to stderr with no stdout.- The pipe to
grepreceives empty input, exits non-zero, and theelsebranch always runs — settingVERSION_CHANGED="false"even when the version did change. - The result: every push that bumps the version in
pyproject.tomlwill be detected as "version unchanged" and the release will be silently skipped.
- Recommendation: Fix by adding
fetch-depth: 0(or at minimumfetch-depth: 2) to thecheck-versionjob's checkout step
| if [[ "${{ github.event_name }}" == "push" ]]; then | ||
| BEFORE_SHA="${{ github.event.before }}" | ||
| if [[ -n "$BEFORE_SHA" && "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then | ||
| if git diff --unified=0 "$BEFORE_SHA" "${{ github.sha }}" -- pyproject.toml | grep -E '^[+-]version = "' >/dev/null; then | ||
| VERSION_CHANGED="true" |
There was a problem hiding this comment.
(a) [Critical] The git diff call will silently fail on every run because a shallow clone is performed by default
- The Copilot feedback is legit
- Problem: The
git diff "$BEFORE_SHA" "${{ github.sha }}"call will silently fail on every run becauseactions/checkout@v4performs a shallow clone (fetch-depth: 1) by default.BEFORE_SHA(fromgithub.event.before) is not present in the shallow-cloned history, so git outputs a fatal error to stderr with no stdout.- The pipe to
grepreceives empty input, exits non-zero, and theelsebranch always runs — settingVERSION_CHANGED="false"even when the version did change. - The result: every push that bumps the version in
pyproject.tomlwill be detected as "version unchanged" and the release will be silently skipped.
- Recommendation: Fix by adding
fetch-depth: 0(or at minimumfetch-depth: 2) to thecheck-versionjob's checkout step
|
resetted to 0 from 2 in depth |
| if [[ "${{ github.event_name }}" == "push" ]]; then | ||
| BEFORE_SHA="${{ github.event.before }}" | ||
| if [[ -n "$BEFORE_SHA" && "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then | ||
| if git diff --unified=0 "$BEFORE_SHA" "${{ github.sha }}" -- pyproject.toml | grep -E '^[+-]version = "' >/dev/null; then | ||
| VERSION_CHANGED="true" |
This pull request updates the release workflow to prevent unnecessary releases when the version line in
pyproject.tomlhasn't changed. The workflow now checks for changes to the version and skips the release process if no update is detected.Release workflow improvements:
versionline inpyproject.tomlbetween the previous and current commit, and set aversion_changedoutput accordingly to determine if a release should proceed.skip_releaseandis_prereleaseoutputs totrueand exits early, preventing an unnecessary release.