Skip to content

fix: add repository parameter to checkout steps for fork PR compatibility - #793

Merged
BLumia merged 1 commit into
masterfrom
fix/checkout-fork-pr
Jul 21, 2026
Merged

fix: add repository parameter to checkout steps for fork PR compatibility#793
BLumia merged 1 commit into
masterfrom
fix/checkout-fork-pr

Conversation

@deepin-ci-robot

@deepin-ci-robot deepin-ci-robot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

When using pull_request_target trigger (e.g. in call-license-check.yml), the actions/checkout step with ref: ${{ github.event.pull_request.head.sha }} fails for PRs from forks, because the head SHA doesn't exist in the base repository.

Example: https://github.com/linuxdeepin/deepin-camera/actions/runs/29796604801/job/88529105965

Solution

  1. Add repository: ${{ github.event.pull_request.head.repo.full_name }} to all actions/checkout steps that use ref: ${{ github.event.pull_request.head.sha }}, so that checkout knows to fetch from the fork repository.
  2. Upgrade actions/checkout from v5 to v7 (latest).

Files Changed

File Changes
license-check.yml 3 checkout steps: +repository, v5→v7
auto-tag.yml 1 checkout step: +repository, v5→v7
build-distribution.yml 4 checkout steps: +repository, v5→v7
commitlint.yml 1 checkout step: +repository, v5→v7
doc-check.yml 1 checkout step: +repository, v5→v7
dtk-unittest.yml 1 checkout step: +repository, v5→v7

Summary by Sourcery

Update GitHub Actions workflows to correctly check out forked pull request commits and align on the latest checkout action version.

CI:

  • Add the repository parameter to checkout steps that use the pull request head SHA so workflows can fetch code from forked repositories.
  • Upgrade all affected actions/checkout usages in CI workflows from v5 to v7 for consistency and compatibility.

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Updates multiple GitHub Actions workflows so that checkout steps work for forked pull requests by specifying the source repository and upgrading actions/checkout from v5 to v7 wherever a PR head SHA is used.

File-Level Changes

Change Details Files
Ensure checkout steps use the fork repository when running on pull_request_target with a PR head SHA.
  • Add repository: ${{ github.event.pull_request.head.repo.full_name }} to all checkout steps conditioned on github.event.pull_request.head.sha or using ref: ${{ github.event.pull_request.head.sha }}
  • Keep fetch-depth and other existing checkout options unchanged while adding the repository parameter
.github/workflows/build-distribution.yml
.github/workflows/license-check.yml
.github/workflows/dtk-unittest.yml
.github/workflows/auto-tag.yml
.github/workflows/commitlint.yml
.github/workflows/doc-check.yml
Upgrade actions/checkout usage from v5 to v7 across workflows.
  • Replace uses: actions/checkout@v5 with uses: actions/checkout@v7 in all modified workflows, both for PR and push flows
  • Preserve existing conditional logic (if: expressions) and ancillary options such as fetch-depth and persist-credentials
.github/workflows/build-distribution.yml
.github/workflows/license-check.yml
.github/workflows/dtk-unittest.yml
.github/workflows/auto-tag.yml
.github/workflows/commitlint.yml
.github/workflows/doc-check.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • Several newly added repository: inputs are over‑indented (e.g. in auto-tag.yml, commitlint.yml, doc-check.yml, and the PR/push branches in build-distribution.yml/dtk-unittest.yml), which will cause them to be parsed as part of the previous scalar instead of a separate key; align repository: with the other keys under with:.
  • In the workflows where you add an extra checkout step for github.event_name == 'push', double-check that the repository input is only added to the PR-specific checkout and that the push-specific checkout remains unchanged, to avoid accidentally fetching from the fork when handling push events.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several newly added `repository:` inputs are over‑indented (e.g. in `auto-tag.yml`, `commitlint.yml`, `doc-check.yml`, and the PR/push branches in `build-distribution.yml`/`dtk-unittest.yml`), which will cause them to be parsed as part of the previous scalar instead of a separate key; align `repository:` with the other keys under `with:`.
