Skip to content

Commit e9e4251

Browse files
authored
Improvements for Weekly bench (#7390)
- added 3 links for subweight comparison - now, ~1 month ago release, ~3 month ago release tag - added `--3way --ours` flags for `git apply` to resolve potential conflict - stick to the weekly branch from the start until the end, to prevent race condition with conflicts
1 parent 0d644ca commit e9e4251

File tree

1 file changed

+76
-27
lines changed

1 file changed

+76
-27
lines changed

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

+76-27
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ on:
44
# schedule:
55
# - cron: '0 1 * * 0' # weekly on Sunday night 01:00 UTC
66
workflow_dispatch:
7-
# pull_request:
7+
inputs:
8+
draft:
9+
type: boolean
10+
default: false
11+
description: "Whether to create a draft PR"
812

913
permissions: # allow the action to create a PR
1014
contents: write
@@ -22,19 +26,39 @@ jobs:
2226
timeout-minutes: 30
2327
outputs:
2428
runtime: ${{ steps.runtime.outputs.runtime }}
29+
branch: ${{ steps.branch.outputs.branch }}
30+
date: ${{ steps.branch.outputs.date }}
2531
container:
2632
image: ${{ needs.preflight.outputs.IMAGE }}
2733
name: Extract runtimes from matrix
2834
steps:
2935
- uses: actions/checkout@v4
30-
- id: runtime
36+
with:
37+
ref: master
38+
39+
- name: Extract runtimes
40+
id: runtime
3141
run: |
3242
RUNTIMES=$(jq '[.[] | select(.package != null)]' .github/workflows/runtimes-matrix.json)
3343
3444
RUNTIMES=$(echo $RUNTIMES | jq -c .)
3545
echo "runtime=$RUNTIMES"
3646
echo "runtime=$RUNTIMES" >> $GITHUB_OUTPUT
3747
48+
- name: Create branch
49+
id: branch
50+
run: |
51+
DATE=$(date +'%Y-%m-%d-%s')
52+
BRANCH="update-weights-weekly-$DATE"
53+
# Fixes "detected dubious ownership" error in the ci
54+
git config --global --add safe.directory $GITHUB_WORKSPACE
55+
56+
git checkout -b $BRANCH
57+
git push --set-upstream origin $BRANCH
58+
59+
echo "date=$DATE" >> $GITHUB_OUTPUT
60+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
61+
3862
run-frame-omni-bencher:
3963
needs: [preflight, runtime-matrix]
4064
runs-on: ${{ needs.preflight.outputs.RUNNER_WEIGHTS }}
@@ -58,11 +82,12 @@ jobs:
5882
uses: actions/checkout@v4
5983
with:
6084
fetch-depth: 0
61-
ref: master
85+
ref: ${{ needs.runtime-matrix.outputs.branch }} # checkout always from the initially created branch to avoid conflicts
6286

6387
- name: script
6488
id: required
6589
run: |
90+
git --version
6691
# Fixes "detected dubious ownership" error in the ci
6792
git config --global --add safe.directory $GITHUB_WORKSPACE
6893
git remote -v
@@ -94,21 +119,18 @@ jobs:
94119

95120
apply-diff-commit:
96121
runs-on: ubuntu-latest
97-
needs: [run-frame-omni-bencher]
122+
needs: [runtime-matrix, run-frame-omni-bencher]
98123
steps:
99124
- name: Checkout
100125
uses: actions/checkout@v4
101126
with:
102127
fetch-depth: 0
103-
ref: master
128+
ref: ${{ needs.runtime-matrix.outputs.branch }}
104129

105130
- name: Download all artifacts
106131
uses: actions/download-artifact@v4
107132
with:
108-
path: patches
109-
110-
- name: Install subweight
111-
run: cargo install subweight
133+
path: patches
112134

113135
# needs to be able to trigger CI
114136
- uses: actions/create-github-app-token@v1
@@ -120,28 +142,65 @@ jobs:
120142
- name: Apply diff and create PR
121143
env:
122144
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
145+
BRANCH: ${{ needs.runtime-matrix.outputs.branch }}
146+
DATE: ${{ needs.runtime-matrix.outputs.date }}
123147
run: |
124-
DATE=$(date +'%Y-%m-%d-%s')
125-
BRANCH="update-weights-weekly-$DATE"
126-
148+
git --version
127149
git config user.name "github-actions[bot]"
128150
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
151+
152+
git status
129153
130-
git switch -c "$BRANCH"
131-
154+
# Apply all patches
132155
for file in patches/diff-*/diff-*.patch; do
133156
if [ -f "$file" ] && [ -s "$file" ]; then
134157
echo "Applying $file"
135-
git apply "$file" --unidiff-zero --allow-empty || echo "Failed to apply $file"
158+
# using --3way and --ours for conflicts resolution. Requires git 2.47+
159+
git apply "$file" --unidiff-zero --allow-empty --3way --ours || echo "Failed to apply $file"
136160
else
137161
echo "Skipping empty or non-existent patch file: $file"
138162
fi
139163
done
164+
140165
rm -rf patches
166+
167+
# Get release tags from 1 and 3 months ago
168+
ONE_MONTH_AGO=$(date -d "1 month ago" +%Y-%m-%d)
169+
THREE_MONTHS_AGO=$(date -d "3 months ago" +%Y-%m-%d)
170+
171+
# Get tags with their dates
172+
ONE_MONTH_INFO=$(git for-each-ref --sort=-creatordate --format '%(refname:short)|%(creatordate:iso-strict-local)' 'refs/tags/polkadot-v*' | awk -v date="$ONE_MONTH_AGO" -F'|' '$2 <= date {print $0; exit}')
173+
THREE_MONTHS_INFO=$(git for-each-ref --sort=-creatordate --format '%(refname:short)|%(creatordate:iso-strict-local)' 'refs/tags/polkadot-v*' | awk -v date="$THREE_MONTHS_AGO" -F'|' '$2 <= date {print $0; exit}')
174+
175+
# Split into tag and date
176+
ONE_MONTH_TAG=$(echo "$ONE_MONTH_INFO" | cut -d'|' -f1)
177+
ONE_MONTH_DATE=$(echo "$ONE_MONTH_INFO" | cut -d'|' -f2 | cut -d'T' -f1)
178+
THREE_MONTHS_TAG=$(echo "$THREE_MONTHS_INFO" | cut -d'|' -f1)
179+
THREE_MONTHS_DATE=$(echo "$THREE_MONTHS_INFO" | cut -d'|' -f2 | cut -d'T' -f1)
180+
181+
# Base URL for Subweight comparisons
182+
BASE_URL="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"
183+
184+
# Generate comparison links
185+
MASTER_LINK="${BASE_URL}&old=master&new=${BRANCH}"
186+
ONE_MONTH_LINK="${BASE_URL}&old=${ONE_MONTH_TAG}&new=${BRANCH}"
187+
THREE_MONTHS_LINK="${BASE_URL}&old=${THREE_MONTHS_TAG}&new=${BRANCH}"
188+
189+
# Create PR body with all links in a temporary file
190+
cat > /tmp/pr_body.md << EOF
191+
Auto-update of all weights for ${DATE}.
192+
193+
Subweight results:
194+
- [now vs master](${MASTER_LINK})
195+
- [now vs ${ONE_MONTH_TAG} (${ONE_MONTH_DATE})](${ONE_MONTH_LINK})
196+
- [now vs ${THREE_MONTHS_TAG} (${THREE_MONTHS_DATE})](${THREE_MONTHS_LINK})
197+
EOF
141198
142199
git add .
143200
git commit -m "Update all weights weekly for $DATE"
144201
git push --set-upstream origin "$BRANCH"
202+
203+
MAYBE_DRAFT=${{ inputs.draft && '--draft' || '' }}
145204
146205
PR_TITLE="Auto-update of all weights for $DATE"
147206
gh pr create \
@@ -150,16 +209,6 @@ jobs:
150209
--base "master" \
151210
--reviewer paritytech/ci \
152211
--reviewer paritytech/release-engineering \
153-
--draft \
212+
$MAYBE_DRAFT \
154213
--label "R0-silent" \
155-
--body "$PR_TITLE"
156-
157-
subweight compare commits \
158-
--path-pattern "./**/weights/**/*.rs,./**/weights.rs" \
159-
--method asymptotic \
160-
--format markdown \
161-
--no-color \
162-
--change added changed \
163-
--ignore-errors \
164-
--threshold 2 \
165-
origin/master $BRANCH
214+
--body "$(cat /tmp/pr_body.md)"

0 commit comments

Comments
 (0)