Skip to content

Commit 3bc472b

Browse files
Swamp-Igcursoragent
andcommitted
ci: checkout fork head for format-docs workflow
Pull requests from forks only have the head branch on the fork repo, so ref: github.head_ref against upstream origin failed checkout. Also only auto-commit prettier fixes for same-repo PRs; fork PRs get --check because GITHUB_TOKEN cannot push to the fork. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c474d1c commit 3bc472b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/format-docs.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v6
1515
with:
16-
# Make sure the actual branch is checked out when running on pull requests
17-
ref: ${{ github.head_ref }}
18-
# This is important to fetch the changes to the previous commit
16+
# Fork PRs: head_ref only exists on the head repo, not upstream origin
17+
repository: ${{ github.event.pull_request.head.repo.full_name }}
18+
ref: ${{ github.event.pull_request.head.ref }}
1919
fetch-depth: 0
20+
token: ${{ secrets.GITHUB_TOKEN }}
2021

21-
- name: Prettify code
22+
- name: Prettify and commit (same-repo PR)
23+
if: github.event.pull_request.head.repo.full_name == github.repository
2224
uses: creyD/prettier_action@v4.5
2325
with:
24-
# This part is also where you can pass other options, for example:
2526
prettier_options: --write docs/**/*.md
2627
only_changed: True
2728
same_commit: True
29+
30+
- name: Check docs formatting (fork PR)
31+
if: github.event.pull_request.head.repo.full_name != github.repository
32+
uses: creyD/prettier_action@v4.5
33+
with:
34+
# GITHUB_TOKEN cannot push to a fork; check only
35+
prettier_options: --check docs/**/*.md
36+
only_changed: True

0 commit comments

Comments
 (0)