fix: use branch ref instead of SHA for actions/checkout@v7 - #797
Conversation
Using bare SHA as ref parameter in actions/checkout@v7 causes
getRefSpec to only fetch the specific commit instead of the full
branch. This breaks when git commit --amend is used on a PR branch,
because testRef() always returns true for SHA refs, never triggering
the second targeted fetch.
Fix all affected workflows to use refs/heads/<branch> instead of
the bare SHA, consistent with the upstream fix guidance.
Affected workflows:
- license-check.yml (3 occurrences)
- build-distribution.yml (4 occurrences)
- auto-tag.yml
- commitlint.yml
- doc-check.yml
- dtk-unittest.yml
- workflow-templates/cppcheck.yml
Log: 修复 actions/checkout@v7 在 git commit --amend 后无法正确获取
PR 分支最新 commit 的问题
There was a problem hiding this comment.
Sorry @hudeng-go, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces all usages of actions/checkout@v7 that checked out a PR head by bare SHA with branch ref-based checkouts so that full branch history is fetched and force-pushed PRs are handled correctly across all CI workflows. Sequence diagram for actions_checkout@v7 using branch ref instead of SHAsequenceDiagram
actor GitHubActionsRunner
participant actions_checkout_v7
participant remote_repo
participant local_git
GitHubActionsRunner->>actions_checkout_v7: uses actions/checkout@v7
actions_checkout_v7->>remote_repo: getRefSpecForAllHistory(refs/heads/github.event.pull_request.head.ref)
remote_repo-->>actions_checkout_v7: full branch history
actions_checkout_v7->>local_git: testRef(refs/heads/github.event.pull_request.head.ref)
alt [ref changed after force-push]
actions_checkout_v7->>remote_repo: getRefSpecForAllHistory(refs/heads/github.event.pull_request.head.ref)
remote_repo-->>actions_checkout_v7: updated branch history
end
actions_checkout_v7->>local_git: git diff base...head
local_git-->>GitHubActionsRunner: diff succeeds with full history
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:60分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 --- a/.github/workflows/auto-tag.yml
+++ b/.github/workflows/auto-tag.yml
@@ -18,8 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v7
with:
ref: refs/heads/${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- allow-unsafe-pr-checkout: true
persist-credentials: false |
|
@hudeng-go: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, hudeng-go The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
问题
actions/checkout@v7在使用ref: ${{ github.event.pull_request.head.sha }}时存在缺陷:getRefSpec对 SHA 只 fetch 单个 commit,不拉取完整分支历史testRef对 SHA 永远返回 true,不会触发第二次 targeted fetchgit commit --amend后,新的 commit SHA 不在本地 git 历史中,导致后续git diff base...head等命令失败修复
将
ref参数从裸 SHA 改为refs/heads/<branch>格式,使getRefSpecForAllHistory能正确处理分支 ref,testRef也能在 force-push 后正确检测到 ref 变化并触发第二次 fetch。变更文件
.github/workflows/license-check.yml.github/workflows/build-distribution.yml.github/workflows/auto-tag.yml.github/workflows/commitlint.yml.github/workflows/doc-check.yml.github/workflows/dtk-unittest.ymlworkflow-templates/cppcheck.yml相关 PR
Summary by Sourcery
Update GitHub Actions workflows to check out pull request branches by ref name instead of commit SHA to ensure full history and correct behavior after force-pushes.
Bug Fixes:
CI: