fix(github_actions): use most specific version tag when updating comments#14461
Merged
jeffwidman merged 1 commit intoMar 17, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes GitHub Actions workflow comment updates when a pinned SHA has multiple version tags, ensuring the version comment is updated using the most specific (longest) matching version string to avoid accidental partial replacements.
Changes:
- Update
FileUpdater#updated_version_commentto select the longest matching prior version suffix rather than the first match. - Add a regression spec covering the “shorter version is a suffix of the comment version” case.
- Add a new workflow fixture representing a pinned SHA with a
# v1.0.1comment.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| github_actions/lib/dependabot/github_actions/file_updater.rb | Chooses the longest matching prior version string to prevent gsub mangling (e.g., matching 1.0.1 instead of 1). |
| github_actions/spec/dependabot/github_actions/file_updater_spec.rb | Adds a regression test reproducing the substring-suffix failure mode with multiple tags on the same SHA. |
| github_actions/spec/fixtures/workflow_files/pinned_source_multiple_tags_substring_versions.yml | Adds a fixture workflow line with a pinned SHA and # v1.0.1 comment used by the new spec. |
truggeri
approved these changes
Mar 16, 2026
…ents
When a pinned SHA has multiple version tags (e.g. v1, v1.0, v1.0.1),
the version comment update logic used .find to pick the first tag whose
version string was a suffix of the comment. Because tags are sorted
ascending, this could pick a short version like "1" that is a substring
of the actual comment version "1.0.1". The subsequent gsub("1", "1.1")
then mangled the entire comment, e.g. "# v1.0.1" became "# v1.1.0.1.1".
Fix by selecting the longest (most specific) matching version string
instead of the first match. This ensures gsub replaces the correct
substring.
Fixes an issue observed in cli/cli#12918 where
the comment was incorrectly updated to "# v1.1.0.1.1" instead of
"# v1.1".
7010e0f to
15a8d32
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a pinned SHA has multiple version tags (e.g.
v1,v1.0,v1.0.1), the version comment update logic inFileUpdater#updated_version_commentused.findto pick the first tag whose version string was a suffix of the comment. Because tags are sorted ascending by version, this could pick a short version like"1"that is a substring of the actual comment version"1.0.1". The subsequentgsub("1", "1.1")then mangled the entire comment:# v1.0.1→# v1.1.0.1.1# v1.0.1→# v1.1Root Cause
In
updated_version_comment, the code:With tags
["v1", "v1.0", "v1.0.1"], this maps to["1", "1.0", "1.0.1"]and.findreturns"1"because"v1.0.1".end_with?("1")is true. Thencomment.gsub("1", "1.1")replaces every"1"in the comment.Fix
Changed
.findto.select { ... }.max_by(&:length)so the longest (most specific) matching version string is used. This correctly picks"1.0.1"over"1", andgsub("1.0.1", "1.1")produces the correct result.Test
Added a test case that reproduces the exact scenario from cli/cli#12918 — multiple tags (
v1,v1.0,v1.0.1) on the same SHA where a shorter version is a suffix of the version in the comment.References