Skip to content

Commit

Permalink
chore(CI): refactor openzeppelin-tests (#1543)
Browse files Browse the repository at this point in the history
* chore(CI): refactor `openzeppelin_test_1_5_and_12_15` workflow

* chore(CI): refactor `openzeppelin_test_6_10` workflow

* chore(CI): refactor `openzeppelin_test_11` workflow

* chore(CI): refactor `openzeppelin_test_16_19` workflow

* chore(CI): remove `push` and `pull_request` events in time consuming workflows
  • Loading branch information
Flouse authored Nov 14, 2023
1 parent 0fb4d7f commit f0fc4be
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 281 deletions.
123 changes: 52 additions & 71 deletions .github/workflows/openzeppelin_test_11.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,68 @@
name: OCT 11

on:
push:
branches:
- main
merge_group:
workflow_dispatch:
inputs:
dispatch:
type: string
description: "Dispatch contains pr context that want to trigger OCT 11 test"
description: "'regression' or the JSON of a PR's context"
required: true

jobs:
openzeppelin-contracts-1:
openzeppelin-contracts-3:
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 }}
outputs:
output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }}

# 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

env:
IS_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }}
IS_REGRESSION: ${{ github.event.inputs.dispatch == 'regression' }}

steps:
- name: Generate axon-bot token
if: contains(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'
- 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: 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
- 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 commit ${{ steps.axon_git_ref.outputs.result}}
uses: actions/checkout@v4
with:
ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main'}}
- uses: actions/checkout@v4
ref: ${{ steps.axon_git_ref.outputs.result}}

- name: Git checkout axonweb3/openzeppelin-contracts
uses: actions/checkout@v4
with:
repository: axonweb3/openzeppelin-contracts
ref: c2c4b8f591b7bc048dcbcf45dd2a1d2017074107
path: openzeppelin-contracts

- uses: actions/setup-node@v4
with:
# TODO: upgrade node-version
node-version: "16"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand Down Expand Up @@ -123,7 +109,12 @@ jobs:
--config devtools/chain/config.toml \
>> /tmp/log 2>&1 &
- name: Check Axon Status Before Test
npx zx <<'EOF'
import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js'
await retry(3, '6s', () => waitXBlocksPassed('http://127.0.0.1:8000', 2))
EOF
- name: Check Axon web3_clientVersion Before Test
run: |
MAX_RETRIES=10
for i in $(seq 1 $MAX_RETRIES); do
Expand Down Expand Up @@ -159,39 +150,29 @@ jobs:
- 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 retry(3, '6s', () => waitXBlocksPassed('http://127.0.0.1:8000', 2))
EOF
- name: Publish reports
if: always()
uses: actions/upload-artifact@v3
with:
name: jfoa-build-reports-${{ runner.os }}
path: openzeppelin-contracts/mochawesome-report/

finally:
name: Finally
needs: [ openzeppelin-contracts-1 ]
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.openzeppelin-contracts-1.outputs.output-sha }}',
sha: '${{ steps.axon_git_ref.outputs.result}}',
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
})
117 changes: 47 additions & 70 deletions .github/workflows/openzeppelin_test_16_19.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,68 @@
name: OCT 16-19

on:
push:
branches:
- main
merge_group:
workflow_dispatch:
inputs:
dispatch:
type: string
description: "Dispatch contains pr context that want to trigger OCT 16-19 test"
description: "'regression' or the JSON of a PR's context"
required: true

jobs:
openzeppelin-contracts-1:
openzeppelin-contracts-4:
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 }}
outputs:
output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }}

# 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

env:
IS_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }}
IS_REGRESSION: ${{ github.event.inputs.dispatch == 'regression' }}

steps:
- name: Generate axon-bot token
if: contains(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'
- 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: 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
- 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 commit ${{ steps.axon_git_ref.outputs.result}}
uses: actions/checkout@v4
with:
ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main' }}
- uses: actions/checkout@v4
ref: ${{ steps.axon_git_ref.outputs.result}}

- name: Git checkout axonweb3/openzeppelin-contracts
uses: actions/checkout@v4
with:
repository: axonweb3/openzeppelin-contracts
ref: c2c4b8f591b7bc048dcbcf45dd2a1d2017074107
path: openzeppelin-contracts

- uses: actions/setup-node@v4
with:
# TODO: upgrade node-version
node-version: "16"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand Down Expand Up @@ -123,7 +109,12 @@ jobs:
--config devtools/chain/config.toml \
>> /tmp/log 2>&1 &
- name: Check Axon Status Before Test
npx zx <<'EOF'
import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js'
await retry(3, '6s', () => waitXBlocksPassed('http://127.0.0.1:8000', 2))
EOF
- name: Check Axon web3_clientVersion Before Test
run: |
MAX_RETRIES=10
for i in $(seq 1 $MAX_RETRIES); do
Expand Down Expand Up @@ -182,31 +173,17 @@ jobs:
name: jfoa-build-reports-${{ runner.os }}
path: openzeppelin-contracts/mochawesome-report/

finally:
name: Finally
needs: [ openzeppelin-contracts-1 ]
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.openzeppelin-contracts-1.outputs.output-sha }}',
sha: '${{ steps.axon_git_ref.outputs.result}}',
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
})
Loading

0 comments on commit f0fc4be

Please sign in to comment.