-
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 unit test workflow (#1354)
* ci: refactor unit_test workflow * chore: rm the debug step in clippy.yml
- Loading branch information
Showing
3 changed files
with
43 additions
and
150 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,156 +1,52 @@ | ||
name: Unit 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 unit test" | ||
required: true | ||
|
||
jobs: | ||
set-output: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }} | ||
steps: | ||
- name: Generate axon-bot token | ||
if: | | ||
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 | ||
Test: | ||
if: | | ||
(contains(github.event_name, 'workflow_dispatch')) || | ||
(contains(github.event_name, 'pull_request') && contains(fromJson('["dependabot[bot]" ]'), github.actor)) || | ||
(contains(github.event_name, 'push') && github.ref == 'refs/heads/main') | ||
runs-on: ubuntu-latest | ||
needs: set-output | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ needs.set-output.outputs.output-sha }} | ||
- uses: lyricwulf/abc@v1 | ||
with: | ||
linux: m4 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
components: rustfmt, clippy | ||
|
||
- uses: Swatinem/rust-cache@v2 | ||
|
||
- name: CI | ||
run: make test | ||
# 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 | ||
|
||
Metadata-Test: | ||
if: | | ||
(contains(github.event_name, 'workflow_dispatch')) || | ||
(contains(github.event_name, 'pull_request') && contains(fromJson('["dependabot[bot]" ]'), github.actor)) || | ||
(contains(github.event_name, 'push') && github.ref == 'refs/heads/main') | ||
runs-on: ubuntu-latest | ||
needs: set-output | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ needs.set-output.outputs.output-sha }} | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16" | ||
|
||
- name: CI | ||
run: make metadata-test | ||
jobs: | ||
rust-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 }} | ||
|
||
Crosschain-Test: | ||
if: | | ||
(contains(github.event_name, 'workflow_dispatch')) || | ||
(contains(github.event_name, 'pull_request') && contains(fromJson('["dependabot[bot]" ]'), github.actor)) || | ||
(contains(github.event_name, 'push') && github.ref == 'refs/heads/main') | ||
runs-on: ubuntu-latest | ||
needs: set-output | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ needs.set-output.outputs.output-sha }} | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16" | ||
|
||
- name: CI | ||
run: make crosschain-test | ||
|
||
finally: | ||
name: Finally | ||
if: always() && contains(github.event_name, 'workflow_dispatch') && | ||
github.event.inputs.dispatch != 'regression' && github.repository_owner == 'axonweb3' | ||
needs: [ Test,Metadata-Test,Crosschain-Test,set-output] | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Cache of Cargo | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: | | ||
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-test | ||
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo | ||
- name: Run Rust unit-test | ||
run: make test | ||
|
||
other-unit-test: | ||
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.set-output.outputs.output-sha }}', | ||
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | ||
}) | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- name: Run metadata-test | ||
run: make metadata-test | ||
- name: Run crosschain-test | ||
run: make crosschain-test |