From c2867ef3459088120edfac5100d03ed6bcc2b98b Mon Sep 17 00:00:00 2001 From: Flouse <1297478+Flouse@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:38:48 +0800 Subject: [PATCH] ci: refactor unit test workflow (#1354) * ci: refactor unit_test workflow * chore: rm the debug step in clippy.yml --- .github/PULL_REQUEST_TEMPLATE.md | 1 - .github/workflows/clippy.yml | 6 +- .github/workflows/unit_test.yml | 186 +++++++------------------------ 3 files changed, 43 insertions(+), 150 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 151056fd8..c0e65fb13 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index fa7890190..b8cc4966a 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -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: @@ -44,5 +44,3 @@ jobs: - name: Run cargo-clippy in Makefile run: make clippy && git diff --exit-code Cargo.lock - - - run: ls -lh target diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index 680e998ed..d01271d0f 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -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