diff --git a/.github/workflows/entry_workflow.yml b/.github/workflows/entry_workflow.yml index 3bfd1a874..1840d88a7 100644 --- a/.github/workflows/entry_workflow.yml +++ b/.github/workflows/entry_workflow.yml @@ -8,7 +8,8 @@ on: jobs: run-ci: - name: from-comments + name: run-ci-from-pr-comment + # PullRequestEvent: https://docs.github.com/en/rest/overview/github-event-types?apiVersion=2022-11-28#pullrequestevent if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/run-ci') runs-on: ubuntu-22.04 # When the permissions key is used, all unspecified permissions are set to no access, with the exception of the metadata scope, which always gets read access. @@ -53,24 +54,11 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number, }); + let check_list=` \### CI test list: `; - // check Chaos CI exist or not - const chaos_match = pr.data.body.includes("[x] Chaos CI"); - if (chaos_match) { - const resp = await github.rest.actions.createWorkflowDispatch({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: "chaos.yml", - ref: "main", - inputs: { - dispatch: jsonDispatch, - } - }); - core.info(`${JSON.stringify(resp, null, 2)}`); - check_list=`${check_list}\n - Chaos CI`; - } + // check Coverage Test exist or not const coverage_match = pr.data.body.includes("[x] Coverage Test"); if (coverage_match) { @@ -78,7 +66,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "coverage.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -86,6 +74,7 @@ jobs: core.info(`${JSON.stringify(resp, null, 2)}`); check_list=`${check_list}\n - Coverage Test`; } + // check E2E Tests exist or not const e2e_match = pr.data.body.includes("[x] E2E Tests"); if (e2e_match) { @@ -93,7 +82,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "e2e_test.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -108,7 +97,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "openzeppelin_test_1_5_and_12_15.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -123,7 +112,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "openzeppelin_test_6_10.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -138,7 +127,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "openzeppelin_test_11.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -153,7 +142,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "openzeppelin_test_16_19.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -168,7 +157,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "v3_core_test.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -183,7 +172,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, workflow_id: "web3_compatible.yml", - ref: "main", + ref: `main`, inputs: { dispatch: jsonDispatch, } @@ -203,6 +192,7 @@ jobs: # https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment # The `pull-requests: write` permission is required in the step. - name: Post a coment about component information to PR + if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission) id: post_workflow_run_comment uses: actions/github-script@v6 with: diff --git a/.github/workflows/regression_testing.yml b/.github/workflows/regression_testing.yml index 3e20bd65a..472a57aa6 100644 --- a/.github/workflows/regression_testing.yml +++ b/.github/workflows/regression_testing.yml @@ -7,6 +7,7 @@ on: jobs: invoke-fmt-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke fmt test @@ -15,9 +16,9 @@ jobs: with: workflow: Code Format token: ${{ secrets.GITHUB_TOKEN }} - inputs: '{ "dispatch": "regression" }' invoke-E2E-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke fmt test @@ -29,6 +30,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-v3-core-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke v3 core test @@ -41,6 +43,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-web3-compatible-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke web3 compatible test @@ -53,6 +56,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-openzeppelin-test-1-5-and-12-15-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke OCT 1-5 And 12-15 test @@ -65,6 +69,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-OCT-6-10-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke OCT 1-5 And 12-15 test @@ -77,6 +82,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-OCT-11-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke OCT 11 test @@ -89,6 +95,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-OCT-16-19-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke OCT 16-19 test @@ -101,6 +108,7 @@ jobs: inputs: '{ "dispatch": "regression" }' invoke-chaos-test: + if: github.repository_owner == 'axonweb3' runs-on: ubuntu-latest steps: - name: Invoke OCT 16-19 test @@ -115,7 +123,7 @@ jobs: output-result: runs-on: ubuntu-latest needs: [invoke-fmt-test,invoke-E2E-test,invoke-v3-core-test,invoke-web3-compatible-test,invoke-openzeppelin-test-1-5-and-12-15-test,invoke-OCT-6-10-test,invoke-OCT-11-test,invoke-OCT-16-19-test,invoke-chaos-test] - if: always() + if: github.repository_owner == 'axonweb3' && always() steps: - name: send message uses: nobrayner/discord-webhook@v1 diff --git a/.github/workflows/web3_compatible.yml b/.github/workflows/web3_compatible.yml index 07b4982e1..710887581 100644 --- a/.github/workflows/web3_compatible.yml +++ b/.github/workflows/web3_compatible.yml @@ -1,25 +1,16 @@ name: Web3 Compatible 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 web3-compatible test" - required: true + required: false jobs: - # Build Axon and cache the binary - build-axon: - uses: ./.github/workflows/build.yml - - dispatch-web3-compatible: - needs: build-axon + web3-compatible-test: strategy: matrix: # Supported GitHub-hosted runners and hardware resources @@ -27,192 +18,117 @@ jobs: os: [ubuntu-22.04] fail-fast: false runs-on: ${{ matrix.os }} - if: contains(github.event_name, 'workflow_dispatch') - outputs: - output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }} + env: + IS_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }} + IS_REGRESSION: ${{ github.event.inputs.dispatch == 'regression' }} + + # When the permissions key is used, all unspecified permissions are set to no access, with the exception of the metadata scope, which always gets read access. + # See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + statuses: write + 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: github.event_name == 'workflow_dispatch' && - github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression' + - name: Get the git ref of Axon uses: actions/github-script@v6 - id: get_sha + id: axon_git_ref 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: 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 + if (`${{ env.IS_DISPATCH }}` == 'true' && `${{ env.IS_REGRESSION }}` == 'false' && `${{ github.event.inputs.dispatch }}`) { + const dispatch = JSON.parse(`${{ github.event.inputs.dispatch }}`); + const prNum = dispatch.issue.number; + const { data: pullRequest } = await github.rest.pulls.get({ + owner: dispatch.repo.owner, + repo: dispatch.repo.repo, + pull_number: dispatch.issue.number, + }); + return pullRequest.head.sha; + } + return `${{ github.sha }}`; + result-encoding: string + + - name: Checkout Axon ${{ steps.axon_git_ref.outputs.result}} uses: actions/checkout@v3 with: - ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main'}} - - uses: actions/checkout@v3 + ref: ${{ steps.axon_git_ref.outputs.result}} + + - 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-${{ hashFiles('**/Cargo.lock') }} + - name: Build Axon in the development profile + run: cargo build + - name: Deploy Local Network of Axon + run: | + rm -rf ./devtools/chain/data + ./target/debug/axon run \ + --config devtools/chain/config.toml \ + --chain-spec devtools/chain/specs/single_node/chain-spec.toml \ + > /tmp/log 2>&1 & + + - name: Checkout gpBlockchain/axon-test + uses: actions/checkout@v3 with: repository: gpBlockchain/axon-test path: axon-test + - uses: actions/setup-node@v3 with: - node-version: "16" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + node-version: "18" + - 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-path.outputs.dir }} - ~/.npm - key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }} + ${{ 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: Cache of the axon binary - uses: actions/cache@v3 - with: - path: | - target/debug/axon - target/release/axon - key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-axon-${{ github.sha }} - - name: Deploy Local Network of Axon - run: | - rm -rf ./devtools/chain/data - ./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 & - - name: Run Test + + - name: Run axon-test + working-directory: axon-test run: | - cd /home/runner/work/axon/axon/axon-test npm install npm run test:test --network=axon_test --grep="" + - name: Check Axon Status if: success() || failure() run: | - curl http://localhost:8000 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}' + npx zx <<'EOF' + import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js' + await waitXBlocksPassed('http://127.0.0.1:8000', 2); + EOF - name: Publish reports - if: always() + if: success() || failure() uses: actions/upload-artifact@v3 with: name: jfoa-build-reports-${{ runner.os }} path: axon-test/mochawesome-report/ - finally: - name: Finally - needs: [ dispatch-web3-compatible ] - 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() }} + # The `statuses: write` permission is required in this step. + - name: Update the commit Status + if: always() && env.IS_DISPATCH == 'true' && env.IS_REGRESSION == 'false' + uses: actions/github-script@v6 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-web3-compatible.outputs.output-sha }}', + sha: '${{ steps.axon_git_ref.outputs.result}}', target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' }) - - web3-compatible: - needs: build-axon - 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 }} - if: | - (contains(fromJson('["dependabot[bot]" ]'), github.actor) && github.event_name == 'pull_request') || - (contains(github.event_name, 'push') && github.ref == 'refs/heads/main' ) - steps: - - name: Git checkout - uses: actions/checkout@v3 - - uses: actions/checkout@v3 - with: - repository: gpBlockchain/axon-test - path: axon-test - - uses: actions/setup-node@v3 - with: - node-version: "16" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $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-path.outputs.dir }} - ~/.npm - key: ${{ runner.os }}-node_modules-${{ hashFiles('/home/runner/work/**/package-lock.json', '/home/runner/work/**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-node_modules- - - name: Cache of the axon binary - uses: actions/cache@v3 - with: - path: | - target/debug/axon - target/release/axon - key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-axon-${{ github.sha }} - - name: Deploy Local Network of Axon - run: | - rm -rf ./devtools/chain/data - ./target/debug/axon run --config devtools/chain/config.toml --chain-spec devtools/chain/specs/single_node/chain-spec.toml > /tmp/log 2>&1 & - - name: Run Test - run: | - cd /home/runner/work/axon/axon/axon-test - npm install - npm run test:test --network=axon_test --grep="" - - - name: Check Axon Status - if: success() || failure() - run: | - curl http://localhost:8000 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}' - - name: Publish reports - if: always() - uses: actions/upload-artifact@v3 - with: - name: jfoa-build-reports-${{ runner.os }} - path: axon-test/mochawesome-report/