-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: refactor the e2e test workflow (#1436)
* chore(CI): refactor the E2E test workflow * chore(CI): install GNU M4 for the E2E test job * chore(deps): update puppeteer in tests/e2e * chore(CI): rewine the cargo-build-cache key * node-version: "16" * chore(deps): update eslint in tests/e2e * chore(CI): run E2E test for every commit With cache, `make e2e-test-ci` only takes only 7 minutes.
- Loading branch information
Showing
8 changed files
with
245 additions
and
389 deletions.
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
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
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 |
---|---|---|
@@ -1,136 +1,73 @@ | ||
name: E2E Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [ opened, synchronize, reopened ] | ||
merge_group: | ||
workflow_dispatch: | ||
inputs: | ||
dispatch: | ||
type: string | ||
description: "Dispatch contains pr context that want to trigger e2e test" | ||
required: true | ||
|
||
# Ensure that only a single job or workflow using the same concurrency group will run at a time. | ||
# see https://docs.github.com/en/actions/using-jobs/using-concurrency#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
# only needs to test the group's latest commit | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
dispatch-build: | ||
if: contains(github.event_name, 'workflow_dispatch') | ||
runs-on: ubuntu-latest | ||
outputs: | ||
output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }} | ||
e2e-test: | ||
strategy: | ||
matrix: | ||
# Supported GitHub-hosted runners and hardware resources | ||
# see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources | ||
os: [ubuntu-22.04] | ||
fail-fast: false | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Generate axon-bot token | ||
if: contains(github.event_name, 'workflow_dispatch') && | ||
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression' | ||
id: generate_axon_bot_token | ||
uses: wow-actions/use-app-token@v2 | ||
with: | ||
app_id: ${{ secrets.AXON_BOT_APP_ID }} | ||
private_key: ${{ secrets.AXON_BOT_PRIVATE_KEY }} | ||
- name: Event is dispatch | ||
if: contains(github.event_name, 'workflow_dispatch') && | ||
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression' | ||
uses: actions/github-script@v6 | ||
id: get_sha | ||
with: | ||
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }} | ||
script: | | ||
const dispatch = JSON.parse(`${{ github.event.inputs.dispatch }}`); | ||
const pr = ( | ||
await github.rest.pulls.get({ | ||
owner: dispatch.repo.owner, | ||
repo: dispatch.repo.repo, | ||
pull_number: dispatch.issue.number, | ||
}) | ||
).data.head; | ||
github.rest.repos.createCommitStatus({ | ||
state: 'pending', | ||
owner: dispatch.repo.owner, | ||
repo: dispatch.repo.repo, | ||
context: '${{ github.workflow }}', | ||
sha: pr.sha, | ||
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | ||
}) | ||
return pr.sha | ||
- name: Escape multiple lines test inputs | ||
if: contains(github.event_name, 'workflow_dispatch') && | ||
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression' | ||
id: escape_multiple_lines_test_inputs | ||
run: | | ||
inputs=${{ steps.get_sha.outputs.result}} | ||
inputs="${inputs//'%'/'%25'}" | ||
inputs="${inputs//'\n'/'%0A'}" | ||
inputs="${inputs//'\r'/'%0D'}" | ||
echo "result=$inputs" >> $GITHUB_OUTPUT | ||
- name: Git checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main' }} | ||
- uses: lyricwulf/abc@v1 | ||
with: | ||
linux: m4 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
- name: Cache of Cargo | ||
uses: actions/cache@v3 | ||
with: | ||
node-version: "16" | ||
cache: "yarn" | ||
cache-dependency-path: "tests/e2e/yarn.lock" | ||
|
||
- name: E2E Tests Linting | ||
run: make e2e-test-lint | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build | ||
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo | ||
- name: E2E Tests | ||
run: make e2e-test-ci | ||
finally: | ||
name: Finally | ||
needs: [ dispatch-build ] | ||
if: always() && contains(github.event_name, 'workflow_dispatch') && | ||
github.event.inputs.dispatch != 'regression' && github.repository_owner == 'axonweb3' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Generate axon-bot token | ||
id: generate_axon_bot_token | ||
uses: wow-actions/use-app-token@v2 | ||
with: | ||
app_id: ${{ secrets.AXON_BOT_APP_ID }} | ||
private_key: ${{ secrets.AXON_BOT_PRIVATE_KEY }} | ||
- if: contains(join(needs.*.result, ';'), 'failure') || contains(join(needs.*.result, ';'), 'cancelled') | ||
run: exit 1 | ||
- uses: actions/github-script@v6 | ||
if: ${{ always() }} | ||
with: | ||
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }} | ||
script: | | ||
github.rest.repos.createCommitStatus({ | ||
state: '${{ job.status }}', | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
context: '${{ github.workflow }}', | ||
sha: '${{ needs.dispatch-build.outputs.output-sha }}', | ||
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | ||
}) | ||
build: | ||
if: | | ||
(contains(fromJson('["dependabot[bot]" ]'), github.actor) && github.event_name == 'pull_request') || | ||
(contains(github.event_name, 'push') && github.ref == 'refs/heads/main' ) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: lyricwulf/abc@v1 | ||
with: | ||
# https://www.gnu.org/software/m4/ | ||
linux: m4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
# TODO: use Node.js 18 | ||
- name: Use Node.js 16 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16" | ||
cache: "yarn" | ||
cache-dependency-path: "tests/e2e/yarn.lock" | ||
- name: Get yarn cache directory | ||
id: yarn-cache-dir | ||
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT} | ||
- name: Get npm cache directory | ||
id: npm-cache-dir | ||
shell: bash | ||
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} | ||
- name: Node Cache | ||
uses: actions/cache@v3 | ||
id: npm-and-yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: | | ||
${{ steps.yarn-cache-dir.outputs.dir }} | ||
${{ steps.npm-cache-dir.outputs.dir }} | ||
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-node_modules- | ||
- name: E2E Tests Linting | ||
- name: E2E Tests Linting in tests/e2e | ||
run: make e2e-test-lint | ||
|
||
- name: E2E Tests | ||
- name: E2E Tests in tests/e2e | ||
run: make e2e-test-ci |
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
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
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
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.