-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run acceptance tests on fork #97
Open
edif2008
wants to merge
5
commits into
main
Choose a base branch
from
feat/run-e2e-test-on-fork
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−4
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7bc8781
Update checkout version
edif2008 69d8482
Add condition to run tests only on maintainer's branches
edif2008 fa68829
Add ok-to-test command
edif2008 9dbe48e
Add fork workflow for acceptance tests
edif2008 dd5aa0e
Format YML files
edif2008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event | ||
name: Ok To Test | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
ok-to-test: | ||
runs-on: ubuntu-latest | ||
# required permissions for adding reactions to the pull request comments | ||
permissions: | ||
pull-requests: write | ||
# Only run for PRs, not issue comments | ||
if: ${{ github.event.issue.pull_request }} | ||
steps: | ||
- name: Slash Command Dispatch | ||
uses: peter-evans/slash-command-dispatch@v3 | ||
with: | ||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
reaction-token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-type: pull-request | ||
commands: ok-to-test | ||
# The repository permission level required by the user to dispatch commands. Only allows 1Password collaborators to run this. | ||
permission: write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
on: | ||
repository_dispatch: | ||
types: [ok-to-test-command] | ||
name: Run acceptance tests [fork] | ||
|
||
jobs: | ||
test-with-output-secrets: | ||
if: | | ||
github.event_name == 'repository_dispatch' && | ||
github.event.client_payload.slash_command.args.named.sha != '' && | ||
contains( | ||
github.event.client_payload.pull_request.head.sha, | ||
github.event.client_payload.slash_command.args.named.sha | ||
) | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
auth: [connect, service-account] | ||
exclude: | ||
- os: macos-latest | ||
auth: connect | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.client_payload.pull_request.head.sha }} | ||
- name: Launch 1Password Connect instance | ||
if: ${{ matrix.auth == 'connect' }} | ||
env: | ||
OP_CONNECT_CREDENTIALS: ${{ secrets.OP_CONNECT_CREDENTIALS }} | ||
run: | | ||
echo "$OP_CONNECT_CREDENTIALS" > 1password-credentials.json | ||
docker compose -f tests/fixtures/docker-compose.yml up -d && sleep 10 | ||
- name: Configure Service account | ||
if: ${{ matrix.auth == 'service-account' }} | ||
uses: ./configure | ||
with: | ||
service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
- name: Configure 1Password Connect | ||
if: ${{ matrix.auth == 'connect' }} | ||
uses: ./configure # 1password/load-secrets-action/configure@<version> | ||
with: | ||
connect-host: http://localhost:8080 | ||
connect-token: ${{ secrets.OP_CONNECT_TOKEN }} | ||
- name: Load secrets | ||
id: load_secrets | ||
uses: ./ # 1password/load-secrets-action@<version> | ||
with: | ||
export-env: false | ||
env: | ||
SECRET: op://acceptance-tests/test-secret/password | ||
SECRET_IN_SECTION: op://acceptance-tests/test-secret/test-section/password | ||
MULTILINE_SECRET: op://acceptance-tests/multiline-secret/notesPlain | ||
- name: Assert test secret values | ||
env: | ||
SECRET: ${{ steps.load_secrets.outputs.SECRET }} | ||
SECRET_IN_SECTION: ${{ steps.load_secrets.outputs.SECRET_IN_SECTION }} | ||
MULTILINE_SECRET: ${{ steps.load_secrets.outputs.MULTILINE_SECRET }} | ||
run: ./tests/assert-env-set.sh | ||
test-with-export-env: | ||
if: | | ||
github.event_name == 'repository_dispatch' && | ||
github.event.client_payload.slash_command.args.named.sha != '' && | ||
contains( | ||
github.event.client_payload.pull_request.head.sha, | ||
github.event.client_payload.slash_command.args.named.sha | ||
) | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
auth: [connect, service-account] | ||
exclude: | ||
- os: macos-latest | ||
auth: connect | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.client_payload.pull_request.head.sha }} | ||
- name: Launch 1Password Connect instance | ||
if: ${{ matrix.auth == 'connect' }} | ||
env: | ||
OP_CONNECT_CREDENTIALS: ${{ secrets.OP_CONNECT_CREDENTIALS }} | ||
run: | | ||
echo "$OP_CONNECT_CREDENTIALS" > 1password-credentials.json | ||
docker compose -f tests/fixtures/docker-compose.yml up -d && sleep 10 | ||
- name: Configure Service account | ||
if: ${{ matrix.auth == 'service-account' }} | ||
uses: ./configure | ||
with: | ||
service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
- name: Configure 1Password Connect | ||
if: ${{ matrix.auth == 'connect' }} | ||
uses: ./configure # 1password/load-secrets-action/configure@<version> | ||
with: | ||
connect-host: http://localhost:8080 | ||
connect-token: ${{ secrets.OP_CONNECT_TOKEN }} | ||
- name: Load secrets | ||
id: load_secrets | ||
uses: ./ # 1password/load-secrets-action@<version> | ||
env: | ||
SECRET: op://acceptance-tests/test-secret/password | ||
SECRET_IN_SECTION: op://acceptance-tests/test-secret/test-section/password | ||
MULTILINE_SECRET: op://acceptance-tests/multiline-secret/notesPlain | ||
- name: Assert test secret values | ||
run: ./tests/assert-env-set.sh | ||
- name: Remove secrets | ||
uses: ./ # 1password/load-secrets-action@<version> | ||
with: | ||
unset-previous: true | ||
- name: Assert removed secrets | ||
run: ./tests/assert-env-unset.sh | ||
test-references-with-ids: | ||
if: | | ||
github.event_name == 'repository_dispatch' && | ||
github.event.client_payload.slash_command.args.named.sha != '' && | ||
contains( | ||
github.event.client_payload.pull_request.head.sha, | ||
github.event.client_payload.slash_command.args.named.sha | ||
) | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
auth: [connect, service-account] | ||
exclude: | ||
- os: macos-latest | ||
auth: connect | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.client_payload.pull_request.head.sha }} | ||
- name: Launch 1Password Connect instance | ||
if: ${{ matrix.auth == 'connect' }} | ||
env: | ||
OP_CONNECT_CREDENTIALS: ${{ secrets.OP_CONNECT_CREDENTIALS }} | ||
run: | | ||
echo "$OP_CONNECT_CREDENTIALS" > 1password-credentials.json | ||
docker compose -f tests/fixtures/docker-compose.yml up -d && sleep 10 | ||
- name: Configure Service account | ||
if: ${{ matrix.auth == 'service-account' }} | ||
uses: ./configure | ||
with: | ||
service-account-token: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
- name: Configure 1Password Connect | ||
if: ${{ matrix.auth == 'connect' }} | ||
uses: ./configure # 1password/load-secrets-action/configure@<version> | ||
with: | ||
connect-host: http://localhost:8080 | ||
connect-token: ${{ secrets.OP_CONNECT_TOKEN }} | ||
- name: Load secrets | ||
id: load_secrets | ||
uses: ./ # 1password/load-secrets-action@<version> | ||
with: | ||
export-env: false | ||
env: | ||
SECRET: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/password | ||
SECRET_IN_SECTION: op://v5pz6venw4roosmkzdq2nhpv6u/hrgkzhrlvscomepxlgafb2m3ca/Section_tco6nsqycj6jcbyx63h5isxcny/doxu3mhkozcznnk5vjrkpdqayy | ||
MULTILINE_SECRET: op://v5pz6venw4roosmkzdq2nhpv6u/ghtz3jvcc6dqmzc53d3r3eskge/notesPlain | ||
- name: Assert test secret values | ||
env: | ||
SECRET: ${{ steps.load_secrets.outputs.SECRET }} | ||
SECRET_IN_SECTION: ${{ steps.load_secrets.outputs.SECRET_IN_SECTION }} | ||
MULTILINE_SECRET: ${{ steps.load_secrets.outputs.MULTILINE_SECRET }} | ||
run: ./tests/assert-env-set.sh | ||
update-checks: | ||
# required permissions for updating the status of the pull request checks | ||
permissions: | ||
pull-requests: write | ||
checks: write | ||
runs-on: ubuntu-latest | ||
if: ${{ always() }} | ||
strategy: | ||
matrix: | ||
job-name: | ||
[ | ||
test-with-output-secrets, | ||
test-with-export-env, | ||
test-references-with-ids, | ||
] | ||
needs: | ||
[test-with-output-secrets, test-with-export-env, test-references-with-ids] | ||
steps: | ||
- uses: actions/github-script@v6 | ||
env: | ||
job: ${{ matrix.job-name }} | ||
ref: ${{ github.event.client_payload.pull_request.head.sha }} | ||
conclusion: ${{ needs[format('{0}', matrix.job-name )].result }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { data: checks } = await github.rest.checks.listForRef({ | ||
...context.repo, | ||
ref: process.env.ref | ||
}); | ||
|
||
const check = checks.check_runs.filter(c => c.name === process.env.job); | ||
|
||
const { data: result } = await github.rest.checks.update({ | ||
...context.repo, | ||
check_run_id: check[0].id, | ||
status: 'completed', | ||
conclusion: process.env.conclusion | ||
}); | ||
|
||
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not possible to have a single workflow file that listens for multiple
on
statements? One for our commits and one for forks?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR - It is possible, but I've decided not to merge the two workflows into one file listening for multiple
on
statements.I've chosen separating the two for the following reasons:
Now I can see why having two separate files can become a hassle from a maintenance standpoint, but I would take a step further and say that this can be simplified once we simplify each acceptance test job, since all 3 are over 80% identical. However, I would consider doing this outside of this PR.