Skip to content

Commit a5e5c78

Browse files
authored
Merge pull request #97 from 1Password/feat/run-e2e-test-on-fork
Currently an external contributor can't have the acceptance tests run on their PR because pull_request doesn't give access to the secrets needed for them. Therefore, in this PR we create a new workflow that is identical to the one for existing acceptance tests, with the following differences: This workflow can be triggered with the command /ok-to-test sha="<contributor's latest commit sha>" by one of this repo's maintainers. After the acceptance tests finish, their result will be updated to the PR's list of checks.
2 parents a525a84 + 7d16183 commit a5e5c78

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

.github/workflows/ok-to-test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event
2+
name: Ok To Test
3+
4+
on:
5+
issue_comment:
6+
types: [created]
7+
8+
jobs:
9+
ok-to-test:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write # For adding reactions to the pull request comments
13+
contents: write # For executing the repository_dispatch event
14+
# Only run for PRs, not issue comments
15+
if: ${{ github.event.issue.pull_request }}
16+
steps:
17+
- name: Slash Command Dispatch
18+
uses: peter-evans/slash-command-dispatch@v3
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
reaction-token: ${{ secrets.GITHUB_TOKEN }}
22+
issue-type: pull-request
23+
commands: ok-to-test
24+
# The repository permission level required by the user to dispatch commands. Only allows 1Password collaborators to run this.
25+
permission: write

.github/workflows/test-fork.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
on:
2+
repository_dispatch:
3+
types: [ok-to-test-command]
4+
name: Run acceptance tests [fork]
5+
6+
jobs:
7+
test-with-output-secrets:
8+
if: |
9+
github.event_name == 'repository_dispatch' &&
10+
github.event.client_payload.slash_command.args.named.sha != '' &&
11+
contains(
12+
github.event.client_payload.pull_request.head.sha,
13+
github.event.client_payload.slash_command.args.named.sha
14+
)
15+
uses: ./.github/workflows/acceptance-test.yml
16+
secrets: inherit
17+
with:
18+
secret: op://acceptance-tests/test-secret/password
19+
secret-in-section: op://acceptance-tests/test-secret/test-section/password
20+
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
21+
export-env: false
22+
test-with-export-env:
23+
if: |
24+
github.event_name == 'repository_dispatch' &&
25+
github.event.client_payload.slash_command.args.named.sha != '' &&
26+
contains(
27+
github.event.client_payload.pull_request.head.sha,
28+
github.event.client_payload.slash_command.args.named.sha
29+
)
30+
uses: ./.github/workflows/acceptance-test.yml
31+
secrets: inherit
32+
with:
33+
secret: op://acceptance-tests/test-secret/password
34+
secret-in-section: op://acceptance-tests/test-secret/test-section/password
35+
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
36+
export-env: true
37+
test-references-with-ids:
38+
if: |
39+
github.event_name == 'repository_dispatch' &&
40+
github.event.client_payload.slash_command.args.named.sha != '' &&
41+
contains(
42+
github.event.client_payload.pull_request.head.sha,
43+
github.event.client_payload.slash_command.args.named.sha
44+
)
45+
uses: ./.github/workflows/acceptance-test.yml
46+
secrets: inherit
47+
with:
48+
secret: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password
49+
secret-in-section: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy
50+
multiline-secret: op://v5pz6venw4roosmkzdq2nhpv6u/ghtz3jvcc6dqmzc53d3r3eskge/notesPlain
51+
export-env: false
52+
update-checks:
53+
# required permissions for updating the status of the pull request checks
54+
permissions:
55+
pull-requests: write
56+
checks: write
57+
runs-on: ubuntu-latest
58+
if: ${{ always() }}
59+
strategy:
60+
matrix:
61+
job-name:
62+
[
63+
test-with-output-secrets,
64+
test-with-export-env,
65+
test-references-with-ids,
66+
]
67+
needs:
68+
[test-with-output-secrets, test-with-export-env, test-references-with-ids]
69+
steps:
70+
- uses: actions/github-script@v6
71+
env:
72+
job: ${{ matrix.job-name }}
73+
ref: ${{ github.event.client_payload.pull_request.head.sha }}
74+
conclusion: ${{ needs[format('{0}', matrix.job-name )].result }}
75+
with:
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
script: |
78+
const { data: checks } = await github.rest.checks.listForRef({
79+
...context.repo,
80+
ref: process.env.ref
81+
});
82+
83+
const check = checks.check_runs.filter(c => c.name === process.env.job);
84+
85+
const { data: result } = await github.rest.checks.update({
86+
...context.repo,
87+
check_run_id: check[0].id,
88+
status: 'completed',
89+
conclusion: process.env.conclusion
90+
});
91+
92+
return result;

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ jobs:
1515
- run: npm ci
1616
- run: npm test
1717
test-with-output-secrets:
18+
if: |
19+
github.ref == 'refs/heads/main' ||
20+
(
21+
github.event_name == 'pull_request' &&
22+
github.event.pull_request.head.repo.full_name == github.repository
23+
)
1824
uses: ./.github/workflows/acceptance-test.yml
1925
secrets: inherit
2026
with:
@@ -23,6 +29,12 @@ jobs:
2329
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
2430
export-env: false
2531
test-with-export-env:
32+
if: |
33+
github.ref == 'refs/heads/main' ||
34+
(
35+
github.event_name == 'pull_request' &&
36+
github.event.pull_request.head.repo.full_name == github.repository
37+
)
2638
uses: ./.github/workflows/acceptance-test.yml
2739
secrets: inherit
2840
with:
@@ -31,6 +43,12 @@ jobs:
3143
multiline-secret: op://acceptance-tests/multiline-secret/notesPlain
3244
export-env: true
3345
test-references-with-ids:
46+
if: |
47+
github.ref == 'refs/heads/main' ||
48+
(
49+
github.event_name == 'pull_request' &&
50+
github.event.pull_request.head.repo.full_name == github.repository
51+
)
3452
uses: ./.github/workflows/acceptance-test.yml
3553
secrets: inherit
3654
with:

0 commit comments

Comments
 (0)