Improvements for Weekly bench #27
Workflow file for this run
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: Bench all runtimes | |
on: | |
# schedule: | |
# - cron: '0 1 * * 0' # weekly on Sunday night 01:00 UTC | |
workflow_dispatch: | |
#TODO: Remove this | |
pull_request: | |
permissions: # allow the action to create a PR | |
contents: write | |
issues: write | |
pull-requests: write | |
actions: read | |
jobs: | |
preflight: | |
uses: ./.github/workflows/reusable-preflight.yml | |
runtime-matrix: | |
runs-on: ubuntu-latest | |
needs: [preflight] | |
timeout-minutes: 30 | |
outputs: | |
runtime: ${{ steps.runtime.outputs.runtime }} | |
branch: ${{ steps.branch.outputs.branch }} | |
container: | |
image: ${{ needs.preflight.outputs.IMAGE }} | |
name: Extract runtimes from matrix | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: master | |
- name: Extract runtimes | |
id: runtime | |
run: | | |
# TODO: Remove [3:4] | |
RUNTIMES=$(jq '[.[] | select(.package != null)] | .[3:4]' .github/workflows/runtimes-matrix.json) | |
RUNTIMES=$(echo $RUNTIMES | jq -c .) | |
echo "runtime=$RUNTIMES" | |
echo "runtime=$RUNTIMES" >> $GITHUB_OUTPUT | |
- name: Create branch | |
id: branch | |
run: | | |
DATE=$(date +'%Y-%m-%d-%s') | |
BRANCH="update-weights-weekly-$DATE" | |
# Fixes "detected dubious ownership" error in the ci | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git checkout -b $BRANCH | |
git push --set-upstream origin $BRANCH | |
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
run-frame-omni-bencher: | |
needs: [preflight, runtime-matrix] | |
runs-on: ${{ needs.preflight.outputs.RUNNER_WEIGHTS }} | |
# 24 hours per runtime. | |
# Max it takes 14hr for westend to recalculate, but due to limited runners, | |
# sometimes it can take longer. | |
timeout-minutes: 1440 | |
strategy: | |
fail-fast: false # keep running other workflows even if one fails, to see the logs of all possible failures | |
matrix: | |
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }} | |
container: | |
image: ${{ needs.preflight.outputs.IMAGE }} | |
env: | |
PACKAGE_NAME: ${{ matrix.runtime.package }} | |
FLAGS: ${{ matrix.runtime.bench_flags }} | |
RUST_LOG: "frame_omni_bencher=info,polkadot_sdk_frame=info" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ needs.runtime-matrix.outputs.branch }} # checkout always from the initially created branch to avoid conflicts | |
- name: script | |
id: required | |
run: | | |
git --version | |
# Fixes "detected dubious ownership" error in the ci | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git remote -v | |
python3 -m pip install -r .github/scripts/generate-prdoc.requirements.txt | |
# TODO: REMOVE pallet | |
python3 .github/scripts/cmd/cmd.py bench --runtime ${{ matrix.runtime.name }} --pallet pallet_balances | |
git add . | |
git status | |
if [ -f /tmp/cmd/command_output.log ]; then | |
CMD_OUTPUT=$(cat /tmp/cmd/command_output.log) | |
# export to summary to display in the PR | |
echo "$CMD_OUTPUT" >> $GITHUB_STEP_SUMMARY | |
# should be multiline, otherwise it captures the first line only | |
echo 'cmd_output<<EOF' >> $GITHUB_OUTPUT | |
echo "$CMD_OUTPUT" >> $GITHUB_OUTPUT | |
echo 'EOF' >> $GITHUB_OUTPUT | |
fi | |
# Create patch that includes both modifications and new files | |
git add -A | |
git diff --staged > diff-${{ matrix.runtime.name }}.patch -U0 | |
git reset | |
- name: Upload diff | |
uses: actions/upload-artifact@v4 | |
with: | |
name: diff-${{ matrix.runtime.name }} | |
path: diff-${{ matrix.runtime.name }}.patch | |
apply-diff-commit: | |
runs-on: ubuntu-latest | |
needs: [runtime-matrix, run-frame-omni-bencher] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ needs.runtime-matrix.outputs.branch }} | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: patches | |
# needs to be able to trigger CI | |
- uses: actions/create-github-app-token@v1 | |
id: generate_token | |
with: | |
app-id: ${{ secrets.CMD_BOT_APP_ID }} | |
private-key: ${{ secrets.CMD_BOT_APP_KEY }} | |
- name: Apply diff and create PR | |
env: | |
GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
BRANCH: ${{ needs.runtime-matrix.outputs.branch }} | |
run: | | |
git --version | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git status | |
for file in patches/diff-*/diff-*.patch; do | |
if [ -f "$file" ] && [ -s "$file" ]; then | |
echo "Applying $file" | |
# --ours for conflicts requires git 2.47+ | |
git apply "$file" --unidiff-zero --allow-empty --3way --ours || echo "Failed to apply $file" | |
else | |
echo "Skipping empty or non-existent patch file: $file" | |
fi | |
done | |
rm -rf patches | |
LINK="https://weights.tasty.limo/compare?repo=polkadot-sdk&threshold=5&path_pattern=.%2F**%2Fweights%2F**%2F*.rs%2C.%2F**%2Fweights.rs&method=asymptotic&ignore_errors=true&unit=time&old=master&new=$BRANCH" | |
echo "[Subweight result]($LINK)" >> $GITHUB_STEP_SUMMARY | |
git add . | |
git commit -m "Update all weights weekly for $DATE" | |
git push --set-upstream origin "$BRANCH" | |
PR_TITLE="Auto-update of all weights for $DATE" | |
gh pr create \ | |
--title "$PR_TITLE" \ | |
--head "$BRANCH" \ | |
--base "master" \ | |
--reviewer paritytech/ci \ | |
--reviewer paritytech/release-engineering \ | |
--draft \ | |
--label "R0-silent" \ | |
--body "$PR_TITLE. [Subweight result]($LINK)" |