Skip to content

Commit b58a3e3

Browse files
authored
ci(e2e): allow fork PR runs via 'safe to test' label (#55)
1 parent bb6297e commit b58a3e3

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,62 @@ on:
44
push:
55
branches: [ '**' ] # Run on all branches
66
pull_request:
7-
branches: [ '**' ] # Run on all PRs
7+
branches: [ '**' ] # Run on internal PRs (skipped for fork PRs - see job `if`)
8+
pull_request_target:
9+
# Used to run E2E on fork PRs after a maintainer applies the `safe to test` label.
10+
types: [ labeled, synchronize ]
811
workflow_dispatch: # Allow manual trigger
912

13+
permissions:
14+
contents: read
15+
pull-requests: write # only used by reset-trust-on-sync to remove the label
16+
1017
jobs:
18+
# When new commits arrive on a PR that already carries `safe to test`, drop the
19+
# label so a maintainer must re-review the diff before E2E runs again with secrets.
20+
reset-trust-on-sync:
21+
name: Reset trust label on new commits
22+
if: >
23+
github.event_name == 'pull_request_target' &&
24+
github.event.action == 'synchronize' &&
25+
contains(github.event.pull_request.labels.*.name, 'safe to test')
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Remove "safe to test" label
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
gh api -X DELETE \
33+
"repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/safe%20to%20test" \
34+
|| true
35+
1136
e2e-tests-saas:
1237
name: E2E Tests on SaaS Environment
1338
runs-on: ubuntu-latest
1439
timeout-minutes: 30
40+
# Run on:
41+
# - push to any branch
42+
# - manual workflow_dispatch
43+
# - pull_request from the same repo (internal PR)
44+
# - pull_request_target only when the `safe to test` label is being applied
45+
if: >
46+
github.event_name == 'push' ||
47+
github.event_name == 'workflow_dispatch' ||
48+
(github.event_name == 'pull_request' &&
49+
github.event.pull_request.head.repo.full_name == github.repository) ||
50+
(github.event_name == 'pull_request_target' &&
51+
github.event.action == 'labeled' &&
52+
github.event.label.name == 'safe to test')
1553
1654
steps:
1755
- name: Checkout code
1856
uses: actions/checkout@v5
57+
with:
58+
# For pull_request_target the default ref is the base branch; we must
59+
# explicitly check out the PR head SHA so we actually test the PR's code.
60+
# For all other events the default ref is correct.
61+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
62+
persist-credentials: false
1963

2064
- name: Set up Go
2165
uses: actions/setup-go@v6
@@ -41,4 +85,3 @@ jobs:
4185
--jfrog.projectKey=${{ secrets.EVIDENCE_PROJECT_KEY }}
4286
env:
4387
CI: true
44-

.github/workflows/pr-labels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
- name: Check if PR has allowed labels
1212
uses: jfrog/.github/actions/pr-labels@main
1313
with:
14-
allowed-labels: 'bug,breaking change,new feature,feature,enhancement,improvement,security,vulnerability,performance,optimization,documentation,docs,test,testing,dependencies,deps,ci,build,maintenance,refactor,chore,style,question,wontfix,ignore for release,feature request'
14+
allowed-labels: 'bug,breaking change,new feature,feature,enhancement,improvement,security,vulnerability,performance,optimization,documentation,docs,test,testing,dependencies,deps,ci,build,maintenance,refactor,chore,style,question,wontfix,ignore for release,feature request,safe to test'

0 commit comments

Comments
 (0)