fix: add repository parameter to checkout steps for fork PR compatibility - #793
Conversation
Reviewer's GuideUpdates 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- Several newly added
repository:inputs are over‑indented (e.g. inauto-tag.yml,commitlint.yml,doc-check.yml, and the PR/push branches inbuild-distribution.yml/dtk-unittest.yml), which will cause them to be parsed as part of the previous scalar instead of a separate key; alignrepository:with the other keys underwith:. - In the workflows where you add an extra checkout step for
github.event_name == 'push', double-check that therepositoryinput 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…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.
7fa9efd to
2273b26
Compare
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 # 当前代码已是最优实践,无需额外修复,以下为标准用法示例
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
persist-credentials: false |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Problem
When using
pull_request_targettrigger (e.g. incall-license-check.yml), theactions/checkoutstep withref: ${{ 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
repository: ${{ github.event.pull_request.head.repo.full_name }}to allactions/checkoutsteps that useref: ${{ github.event.pull_request.head.sha }}, so that checkout knows to fetch from the fork repository.actions/checkoutfrom v5 to v7 (latest).Files Changed
license-check.ymlauto-tag.ymlbuild-distribution.ymlcommitlint.ymldoc-check.ymldtk-unittest.ymlSummary by Sourcery
Update GitHub Actions workflows to correctly check out forked pull request commits and align on the latest checkout action version.
CI: