chore(CI): add Start Single Axon Node
test
#2333
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: From Issue Comments | |
on: | |
issue_comment: | |
types: [created] | |
pull_request: | |
types: [opened, synchronize] | |
jobs: | |
test: | |
name: from-comments | |
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/run-ci') && github.repository_owner == 'axonweb3' | |
runs-on: ubuntu-20.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. | |
# See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token | |
permissions: | |
contents: read | |
steps: | |
- name: Query author repository permissions | |
uses: octokit/[email protected] | |
id: user_permission | |
with: | |
route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}/permission | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- 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 }} | |
- uses: actions/checkout@v3 | |
- name: Dispatch ci if user does have correct permission | |
if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission) | |
id: dispatch | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }} | |
script: | | |
const dispatch = { | |
comment_body: `${{ github.event.comment.body }}`, | |
repo: context.repo, | |
issue: context.issue, | |
}; | |
const jsonDispatch = JSON.stringify(dispatch) | |
.replace(/\\b/g, "\\\\b") | |
.replace(/\\f/g, "\\\\f") | |
.replace(/\\n/g, "\\\\n") | |
.replace(/\\r/g, "\\\\r") | |
.replace(/\\t/g, "\\\\t"); | |
// get pr comments body,not issue comments body | |
const pr = | |
await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
}); | |
let check_list=` | |
\### CI test list: | |
`; | |
// check Code Format exist or not | |
const fmt_match = pr.data.body.includes("[x] Code Format"); | |
if (fmt_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "fmt.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - Code Format`; | |
} | |
// check Cargo Clippy exist or not | |
const clippy_match = pr.data.body.includes("[x] Cargo Clippy"); | |
if (clippy_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "clippy.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - Cargo Clippy`; | |
} | |
// 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) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "coverage.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
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) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "e2e_test.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - E2E Tests`; | |
} | |
// check OCT 1-5 And 12-15 exist or not | |
const OCT_match = pr.data.body.includes("[x] OCT 1-5 And 12-15"); | |
if (OCT_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "openzeppelin_test_1_5_and_12_15.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - OCT 1-5 And 12-15`; | |
} | |
// check OCT 6-10 exist or not | |
const OCT_6_match = pr.data.body.includes("[x] OCT 6-10"); | |
if (OCT_6_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "openzeppelin_test_6_10.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - OCT 6-10`; | |
} | |
// check OCT 11 exist or not | |
const OCT_11_match = pr.data.body.includes("[x] OCT 11"); | |
if (OCT_11_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "openzeppelin_test_11.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - OCT 11`; | |
} | |
// check OCT 16-19 exist or not | |
const OCT_16_match = pr.data.body.includes("[x] OCT 16-19"); | |
if (OCT_16_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "openzeppelin_test_16_19.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - OCT 16-19`; | |
} | |
// check Unit Tests exist or not | |
const unit_match = pr.data.body.includes("[x] Unit Tests"); | |
if (unit_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "unit_test.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - Unit Tests`; | |
} | |
// check v3 Core Tests exist or not | |
const v3_match = pr.data.body.includes("[x] v3 Core Tests"); | |
if (v3_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "v3_core_test.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - v3 Core Tests`; | |
} | |
// check Unit Tests exist or not | |
const web3_match = pr.data.body.includes("[x] Web3 Compatible Tests"); | |
if (web3_match) { | |
const resp = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: "web3_compatible.yml", | |
ref: "main", | |
inputs: { | |
dispatch: jsonDispatch, | |
} | |
}); | |
core.info(`${JSON.stringify(resp, null, 2)}`); | |
check_list=`${check_list}\n - Web3 Compatible Tests`; | |
}; | |
return check_list | |
- name: Escape check list | |
id: escape_multiple_lines_test_inputs | |
run: | | |
echo ${{ steps.dispatch.outputs.result}} | |
inputs=${{ steps.dispatch.outputs.result}} | |
echo "result=$inputs" >> $GITHUB_OUTPUT | |
- name: Post a coment about component information to PR | |
id: post_workflow_run_comment | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }} | |
script: | | |
console.log(`${{ steps.escape_multiple_lines_test_inputs.outputs.result }}`); | |
const dispatch = { | |
comment_body: `${{ github.event.comment.body }}`, | |
repo: context.repo, | |
issue: context.issue, | |
}; | |
const pr = ( | |
await github.rest.pulls.get({ | |
owner: dispatch.repo.owner, | |
repo: dispatch.repo.repo, | |
pull_number: dispatch.issue.number, | |
}) | |
).data.head; | |
let integrationTestInfo = ` | |
\### CI tests run on commit: | |
- commit id: https://github.com/${{ github.repository }}/commit/${pr.sha}`; | |
integrationTestInfo = `${integrationTestInfo}`; | |
integrationTestInfo = `${integrationTestInfo}\n ${{ steps.escape_multiple_lines_test_inputs.outputs.result }}\n ### Please check ci test results later.`; | |
console.log(integrationTestInfo); | |
const comment = await github.rest.issues.createComment({ | |
issue_number: dispatch.issue.number, | |
owner: dispatch.repo.owner, | |
repo: dispatch.repo.repo, | |
body: integrationTestInfo, | |
}); |