Skip to content

Commit 2a6db3b

Browse files
authored
Merge pull request #1454 from galacticcouncil/feat/add-weight-comparison-task
ci: add PR comment reporting weight changes vs master
2 parents 6f8e83f + 3f1a546 commit 2a6db3b

3 files changed

Lines changed: 545 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,54 @@ jobs:
189189
190190
echo "Successfully pushed benchmark results to branch ${{ github.head_ref || github.ref_name }}"
191191
192+
# Weight diff for full bench runs. The standalone weight-diff workflow
193+
# can't trigger off the bot's push (GITHUB_TOKEN does not retrigger
194+
# workflows), so we compute and post the diff here instead. Both writers
195+
# use the same `weight-diff` sticky header, so this overwrites the
196+
# last comment from the standalone workflow.
197+
- name: Materialize master weights for weight-diff
198+
if: steps.prepare.outputs.benchmark_type == 'full'
199+
run: |
200+
git fetch --no-tags --depth=1 origin master:refs/remotes/origin/master
201+
mkdir -p /tmp/weights-master/runtime/hydradx/src/weights
202+
git archive origin/master runtime/hydradx/src/weights 2>/dev/null \
203+
| tar -x -C /tmp/weights-master || true
204+
205+
- name: Generate weight diff report
206+
if: steps.prepare.outputs.benchmark_type == 'full'
207+
id: weight-diff
208+
run: |
209+
set -euo pipefail
210+
python3 scripts/weight-diff/weight_diff.py \
211+
--old /tmp/weights-master/runtime/hydradx/src/weights \
212+
--new runtime/hydradx/src/weights \
213+
> weight-diff-report.md
214+
215+
if grep -q 'No weight changes detected' weight-diff-report.md; then
216+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
217+
else
218+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
219+
fi
220+
221+
echo "----- report preview -----"
222+
head -40 weight-diff-report.md
223+
224+
- name: Post weight-diff comment after full bench
225+
if: steps.prepare.outputs.benchmark_type == 'full' && steps.weight-diff.outputs.has_changes == 'true'
226+
uses: marocchino/sticky-pull-request-comment@v2.1.0
227+
with:
228+
header: weight-diff
229+
path: weight-diff-report.md
230+
number: ${{ steps.prepare.outputs.pr_number }}
231+
232+
- name: Remove stale weight-diff comment after full bench (no changes)
233+
if: steps.prepare.outputs.benchmark_type == 'full' && steps.weight-diff.outputs.has_changes == 'false'
234+
uses: marocchino/sticky-pull-request-comment@v2.1.0
235+
with:
236+
header: weight-diff
237+
delete: true
238+
number: ${{ steps.prepare.outputs.pr_number }}
239+
192240
- name: Comment benchmark results to the pull request
193241
if: github.event_name == 'pull_request'
194242
uses: marocchino/sticky-pull-request-comment@v2.1.0

.github/workflows/weight-diff.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: weight-diff
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
pull-requests: write
8+
contents: read
9+
10+
jobs:
11+
weight-diff:
12+
name: Weight diff
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout PR
16+
uses: actions/checkout@v4
17+
18+
- name: Fetch master
19+
run: git fetch --no-tags --depth=1 origin master:refs/remotes/origin/master
20+
21+
- name: Materialize master weights into a temp dir
22+
run: |
23+
mkdir -p /tmp/weights-master/runtime/hydradx/src/weights
24+
# Extract weights from master. If the path doesn't exist on master
25+
# (e.g. brand-new directory in this PR), proceed with an empty dir.
26+
git archive origin/master runtime/hydradx/src/weights 2>/dev/null \
27+
| tar -x -C /tmp/weights-master || true
28+
29+
- name: Generate weight diff report
30+
id: diff
31+
run: |
32+
set -euo pipefail
33+
python3 scripts/weight-diff/weight_diff.py \
34+
--old /tmp/weights-master/runtime/hydradx/src/weights \
35+
--new runtime/hydradx/src/weights \
36+
> weight-diff-report.md
37+
38+
if grep -q 'No weight changes detected' weight-diff-report.md; then
39+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
echo "----- report preview -----"
45+
head -40 weight-diff-report.md
46+
47+
- name: Post weight diff comment
48+
if: steps.diff.outputs.has_changes == 'true'
49+
uses: marocchino/sticky-pull-request-comment@v2.1.0
50+
with:
51+
header: weight-diff
52+
path: weight-diff-report.md
53+
54+
- name: Remove stale weight-diff comment when no changes
55+
if: steps.diff.outputs.has_changes == 'false'
56+
uses: marocchino/sticky-pull-request-comment@v2.1.0
57+
with:
58+
header: weight-diff
59+
delete: true

0 commit comments

Comments
 (0)