Skip to content

Commit 76ae655

Browse files
committed
fix(ci): enable e2e tests for fork PRs via pull_request_target
Fork PRs receive a read-only GITHUB_TOKEN under pull_request that cannot push images to the org's GHCR package registry. Switch the branch e2e workflow to pull_request_target which runs in the base repo context with write permissions. Security: the test:e2e label is a maintainer trust gate — only org members can apply it, signalling that the PR code has been reviewed. Changes: - Switch branch-e2e.yml from pull_request to pull_request_target - Add ref input to docker-build.yml and e2e-test.yml so callers can explicitly pass the PR head SHA for checkout and image tagging - Use github.event.pull_request.head.sha instead of github.sha (which points to the base branch under pull_request_target)
1 parent a69ef06 commit 76ae655

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.github/workflows/branch-e2e.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: Branch E2E Checks
22

3+
# pull_request_target runs in the base repo context with write permissions,
4+
# enabling fork PRs to push docker images to GHCR and run e2e tests.
5+
# Security: the test:e2e label is a maintainer trust gate — only org members
6+
# can apply it, signalling that the PR code has been reviewed.
37
on:
4-
pull_request:
8+
pull_request_target:
59
types: [opened, synchronize, reopened, labeled]
610

711
permissions:
@@ -16,6 +20,7 @@ jobs:
1620
component: gateway
1721
platform: linux/arm64
1822
runner: build-arm64
23+
ref: ${{ github.event.pull_request.head.sha }}
1924

2025
build-cluster:
2126
if: contains(github.event.pull_request.labels.*.name, 'test:e2e')
@@ -24,10 +29,12 @@ jobs:
2429
component: cluster
2530
platform: linux/arm64
2631
runner: build-arm64
32+
ref: ${{ github.event.pull_request.head.sha }}
2733

2834
e2e:
2935
needs: [build-gateway, build-cluster]
3036
uses: ./.github/workflows/e2e-test.yml
3137
with:
32-
image-tag: ${{ github.sha }}
38+
image-tag: ${{ github.event.pull_request.head.sha }}
3339
runner: build-arm64
40+
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/docker-build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ on:
3232
required: false
3333
type: string
3434
default: ""
35+
ref:
36+
description: "Git ref to checkout (defaults to the triggering event ref)"
37+
required: false
38+
type: string
39+
default: ""
3540

3641
env:
3742
MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -55,14 +60,15 @@ jobs:
5560
volumes:
5661
- /var/run/docker.sock:/var/run/docker.sock
5762
env:
58-
IMAGE_TAG: ${{ github.sha }}
63+
IMAGE_TAG: ${{ inputs.ref || github.sha }}
5964
IMAGE_REGISTRY: ghcr.io/nvidia/openshell
6065
DOCKER_PUSH: ${{ inputs.push && '1' || '0' }}
6166
DOCKER_PLATFORM: ${{ inputs.platform }}
6267
steps:
6368
- uses: actions/checkout@v4
6469
with:
6570
fetch-depth: 0
71+
ref: ${{ inputs.ref || '' }}
6672

6773
- name: Mark workspace safe for git
6874
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

.github/workflows/e2e-test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ on:
1212
required: false
1313
type: string
1414
default: "build-amd64"
15+
ref:
16+
description: "Git ref to checkout (defaults to the triggering event ref)"
17+
required: false
18+
type: string
19+
default: ""
1520

1621
permissions:
1722
contents: read
@@ -40,6 +45,8 @@ jobs:
4045
OPENSHELL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
4146
steps:
4247
- uses: actions/checkout@v4
48+
with:
49+
ref: ${{ inputs.ref || '' }}
4350

4451
- name: Log in to GHCR
4552
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin

0 commit comments

Comments
 (0)