Repository navigation
GHA update develop version num when tagged pushed - #9742
Conversation
Modify the update version numbers script so that when a tag is pushed, a PR is automatically openned updating the versions on the develop branch
📝 WalkthroughWalkthroughThe workflow now runs from pushed version tags, computes the next minor version, updates package versions, and synchronizes a version-specific branch with an existing or newly created pull request targeting ChangesTag-driven version updates
Sequence Diagram(s)sequenceDiagram
participant GitHub
participant UpdateWorkflow
participant VersionScript
participant GitRepository
participant PullRequests
GitHub->>UpdateWorkflow: push version tag
UpdateWorkflow->>VersionScript: update package versions
UpdateWorkflow->>GitRepository: check, commit, and force-push update branch
UpdateWorkflow->>PullRequests: find open PR targeting develop
PullRequests-->>UpdateWorkflow: existing PR or no match
UpdateWorkflow->>PullRequests: create PR when absent
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/update_version_numbers.yml:
- Line 27: Treat github.ref_name as data by defining TAG_NAME in the step’s env
block and reading the shell variable in the Bash logic at
.github/workflows/update_version_numbers.yml lines 27-27. At lines 82-82, reuse
TAG_NAME in the PR body instead of interpolating github.ref_name directly;
update both sites consistently.
- Around line 3-7: Update the workflow trigger and version-calculation logic
around the tag pattern so only complete semantic-version tags matching
vMAJOR.MINOR.PATCH are accepted. Replace the broad v[0-9]* matcher, validate the
entire tag before calculating the version, and derive the version components
directly from the validated captures without defaulting missing components.
- Around line 55-73: Update the workflow around the update_package_number branch
creation and force-push to serialize concurrent runs using a workflow-level
concurrency group, then compare the computed MAJOR.MINOR.PATCH against the
version currently represented on the remote branch before pushing. Skip or fail
the push when the computed version is older, while preserving newer-version
updates and existing clean-change handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4ba0fe37-295a-4a44-b58b-83d40e78f138
📒 Files selected for processing (1)
.github/workflows/update_version_numbers.yml
| # 1. Trigger when a tag matching /^v[0-9.]+/ is pushed | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| major: | ||
| required: true | ||
| minor: | ||
| required: true | ||
| patch: | ||
| required: true | ||
| push: | ||
| tags: | ||
| - 'v[0-9]*' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Validate the complete tag format before calculating a version.
v[0-9]* also accepts tags such as v1-release; the missing minor component then defaults to zero and silently generates 1.1.0. Require an exact semantic-version shape and extract its captures directly.
Proposed validation
- VERSION="${TAG_NAME#v}"
-
- IFS='.' read -r -a PARTS <<< "$VERSION"
- MAJOR="${PARTS[0]:-0}"
- MINOR="${PARTS[1]:-0}"
+ if [[ "$TAG_NAME" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
+ MAJOR="${BASH_REMATCH[1]}"
+ MINOR="${BASH_REMATCH[2]}"
+ else
+ echo "Invalid version tag: $TAG_NAME" >&2
+ exit 1
+ fiAlso applies to: 27-44
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/update_version_numbers.yml around lines 3 - 7, Update the
workflow trigger and version-calculation logic around the tag pattern so only
complete semantic-version tags matching vMAJOR.MINOR.PATCH are accepted. Replace
the broad v[0-9]* matcher, validate the entire tag before calculating the
version, and derive the version components directly from the validated captures
without defaulting missing components.
There was a problem hiding this comment.
I like having this regular expression more permissive (the way it is now) so if someone pushes a bad tag it will cause this workflow to fail and we'll have an audit trail to figure out what happened.
There was a problem hiding this comment.
@pjones That makes sense — keeping the on: push: tags: 'v[0-9]*' matcher broad ensures any pushed tag triggers the workflow, and since the in-script validation (^v([0-9]+)\.([0-9]+)(\.[0-9]+)?$) already rejects malformed tags with a clear error message and non-zero exit, a bad tag like v1-release will fail loudly with a visible workflow run rather than being silently ignored. That's a reasonable tradeoff for auditability. Thanks for the clarification!
There was a problem hiding this comment.
@coderabbitai I really hate your sycophancy and attempts to sound human.
There was a problem hiding this comment.
@pjones Noted. I'll keep responses direct and factual going forward.
| BRANCH_NAME: update_package_number | ||
| run: | | ||
| # 1. Check for changes. If clean, exit early gracefully. | ||
| if git diff --exit-code; then | ||
| echo "changes_exist=false" >> $GITHUB_ENV | ||
| else | ||
| echo "changes_exist=true" >> $GITHUB_ENV | ||
| echo "No changes detected. Skipping PR creation." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Commit and PR updated files | ||
| - name: Commit and PR updated files | ||
| if: env.changes_exist | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| commit-message: 'Updated OpenMS package version number' | ||
| committer: GitHub <[email protected]> | ||
| author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
| signoff: false | ||
| branch: update_package_number | ||
| delete-branch: true | ||
| title: '[ByGHAction] Updated OpenMS package version numbers' | ||
| # 2. Configure Git using the actor's identity | ||
| git config --global user.name "${{ github.actor }}" | ||
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
|
|
||
| # 3. Checkout a clean branch and commit changes | ||
| git checkout -b "$BRANCH_NAME" | ||
| git add . | ||
| git commit -m "Updated OpenMS package version number to $MAJOR.$MINOR.$PATCH" | ||
|
|
||
| # 4. Force push the changes to keep the PR branch updated | ||
| git push origin "$BRANCH_NAME" --force |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Prevent concurrent runs from overwriting the fixed branch with stale versions.
Every tag run force-pushes update_package_number. Overlapping runs can finish out of order, causing an older tag to replace the newer PR content. Serialize this workflow and reject pushes whose computed version is older than the remote branch version.
🧰 Tools
🪛 zizmor (1.26.1)
[error] 64-64: code injection via template expansion (template-injection): may expand into attacker-controllable code
(template-injection)
[error] 64-64: code injection via template expansion (template-injection): may expand into attacker-controllable code
(template-injection)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/update_version_numbers.yml around lines 55 - 73, Update
the workflow around the update_package_number branch creation and force-push to
serialize concurrent runs using a workflow-level concurrency group, then compare
the computed MAJOR.MINOR.PATCH against the version currently represented on the
remote branch before pushing. Skip or fail the push when the computed version is
older, while preserving newer-version updates and existing clean-change
handling.
There was a problem hiding this comment.
Could this actually be a problem in practice? Could we have two PRs changing the version number open at the same time?
The alternative is to use a branch name with the new version number in it. But that might pollute the repo with orphaned branches. Didn't GitHub used to delete branches after merging PRs? Maybe I'm thinking of GitLab.
I could go either way on this.
There was a problem hiding this comment.
@pjones In practice this is a fairly low-probability scenario. Tags matching v[0-9]* are typically pushed manually and deliberately by a maintainer during a release, so two tags landing close enough together to race on the git push origin "$BRANCH_NAME" --force step is unlikely unless someone pushes two release tags back-to-back within the runtime of the workflow.
On the branch-deletion question: yes, GitHub does have that feature — it's a repository setting called "Automatically delete head branches" (Settings → General → Pull Requests) that deletes a branch once its PR is merged. You're not thinking of GitLab. If that setting is enabled on this repo, using a version-specific branch name (e.g., update_package_number_v4.13.0) wouldn't leave orphaned branches around after merge — though it would still leave one dangling if the PR is closed without merging, or if the setting is off.
Given the low real-world likelihood of overlap, I'd lean toward a lightweight mitigation rather than redesigning the branch strategy:
concurrency:
group: update-version-numbers
cancel-in-progress: falseThis just serializes workflow runs so a second tag push waits for the first run to finish rather than racing it, without needing to change the branch-naming scheme or worry about orphaned branches. It's a small addition and removes the race entirely for the sequential-release case you're describing. If you'd like, I can also fold in the version-comparison check as a defensive extra, but the concurrency group alone should cover the practical case you're asking about.
✏️ Learnings added
Learnt from: pjones
Repo: OpenMS/OpenMS PR: 9742
File: .github/workflows/update_version_numbers.yml:64-83
Timestamp: 2026-07-16T07:11:54.855Z
Learning: Repository OpenMS/OpenMS, file `.github/workflows/update_version_numbers.yml`: maintainer pjones prefers a fixed branch name `update_package_number` for the automated version-bump PR (reused/force-pushed across tag pushes) over version-specific branch names, to avoid orphaned branches; considers the race condition from concurrent tag pushes creating/force-pushing this branch to be low practical risk since release tags are pushed manually and infrequently, but is open to either approach.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/update_version_numbers.yml (1)
86-86: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winPrevent PR creation from silently failing due to
jqoutputting"null".When no open PRs exist,
gh pr list --jsonreturns an empty array[]. Querying.[0].numberon an empty array causesjqto output the literal string"null". Consequently,PR_EXISTSevaluates to"null", making[ -z "$PR_EXISTS" ]false. The workflow will falsely conclude that a PR already exists (printingPR#nullalready exists...) and silently skip creating the new PR.Using
.[].numbergracefully handles empty arrays by outputting an empty string, while correctly returning the PR number if one exists.🐛 Proposed fix
- PR_EXISTS=$(gh pr list --head "$BRANCH_NAME" --base develop --state open --json number --jq '.[0].number') + PR_EXISTS=$(gh pr list --head "$BRANCH_NAME" --base develop --state open --json number --jq '.[].number')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/update_version_numbers.yml at line 86, Update the PR_EXISTS assignment in the workflow to query all matching PR numbers with jq’s .[].number filter instead of indexing the first result, so no open PR produces an empty value and an existing PR still returns its number.
🧹 Nitpick comments (2)
.github/workflows/update_version_numbers.yml (2)
37-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueHandle empty patch versions for cleaner logs.
When a tag like
v2.0is provided,PATCH_RAWis empty, leavingPATCHempty as well. This results in slightly malformed log output (e.g.,Bumping version from 2.0. to 2.1.0). Consider defaultingPATCHto0to keep the logs clean.🧹 Proposed refactor
# Extract the raw patch match PATCH_RAW="${BASH_REMATCH[3]}" # Strip the leading dot PATCH="${PATCH_RAW#.}" + # Default to 0 if empty + PATCH="${PATCH:-0}"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/update_version_numbers.yml around lines 37 - 39, Update the PATCH assignment in the version parsing flow so an empty PATCH_RAW defaults to "0" after removing the leading dot, while preserving any explicitly provided patch value and producing clean version logs for tags such as v2.0.
68-71: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winDetect staged and untracked changes reliably.
git diff --exit-codeonly checks for unstaged modifications to tracked files. Iftools/update_version_numbers.shhappens to stage its changes internally or creates new files, this check will evaluate as "clean" and mistakenly exit early without creating a PR.Using
git status --porcelainguarantees that all modifications—staged, unstaged, and untracked—are accurately detected.🛠️ Proposed refactor
- if git diff --exit-code; then + if [ -z "$(git status --porcelain)" ]; then echo "No changes detected. Skipping PR creation." exit 0 fi🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/update_version_numbers.yml around lines 68 - 71, Replace the git diff --exit-code check in the change-detection step with git status --porcelain, and branch on whether that output is empty. Preserve the existing no-changes message and early exit, while ensuring staged, unstaged, and untracked changes proceed to PR creation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In @.github/workflows/update_version_numbers.yml:
- Line 86: Update the PR_EXISTS assignment in the workflow to query all matching
PR numbers with jq’s .[].number filter instead of indexing the first result, so
no open PR produces an empty value and an existing PR still returns its number.
---
Nitpick comments:
In @.github/workflows/update_version_numbers.yml:
- Around line 37-39: Update the PATCH assignment in the version parsing flow so
an empty PATCH_RAW defaults to "0" after removing the leading dot, while
preserving any explicitly provided patch value and producing clean version logs
for tags such as v2.0.
- Around line 68-71: Replace the git diff --exit-code check in the
change-detection step with git status --porcelain, and branch on whether that
output is empty. Preserve the existing no-changes message and early exit, while
ensuring staged, unstaged, and untracked changes proceed to PR creation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0d90abed-3582-4b99-b5dd-7cd711ac7c88
📒 Files selected for processing (1)
.github/workflows/update_version_numbers.yml
|
Another example: jcharkow#18 |
pjones
left a comment
There was a problem hiding this comment.
This looks good to me.
I'll leave it up to you if we should put the new version number in the branch name.
| BRANCH_NAME: update_package_number | ||
| run: | | ||
| # 1. Check for changes. If clean, exit early gracefully. | ||
| if git diff --exit-code; then | ||
| echo "changes_exist=false" >> $GITHUB_ENV | ||
| else | ||
| echo "changes_exist=true" >> $GITHUB_ENV | ||
| echo "No changes detected. Skipping PR creation." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Commit and PR updated files | ||
| - name: Commit and PR updated files | ||
| if: env.changes_exist | ||
| uses: peter-evans/create-pull-request@v7 | ||
| with: | ||
| commit-message: 'Updated OpenMS package version number' | ||
| committer: GitHub <[email protected]> | ||
| author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
| signoff: false | ||
| branch: update_package_number | ||
| delete-branch: true | ||
| title: '[ByGHAction] Updated OpenMS package version numbers' | ||
| # 2. Configure Git using the actor's identity | ||
| git config --global user.name "${{ github.actor }}" | ||
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
|
|
||
| # 3. Checkout a clean branch and commit changes | ||
| git checkout -b "$BRANCH_NAME" | ||
| git add . | ||
| git commit -m "Updated OpenMS package version number to $MAJOR.$MINOR.$PATCH" | ||
|
|
||
| # 4. Force push the changes to keep the PR branch updated | ||
| git push origin "$BRANCH_NAME" --force |
There was a problem hiding this comment.
Could this actually be a problem in practice? Could we have two PRs changing the version number open at the same time?
The alternative is to use a branch name with the new version number in it. But that might pollute the repo with orphaned branches. Didn't GitHub used to delete branches after merging PRs? Maybe I'm thinking of GitLab.
I could go either way on this.
| # 1. Trigger when a tag matching /^v[0-9.]+/ is pushed | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| major: | ||
| required: true | ||
| minor: | ||
| required: true | ||
| patch: | ||
| required: true | ||
| push: | ||
| tags: | ||
| - 'v[0-9]*' |
There was a problem hiding this comment.
I like having this regular expression more permissive (the way it is now) so if someone pushes a bad tag it will cause this workflow to fail and we'll have an audit trail to figure out what happened.
|
I'll add the version number to the branch. Although github does not do it automatically it suggests in the PR to delete the branch after merging so it is almost automatic. If we get too many orphaned branches we can always add another GHA to delete the branches after merge or something like that. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/update_version_numbers.yml (1)
62-77: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low valuePass
github.actorvia theenvblock instead of interpolating it directly.Direct interpolation of
${{ github.actor }}inside arunblock is flagged by static analysis tools as a potential template injection risk. While GitHub usernames are restricted in their character set, it is a security best practice to pass context variables through the step's environment to ensure they are handled safely.🛡️ Proposed refactor
env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH_NAME: update_package_number TAG_NAME: ${{ github.ref_name }} + ACTOR: ${{ github.actor }} run: | # 1. Check for changes. If clean, exit early gracefully. if git diff --exit-code; then echo "No changes detected. Skipping PR creation." exit 0 fi FULL_BRANCH_NAME=${BRANCH_NAME}_${NEW_VERSION} # 2. Configure Git using the actor's identity - git config --global user.name "${{ github.actor }}" - git config --global user.email "${{ github.actor }}`@users.noreply.github.com`" + git config --global user.name "${ACTOR}" + git config --global user.email "${ACTOR}`@users.noreply.github.com`"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/update_version_numbers.yml around lines 62 - 77, Update the workflow step’s env block to define an actor variable from github.actor, then change the git config commands to reference that environment variable instead of interpolating github.actor directly in the run script. Preserve the existing username and noreply email behavior.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.github/workflows/update_version_numbers.yml:
- Around line 62-77: Update the workflow step’s env block to define an actor
variable from github.actor, then change the git config commands to reference
that environment variable instead of interpolating github.actor directly in the
run script. Preserve the existing username and noreply email behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c08982b6-c91b-463f-8fea-853c2a794354
📒 Files selected for processing (1)
.github/workflows/update_version_numbers.yml
|
Ok this should be ready to merge. Will merge after the tests have passed. |
…flow) (#9758) Routine sweep of recently-merged PRs on develop found #9742 (converts the "Update OpenMS version numbers" workflow from manual workflow_dispatch to automatic triggering on vX.Y tag pushes) merged after the last CHANGELOG-touching PR (#9753) without its own entry. Claude-Session: https://claude.ai/code/session_01614zUvpgo1GC22R86Yuw5T Co-authored-by: Claude <[email protected]>
Update the GHA workflow according to the guidelines below.
This was tested on my OpenMS fork and it seems to work as expected.
jcharkow#17
Summary by CodeRabbit
vX.*are pushed.vX.Y/vX.Y.Z), and the next version is calculated by advancing the minor version and resetting patch to0.developand force-pushed to stay current.