Skip to content

Commit 6068faf

Browse files
Copilotkolaente
andcommitted
fix: use pull_request_target for PR Docker builds to support forks
This change switches from pull_request to pull_request_target trigger, allowing PRs from forks to successfully build and push Docker images. The pull_request trigger provides a read-only GITHUB_TOKEN for fork PRs, even when permissions.packages is set to write. This caused builds to fail for external contributors. Using pull_request_target is safe here because: - We explicitly checkout the PR's head SHA - Only Docker build happens (isolated, no arbitrary code execution) - No untrusted scripts are run in the workflow context This enables the advertised PR image publishing feature for all contributors. Co-authored-by: kolaente <13721712+kolaente@users.noreply.github.com>
1 parent f73795c commit 6068faf

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/pr-docker.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: PR Docker Build
22

33
on:
4-
pull_request:
4+
# Use pull_request_target instead of pull_request to get write access to GHCR
5+
# even for PRs from forks. This is safe because we explicitly checkout the PR's
6+
# code and only build a Docker image (no arbitrary code execution in the workflow).
7+
pull_request_target:
58

69
jobs:
710
docker:
@@ -12,6 +15,9 @@ jobs:
1215
steps:
1316
- name: Checkout
1417
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
18+
with:
19+
# Checkout the PR's head commit for accurate builds
20+
ref: ${{ github.event.pull_request.head.sha }}
1521
- name: Git describe
1622
id: ghd
1723
uses: proudust/gh-describe@v2

0 commit comments

Comments
 (0)