4
4
# schedule:
5
5
# - cron: '0 1 * * 0' # weekly on Sunday night 01:00 UTC
6
6
workflow_dispatch :
7
- # pull_request:
7
+ inputs :
8
+ draft :
9
+ type : boolean
10
+ default : false
11
+ description : " Whether to create a draft PR"
8
12
9
13
permissions : # allow the action to create a PR
10
14
contents : write
@@ -22,19 +26,39 @@ jobs:
22
26
timeout-minutes : 30
23
27
outputs :
24
28
runtime : ${{ steps.runtime.outputs.runtime }}
29
+ branch : ${{ steps.branch.outputs.branch }}
30
+ date : ${{ steps.branch.outputs.date }}
25
31
container :
26
32
image : ${{ needs.preflight.outputs.IMAGE }}
27
33
name : Extract runtimes from matrix
28
34
steps :
29
35
- uses : actions/checkout@v4
30
- - id : runtime
36
+ with :
37
+ ref : master
38
+
39
+ - name : Extract runtimes
40
+ id : runtime
31
41
run : |
32
42
RUNTIMES=$(jq '[.[] | select(.package != null)]' .github/workflows/runtimes-matrix.json)
33
43
34
44
RUNTIMES=$(echo $RUNTIMES | jq -c .)
35
45
echo "runtime=$RUNTIMES"
36
46
echo "runtime=$RUNTIMES" >> $GITHUB_OUTPUT
37
47
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
+
38
62
run-frame-omni-bencher :
39
63
needs : [preflight, runtime-matrix]
40
64
runs-on : ${{ needs.preflight.outputs.RUNNER_WEIGHTS }}
@@ -58,11 +82,12 @@ jobs:
58
82
uses : actions/checkout@v4
59
83
with :
60
84
fetch-depth : 0
61
- ref : master
85
+ ref : ${{ needs.runtime-matrix.outputs.branch }} # checkout always from the initially created branch to avoid conflicts
62
86
63
87
- name : script
64
88
id : required
65
89
run : |
90
+ git --version
66
91
# Fixes "detected dubious ownership" error in the ci
67
92
git config --global --add safe.directory $GITHUB_WORKSPACE
68
93
git remote -v
@@ -94,21 +119,18 @@ jobs:
94
119
95
120
apply-diff-commit :
96
121
runs-on : ubuntu-latest
97
- needs : [run-frame-omni-bencher]
122
+ needs : [runtime-matrix, run-frame-omni-bencher]
98
123
steps :
99
124
- name : Checkout
100
125
uses : actions/checkout@v4
101
126
with :
102
127
fetch-depth : 0
103
- ref : master
128
+ ref : ${{ needs.runtime-matrix.outputs.branch }}
104
129
105
130
- name : Download all artifacts
106
131
uses : actions/download-artifact@v4
107
132
with :
108
- path : patches
109
-
110
- - name : Install subweight
111
- run : cargo install subweight
133
+ path : patches
112
134
113
135
# needs to be able to trigger CI
114
136
- uses : actions/create-github-app-token@v1
@@ -120,28 +142,65 @@ jobs:
120
142
- name : Apply diff and create PR
121
143
env :
122
144
GH_TOKEN : ${{ steps.generate_token.outputs.token }}
145
+ BRANCH : ${{ needs.runtime-matrix.outputs.branch }}
146
+ DATE : ${{ needs.runtime-matrix.outputs.date }}
123
147
run : |
124
- DATE=$(date +'%Y-%m-%d-%s')
125
- BRANCH="update-weights-weekly-$DATE"
126
-
148
+ git --version
127
149
git config user.name "github-actions[bot]"
128
150
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
151
+
152
+ git status
129
153
130
- git switch -c "$BRANCH"
131
-
154
+ # Apply all patches
132
155
for file in patches/diff-*/diff-*.patch; do
133
156
if [ -f "$file" ] && [ -s "$file" ]; then
134
157
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"
136
160
else
137
161
echo "Skipping empty or non-existent patch file: $file"
138
162
fi
139
163
done
164
+
140
165
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
141
198
142
199
git add .
143
200
git commit -m "Update all weights weekly for $DATE"
144
201
git push --set-upstream origin "$BRANCH"
202
+
203
+ MAYBE_DRAFT=${{ inputs.draft && '--draft' || '' }}
145
204
146
205
PR_TITLE="Auto-update of all weights for $DATE"
147
206
gh pr create \
@@ -150,16 +209,6 @@ jobs:
150
209
--base "master" \
151
210
--reviewer paritytech/ci \
152
211
--reviewer paritytech/release-engineering \
153
- --draft \
212
+ $MAYBE_DRAFT \
154
213
--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