Visitar URL original
fix: read the PR's REPOSITORIES.md via the API in drift detection (#33) · worlddriven/documentation@0d7968a · GitHub
Skip to content

Commit 0d7968a

Browse files
authored
fix: read the PR's REPOSITORIES.md via the API in drift detection (#33)
actions/checkout v4.4.0 refuses to check out fork pull request code in pull_request_target workflows (BREAKING backport, actions/checkout#2502). The sparse checkout of REPOSITORIES.md therefore fails for every fork PR, detect-drift is red and the required status check blocks the merge. Fetch only REPOSITORIES.md from the PR head through the contents API instead; it is data and is never executed, so no fork code is checked out.
1 parent 091678c commit 0d7968a

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎.github/workflows/drift-detection.yml‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ jobs:
2020
with:
2121
ref: main
2222

23-
# Checkout PR's REPOSITORIES.md to see what changes are proposed
24-
- name: Checkout PR REPOSITORIES.md
25-
uses: actions/checkout@v4
26-
with:
27-
ref: ${{ github.event.pull_request.head.sha }}
28-
sparse-checkout: |
29-
REPOSITORIES.md
30-
sparse-checkout-cone-mode: false
31-
path: pr-files
32-
33-
# Copy PR's REPOSITORIES.md to working directory
23+
# Fetch only the PR's REPOSITORIES.md (data, never executed) through the
24+
# API. actions/checkout refuses to check out fork PR code in
25+
# pull_request_target workflows since v4.4.0, which failed this check
26+
# for every fork PR.
3427
- name: Use PR's REPOSITORIES.md
35-
run: cp pr-files/REPOSITORIES.md REPOSITORIES.md
28+
env:
29+
GH_TOKEN: ${{ github.token }}
30+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
31+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
32+
run: |
33+
gh api "repos/$HEAD_REPO/contents/REPOSITORIES.md?ref=$HEAD_SHA" \
34+
-H "Accept: application/vnd.github.raw" > REPOSITORIES.md
3635
3736
- name: Setup Node.js
3837
uses: actions/setup-node@v4

0 commit comments

Comments
 (0)