Skip to content

Commit 3115a27

Browse files
committed
go
add subweight remove cmd bot app threshold 2 draft update template and re-run show subweight in logs, and switch to workflow dispatch
1 parent 2d4ea30 commit 3115a27

File tree

2 files changed

+67
-21
lines changed

2 files changed

+67
-21
lines changed

.github/workflows/bench-all-runtimes.yml

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
name: Bench all runtimes (frame-omni-bencher)
1+
name: Bench all runtimes
22

33
on:
44
# schedule:
55
# - cron: '0 1 * * 0' # weekly on Sunday night 01:00 UTC
6-
workflow_dispatch:
6+
# workflow_dispatch:
7+
pull_request:
78

89
permissions: # allow the action to create a PR
910
contents: write
@@ -28,7 +29,6 @@ jobs:
2829
- uses: actions/checkout@v4
2930
- id: runtime
3031
run: |
31-
# only first two runtimes
3232
RUNTIMES=$(jq '[.[] | select(.package != null)]' .github/workflows/runtimes-matrix.json)
3333
3434
RUNTIMES=$(echo $RUNTIMES | jq -c .)
@@ -38,7 +38,10 @@ jobs:
3838
run-frame-omni-bencher:
3939
runs-on: ${{ needs.preflight.outputs.RUNNER_WEIGHTS }}
4040
needs: [preflight, runtime-matrix]
41-
timeout-minutes: 1440 # 24 hours per runtime
41+
# 24 hours per runtime.
42+
# Max it takes 14hr for westend to recalculate, but due to limited runners,
43+
# sometimes it can take longer.
44+
timeout-minutes: 1440
4245
strategy:
4346
fail-fast: false # keep running other workflows even if one fails, to see the logs of all possible failures
4447
matrix:
@@ -77,7 +80,11 @@ jobs:
7780
echo "$CMD_OUTPUT" >> $GITHUB_OUTPUT
7881
echo 'EOF' >> $GITHUB_OUTPUT
7982
fi
80-
git diff HEAD > diff-${{ matrix.runtime.name }}.patch
83+
84+
# Create patch that includes both modifications and new files
85+
git add -A
86+
git diff --staged > diff-${{ matrix.runtime.name }}.patch
87+
git reset
8188
8289
- name: Upload diff
8390
uses: actions/upload-artifact@v4
@@ -100,34 +107,74 @@ jobs:
100107
with:
101108
path: patches
102109

110+
- name: Install subweight
111+
run: cargo install subweight
112+
113+
# needs to be able to trigger CI
103114
- uses: actions/create-github-app-token@v1
104115
id: generate_token
105116
with:
106117
app-id: ${{ secrets.CMD_BOT_APP_ID }}
107118
private-key: ${{ secrets.CMD_BOT_APP_KEY }}
108119

109-
- name: Apply diff from artifacts folder
120+
- name: Apply diff and create PR
110121
env:
111122
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
112123
run: |
113-
# scan all patch files in the patches directory
124+
DATE=$(date +'%Y-%m-%d-%s')
125+
BRANCH="update-weights-weekly-$DATE"
126+
127+
git config user.name "github-actions[bot]"
128+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
129+
130+
git switch -c "$BRANCH"
131+
114132
for file in patches/diff-*/diff-*.patch; do
115-
if [ -f "$file" ]; then
133+
if [ -f "$file" ] && [ -s "$file" ]; then
116134
echo "Applying $file"
117-
git apply "$file"
135+
git apply "$file" || echo "Failed to apply $file"
136+
else
137+
echo "Skipping empty or non-existent patch file: $file"
118138
fi
119139
done
120-
DATE=$(date +'%Y-%m-%d-%s')
121-
BRANCH="update-weights-weekly-$DATE"
122140
rm -rf patches
123-
124-
git config user.name "github-actions[bot]"
125-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
126-
127-
git checkout -b "$BRANCH"
128-
git status
141+
129142
git add .
130143
git commit -m "Update all weights weekly for $DATE"
131144
git push --set-upstream origin "$BRANCH"
132-
git status
133-
gh pr create --title "Update weights weekly for $DATE" --body "Update weights weekly for $DATE"
145+
146+
PR_TITLE="Auto-update of all weights for $DATE"
147+
gh pr create \
148+
--title "$PR_TITLE" \
149+
--head "$BRANCH" \
150+
--base "master" \
151+
--reviewer paritytech/ci \
152+
--reviewer paritytech/release-engineering \
153+
--draft \
154+
--label "R0-silent" \
155+
--body "$PR_TITLE"
156+
157+
# git fetch
158+
159+
# Properly escape the markdown content and format the PR body
160+
# SUBWEIGHT_OUTPUT=$(cat << EOF
161+
# Auto-update weights for $DATE
162+
163+
# <details>
164+
# <summary>Subweight Output</summary>
165+
166+
# $SUBWEIGHT_OUTPUT_RAW
167+
168+
# </details>
169+
# EOF
170+
# )
171+
172+
subweight compare commits \
173+
--path-pattern "./**/weights/**/*.rs,./**/weights.rs" \
174+
--method asymptotic \
175+
--format markdown \
176+
--no-color \
177+
--change added changed \
178+
--ignore-errors \
179+
--threshold 2 \
180+
origin/master refs/heads/$BRANCH)

substrate/.maintain/frame-weight-template.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#![allow(unused_imports)]
1818
#![allow(missing_docs)]
1919

20-
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
21-
use core::marker::PhantomData;
20+
use frame::weights_prelude::*;
2221

2322
/// Weight functions needed for `{{pallet}}`.
2423
pub trait WeightInfo {

0 commit comments

Comments
 (0)