Skip to content
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

ci: refactor unit test workflow #1354

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ You could link a pull request to an issue by using a supported keyword in the pu
- [ ] Coverage Test
- [ ] E2E Tests
- [ ] Code Format
- [ ] Unit Tests
- [ ] Web3 Compatible Tests
- [ ] OCT 1-5 And 12-15
- [ ] OCT 6-10
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
# 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.head_ref || github.ref }}
# only needs to check a group's latest commit
group: ${{ github.workflow }}-${{ github.ref }}
# only needs to check the group's latest commit
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -44,5 +44,3 @@ jobs:

- name: Run cargo-clippy in Makefile
run: make clippy && git diff --exit-code Cargo.lock

- run: ls -lh target
186 changes: 41 additions & 145 deletions .github/workflows/unit_test.yml
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