Web3 Compatible Tests #2220
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
name: Web3 Compatible Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [ opened, synchronize, reopened ] | |
workflow_dispatch: | |
inputs: | |
dispatch: | |
type: string | |
description: "Dispatch contains pr context that want to trigger web3-compatible test" | |
required: true | |
jobs: | |
dispatch-web3-compatible: | |
strategy: | |
fail-fast: false | |
matrix: | |
net: ["axon"] | |
if: contains(github.event_name, 'workflow_dispatch') | |
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: 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: 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@v3 | |
with: | |
ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main'}} | |
- 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: Deploy Local Network of Axon | |
run: | | |
cargo build | |
rm -rf ./devtools/chain/data | |
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /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/ | |
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() }} | |
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 }}', | |
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
}) | |
web3-compatible: | |
strategy: | |
fail-fast: false | |
matrix: | |
net: ["axon"] | |
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: | |
- 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: Deploy Local Network of Axon | |
run: | | |
cargo build | |
rm -rf ./devtools/chain/data | |
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /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/ |