From 65060f08cd625ef0da6d88b0ec6dc588b16007ab Mon Sep 17 00:00:00 2001 From: hudeng Date: Wed, 29 Jul 2026 10:30:49 +0800 Subject: [PATCH] fix: use branch ref instead of SHA for actions/checkout@v7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/ 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 的问题 --- .github/workflows/auto-tag.yml | 2 +- .github/workflows/build-distribution.yml | 8 ++++---- .github/workflows/commitlint.yml | 2 +- .github/workflows/doc-check.yml | 2 +- .github/workflows/dtk-unittest.yml | 2 +- .github/workflows/license-check.yml | 6 +++--- workflow-templates/cppcheck.yml | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 0bc5df898..a165682c8 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + 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 diff --git a/.github/workflows/build-distribution.yml b/.github/workflows/build-distribution.yml index 0cbe4751f..05f357fad 100644 --- a/.github/workflows/build-distribution.yml +++ b/.github/workflows/build-distribution.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@v7 if: ${{ github.event.pull_request.head.sha }} with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: actions/checkout@v7 @@ -67,7 +67,7 @@ jobs: - uses: actions/checkout@v7 if: ${{ github.event.pull_request.head.sha }} with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: actions/checkout@v7 @@ -164,7 +164,7 @@ jobs: - uses: actions/checkout@v7 if: ${{ github.event.pull_request.head.sha }} with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: actions/checkout@v7 @@ -370,7 +370,7 @@ jobs: - uses: actions/checkout@v7 if: ${{ github.event.pull_request.head.sha }} with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: actions/checkout@v7 diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 83903cd45..545d4ca64 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -9,7 +9,7 @@ jobs: - name: Fetch code uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true fetch-depth: 0 diff --git a/.github/workflows/doc-check.yml b/.github/workflows/doc-check.yml index 8d2a02048..cffbb4f02 100644 --- a/.github/workflows/doc-check.yml +++ b/.github/workflows/doc-check.yml @@ -59,7 +59,7 @@ jobs: - uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + 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 diff --git a/.github/workflows/dtk-unittest.yml b/.github/workflows/dtk-unittest.yml index e4c3c45be..d31d1fe13 100644 --- a/.github/workflows/dtk-unittest.yml +++ b/.github/workflows/dtk-unittest.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v7 if: ${{ github.event.pull_request.head.sha }} with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: actions/checkout@v7 diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml index a74b6accf..bd7544b6d 100644 --- a/.github/workflows/license-check.yml +++ b/.github/workflows/license-check.yml @@ -9,7 +9,7 @@ jobs: with: # fetch-depth: 0 必不可少,否则 git diff 找不到对比基准 fetch-depth: 0 - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true @@ -117,7 +117,7 @@ jobs: steps: - uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - name: Install zsh @@ -150,7 +150,7 @@ jobs: - uses: actions/checkout@v7 with: fetch-depth: 0 - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} allow-unsafe-pr-checkout: true - uses: zccrs/github-actions-spdx-checker@main diff --git a/workflow-templates/cppcheck.yml b/workflow-templates/cppcheck.yml index 7915f23a7..d1e8b0ab9 100644 --- a/workflow-templates/cppcheck.yml +++ b/workflow-templates/cppcheck.yml @@ -16,7 +16,7 @@ jobs: - run: export - uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + 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