Skip to content

Commit 826bedc

Browse files
hudeng-goBLumia
authored andcommitted
fix: use branch ref instead of SHA for actions/checkout@v7
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 的问题
1 parent d2510ed commit 826bedc

7 files changed

Lines changed: 12 additions & 12 deletions

File tree

.github/workflows/auto-tag.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v7
2020
with:
21-
ref: ${{ github.event.pull_request.head.sha }}
21+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
2222
repository: ${{ github.event.pull_request.head.repo.full_name }}
2323
allow-unsafe-pr-checkout: true
2424
persist-credentials: false

.github/workflows/build-distribution.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v7
2626
if: ${{ github.event.pull_request.head.sha }}
2727
with:
28-
ref: ${{ github.event.pull_request.head.sha }}
28+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
2929
repository: ${{ github.event.pull_request.head.repo.full_name }}
3030
allow-unsafe-pr-checkout: true
3131
- uses: actions/checkout@v7
@@ -67,7 +67,7 @@ jobs:
6767
- uses: actions/checkout@v7
6868
if: ${{ github.event.pull_request.head.sha }}
6969
with:
70-
ref: ${{ github.event.pull_request.head.sha }}
70+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
7171
repository: ${{ github.event.pull_request.head.repo.full_name }}
7272
allow-unsafe-pr-checkout: true
7373
- uses: actions/checkout@v7
@@ -164,7 +164,7 @@ jobs:
164164
- uses: actions/checkout@v7
165165
if: ${{ github.event.pull_request.head.sha }}
166166
with:
167-
ref: ${{ github.event.pull_request.head.sha }}
167+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
168168
repository: ${{ github.event.pull_request.head.repo.full_name }}
169169
allow-unsafe-pr-checkout: true
170170
- uses: actions/checkout@v7
@@ -370,7 +370,7 @@ jobs:
370370
- uses: actions/checkout@v7
371371
if: ${{ github.event.pull_request.head.sha }}
372372
with:
373-
ref: ${{ github.event.pull_request.head.sha }}
373+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
374374
repository: ${{ github.event.pull_request.head.repo.full_name }}
375375
allow-unsafe-pr-checkout: true
376376
- uses: actions/checkout@v7

.github/workflows/commitlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
- name: Fetch code
1010
uses: actions/checkout@v7
1111
with:
12-
ref: ${{ github.event.pull_request.head.sha }}
12+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
1313
repository: ${{ github.event.pull_request.head.repo.full_name }}
1414
allow-unsafe-pr-checkout: true
1515
fetch-depth: 0

.github/workflows/doc-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
6060
- uses: actions/checkout@v7
6161
with:
62-
ref: ${{ github.event.pull_request.head.sha }}
62+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
6363
repository: ${{ github.event.pull_request.head.repo.full_name }}
6464
allow-unsafe-pr-checkout: true
6565
persist-credentials: false

.github/workflows/dtk-unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v7
2424
if: ${{ github.event.pull_request.head.sha }}
2525
with:
26-
ref: ${{ github.event.pull_request.head.sha }}
26+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
2727
repository: ${{ github.event.pull_request.head.repo.full_name }}
2828
allow-unsafe-pr-checkout: true
2929
- uses: actions/checkout@v7

.github/workflows/license-check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
with:
1010
# fetch-depth: 0 必不可少,否则 git diff 找不到对比基准
1111
fetch-depth: 0
12-
ref: ${{ github.event.pull_request.head.sha }}
12+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
1313
repository: ${{ github.event.pull_request.head.repo.full_name }}
1414
allow-unsafe-pr-checkout: true
1515

@@ -117,7 +117,7 @@ jobs:
117117
steps:
118118
- uses: actions/checkout@v7
119119
with:
120-
ref: ${{ github.event.pull_request.head.sha }}
120+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
121121
repository: ${{ github.event.pull_request.head.repo.full_name }}
122122
allow-unsafe-pr-checkout: true
123123
- name: Install zsh
@@ -150,7 +150,7 @@ jobs:
150150
- uses: actions/checkout@v7
151151
with:
152152
fetch-depth: 0
153-
ref: ${{ github.event.pull_request.head.sha }}
153+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
154154
repository: ${{ github.event.pull_request.head.repo.full_name }}
155155
allow-unsafe-pr-checkout: true
156156
- name: Fetch base ref and test refs

workflow-templates/cppcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- run: export
1717
- uses: actions/checkout@v7
1818
with:
19-
ref: ${{ github.event.pull_request.head.sha }}
19+
ref: refs/heads/${{ github.event.pull_request.head.ref }}
2020
repository: ${{ github.event.pull_request.head.repo.full_name }}
2121
allow-unsafe-pr-checkout: true
2222
persist-credentials: false

0 commit comments

Comments
 (0)