-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1070 from interlay/gha-weights-automation
chore: add weights automation
- Loading branch information
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Original source: https://github.com/AcalaNetwork/Acala/blob/master/.github/workflows/benchmark.yml | ||
|
||
name: Benchmark | ||
on: | ||
issue_comment: | ||
types: [created] | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
jobs: | ||
benchmark: | ||
name: Benchmark | ||
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/run_benchmarks') }} | ||
runs-on: [self-hosted, linux] | ||
steps: | ||
- uses: actions/github-script@v6 | ||
name: Get PR branch | ||
id: issue | ||
with: | ||
script: | | ||
const pr = context.payload.issue.number | ||
const data = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: pr | ||
}) | ||
return { | ||
ref: data.data.head.ref, | ||
sha: data.data.head.sha, | ||
} | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
ref: ${{ fromJson(steps.issue.outputs.result).sha }} | ||
- uses: actions/github-script@v6 | ||
name: Prepare command | ||
id: command | ||
with: | ||
result-encoding: string | ||
script: | | ||
const [, , cmd, ...args] = context.payload.comment.body.split(/\W+/) | ||
const [runtime, pallet] = args | ||
return `bash ./scripts/benchmark.sh -r ${runtime ?? "*"} -p ${pallet ?? "*"}` | ||
- uses: actions/github-script@v6 | ||
name: Post comment | ||
id: comment | ||
with: | ||
script: | | ||
const data = await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: ` | ||
**Request**: \`${context.payload.comment.body}\` | ||
**Command**: \`${{steps.command.outputs.result}}\` | ||
Running... | ||
` | ||
}) | ||
return data.data.id | ||
- name: Set variables | ||
run: | | ||
echo "TOOLCHAIN=$(rustup show active-toolchain | cut -d " " -f1)" >> $GITHUB_ENV | ||
- name: Install toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ env.TOOLCHAIN }} | ||
components: rustfmt | ||
target: wasm32-unknown-unknown | ||
- name: Run benchmarks | ||
run: ${{steps.command.outputs.result}} > ${{runner.temp}}/out.txt | ||
- name: Commit new weights | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: Automated weights | ||
|
||
- uses: actions/github-script@v6 | ||
name: Update comment | ||
with: | ||
script: | | ||
const fs = require('fs') | ||
const id = `${{steps.comment.outputs.result}}` | ||
const body = fs.readFileSync('${{runner.temp}}/out.txt').toString() | ||
github.rest.issues.updateComment({ | ||
comment_id: id, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: ` | ||
**Request**: \`${context.payload.comment.body}\` | ||
**Command**: \`${{steps.command.outputs.result}}\` | ||
<details> | ||
<summary>Results</summary> | ||
\`\`\` | ||
${body.trim()} | ||
\`\`\` | ||
</details> | ||
` | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
#set -euxo pipefail | ||
|
||
while getopts ":r:p:" opt; do | ||
case $opt in | ||
r) | ||
runtime="$OPTARG" | ||
;; | ||
p) | ||
pallet="$OPTARG" | ||
;; | ||
\?) echo "Invalid option -$OPTARG" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
case $OPTARG in | ||
-*) echo "Option $opt needs a valid argument" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "${pallet}" ]; then | ||
pallet="*" | ||
fi | ||
|
||
cargo run \ | ||
--bin interbtc-parachain \ | ||
--features runtime-benchmarks \ | ||
--release \ | ||
-- \ | ||
benchmark pallet \ | ||
--pallet "${pallet}" \ | ||
--extrinsic '*' \ | ||
--chain "${runtime}" \ | ||
--execution=wasm \ | ||
--wasm-execution=compiled \ | ||
--steps 50 \ | ||
--repeat 10 \ | ||
--output "parachain/runtime/${runtime}/src/weights/" \ | ||
--template .deploy/runtime-weight-template.hbs |