Skip to content

Commit 9e3113e

Browse files
ci: fix workflows that always fail for fork PRs (#5062) (#5065)
Two CI workflows failed whenever a PR came from a fork because the pull_request trigger runs in a sandboxed context with no write access and no secrets: - Changelog Preview: switched pull_request → pull_request_target so the workflow runs in the base repo context and can post PR comments. Also tightened permissions from contents:write to contents:read since the workflow only needs to write to pull-requests. - Format Code: pull_request_target cannot push to a fork branch anyway, so the fix is fork-aware logic in the commit step. For fork PRs, formatting issues fail the check with a clear message telling the contributor which dotnet format command to run locally. Internal PR behaviour (auto-commit and push) is unchanged. Warden was also listed as failing but is already resolved — warden.yml was removed because Warden is now a globally-enabled GitHub App with its own credentials, unaffected by fork PR restrictions. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 388121c commit 9e3113e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

.github/workflows/changelog-preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Changelog Preview
22
on:
3-
pull_request:
3+
pull_request_target:
44
types:
55
- opened
66
- synchronize
@@ -9,7 +9,7 @@ on:
99
- labeled
1010
- unlabeled
1111
permissions:
12-
contents: write
12+
contents: read
1313
pull-requests: write
1414
statuses: write
1515

.github/workflows/format-code.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,18 @@ jobs:
5454
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore
5555
# we need to pass the current branch, otherwise we can't commit the changes.
5656
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs.
57+
#
58+
# For fork PRs we can't push back to the contributor's branch, so we fail the check
59+
# instead — prompting the contributor to run dotnet format locally.
5760
- name: Commit Formatted Code
58-
run: ./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF
61+
run: |
62+
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
63+
if [[ $(git status) != *"nothing to commit"* ]]; then
64+
echo "::error::Formatting issues found. Please run the following command locally and push the result:"
65+
echo "::error:: dotnet format Sentry.slnx --no-restore --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs"
66+
exit 1
67+
fi
68+
echo "All code formatted correctly."
69+
else
70+
./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF
71+
fi

0 commit comments

Comments
 (0)