Skip to content

Commit

Permalink
Merge pull request #1070 from interlay/gha-weights-automation
Browse files Browse the repository at this point in the history
chore: add weights automation
  • Loading branch information
gregdhill committed Jun 21, 2023
2 parents 550bf48 + d1d1f05 commit 7f57d1d
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/benchmark.yml
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>
`
})
42 changes: 42 additions & 0 deletions scripts/benchmark.sh
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

0 comments on commit 7f57d1d

Please sign in to comment.