fix(github_actions): Use tagged release commit for SHA-pinned refs without local tag#14718
Draft
scottschreckengaust wants to merge 4 commits intodependabot:mainfrom
Draft
Conversation
…thout local tag When a SHA-pinned GitHub Action ref has no matching version tag (local_tag_for_pinned_sha returns nil), the code previously fell through to latest_commit_for_pinned_ref which resolved to the HEAD of the branch containing the SHA. This caused updates to point at untagged commits (often on main) instead of tagged release commits (often on releases/vN), leaving version comments stale and misleading. Now, when a latest version tag is found, always use its commit_sha regardless of whether the current pinned SHA has a matching tag. Remove the now-unused latest_commit_for_pinned_ref and find_container_branch methods from both update_checker.rb and package_details_fetcher.rb. Fixes: dependabot#14716 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… test - Wrap latest_version_tag with T.must() to satisfy Sorbet's nil check - Remove now-unnecessary rubocop:disable Metrics/PerceivedComplexity - Update latest_version_finder_spec to expect tagged version instead of branch HEAD commit for SHA-pinned refs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The four sub-contexts testing different branch scenarios for SHA refs not at a branch tip now all have identical behavior (return latest tagged version), since find_container_branch was removed. Consolidate into a single test to fix RSpec/RepeatedExampleGroupBody offenses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 SHA-pinned GitHub Action ref has no matching version tag (
local_tag_for_pinned_shareturns nil),latest_commit_shapreviously fell through tolatest_commit_for_pinned_refwhich resolved to the HEAD of the containing branch — an untagged commit. This caused:main) instead of tagged release commits (often onreleases/vN)# v4.31.9when the SHA is actually an unrelatedmainbranch HEAD)This is especially common with action repos using a release branch workflow like
github/codeql-action(tags onreleases/v4, development onmain).Changes
update_checker.rb: Simplifiedlatest_commit_shato always usenew_tag.fetch(:commit_sha)when a latest version tag exists. Removed the now-unusedsource_checkerparameter, thelocal_tag_for_pinned_shagate, and the deadlatest_commit_for_pinned_ref/find_container_branchmethods.package_details_fetcher.rb: Same fix — always returnT.must(latest_version_tag).fetch(:version)for SHA-pinned refs. Removed dead methods and the now-unnecessaryrubocop:disable Metrics/PerceivedComplexitydirective.update_checker_spec.rb: Added new test for the bug scenario. Consolidated the four identical "git commit SHA not pointing to tip of branch" sub-contexts (default branch, different branch, multiple branches with/without default) into a single test — sincefind_container_branchwas removed, branch membership no longer affects behavior, and RuboCop flagged the repeated bodies (RSpec/RepeatedExampleGroupBody). Updated remaining tests to expect tagged versions instead of branch HEAD commits.package_details_fetcher_spec.rb: Updated "realworld repository" and "tip of master" tests to expect tagged versions instead of branch HEAD commits.latest_version_finder_spec.rb: Updated SHA-at-branch-tip test to expect tagged version instead of commit SHA.Root Cause
The
elsebranch was only reachable whennew_tagalready existed (we return nil before it), making it contradictory to ignore the resolved tag and return a branch HEAD instead.Test plan
RSpec/RepeatedExampleGroupBodylintlatest_version_tagwithT.must()for Sorbet compliancerubocop:disable Metrics/PerceivedComplexitydirectiveupdate_checker_spec.rb: 83 examples, 0 failurespackage_details_fetcher_spec.rb: 21 examples, 0 failureslatest_version_finder_spec.rb: passingdependabot/cliagainst a repo usinggithub/codeql-actionSHA pinsFixes #14716
Related: #7912, #8011, #13466, #14685
🤖 Generated with Claude Code