- In the workflows where you add an extra checkout step for `github.event_name == 'push'`, double-check that the `repository` input is only added to the PR-specific checkout and that the push-specific checkout remains unchanged, to avoid accidentally fetching from the fork when handling push events.

## Individual Comments

### Comment 1
<location path=".github/workflows/auto-tag.yml" line_range="22" />
<code_context>
+      - uses: actions/checkout@v7
         with:
           ref: ${{ github.event.pull_request.head.sha }}
+            repository: ${{ github.event.pull_request.head.repo.full_name }}
           persist-credentials: false
       - name: get changelog version
</code_context>
<issue_to_address>
**issue (bug_risk):** `repository` appears to be incorrectly nested under `ref`, which will invalidate the YAML.

Given the current indentation, `repository` is nested under `ref` instead of being a separate key in `with`. Please indent `repository` to align with `ref` and `persist-credentials` so the workflow YAML remains valid.
</issue_to_address>

### Comment 2
<location path=".github/workflows/commitlint.yml" line_range="13" />
<code_context>
+      - uses: actions/checkout@v7
         with:
           ref: ${{ github.event.pull_request.head.sha }}
+            repository: ${{ github.event.pull_request.head.repo.full_name }}
           persist-credentials: false
       - name: get changelog version
</code_context>
<issue_to_address>
**issue (bug_risk):** The indentation of `repository` under `with:` should match `ref` to be a valid input to `actions/checkout`.

`repository` must be aligned with `ref` (and other keys under `with:`), not indented further, otherwise the workflow will fail to load:

```yaml
      - name: Fetch code
        uses: actions/checkout@v7
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          fetch-depth: 0
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread .github/workflows/auto-tag.yml Outdated
Comment thread .github/workflows/commitlint.yml Outdated
…lity

When using pull_request_target trigger, the checkout step needs to
explicitly specify the repository to check out from the fork repo.
Otherwise, PRs from forks fail at checkout because the head SHA
doesn't exist in the base repository.

Also upgrade actions/checkout from v5 to v7.
@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了GitHub Actions工作流中checkout版本的升级与Fork仓库PR代码拉取的修复
逻辑正确且无安全漏洞,CI配置规范一致,无需扣分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修改涉及.github/workflows/目录下的多个YAML配置文件,均正确升级了actions/checkout的版本至v7,并在PR触发的步骤中正确添加了repository: ${{ github.event.pull_request.head.repo.full_name }}参数。YAML缩进和结构完全符合规范。
潜在问题:无
建议:无需修改

  • 2.代码质量(优秀)✓

变更在所有涉及Pull Request触发的checkout步骤中保持高度一致,修改模式统一,有效解决了从Fork仓库发起PR时可能遇到的代码拉取失败问题,代码意图清晰。
潜在问题:无
建议:无需修改

  • 3.代码性能(无性能问题)✓

仅修改了CI配置的参数和Action版本,不涉及运行时算法或资源调度优化,对CI执行性能无负面影响。
潜在问题:无
建议:无需修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改为CI流程的基础配置优化,显式指定PR来源仓库全名,确保了代码拉取的准确性,未引入任何安全风险。

  • 建议:无需修改

■ 【改进建议代码示例】

# 当前代码已是最优实践,无需额外修复,以下为标准用法示例
- uses: actions/checkout@v7
  with:
    ref: ${{ github.event.pull_request.head.sha }}
    repository: ${{ github.event.pull_request.head.repo.full_name }}
    persist-credentials: false

@deepin-ci-robot

Copy link
Copy Markdown
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, deepin-ci-robot

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia
BLumia merged commit 10499fb into master Jul 21, 2026
9 of 10 checks passed
@BLumia
BLumia deleted the fix/checkout-fork-pr branch July 21, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants