duel 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENT_PROMPT.md +51 -27
- data/CHANGELOG.md +247 -1
- data/README.md +30 -14
- data/docs/benchmarks.md +28 -24
- data/docs/ci.md +328 -362
- data/docs/configuration.md +40 -37
- data/docs/how-it-works.md +23 -10
- data/docs/json.md +21 -25
- data/docs/plugins.md +40 -22
- data/docs/troubleshooting.md +3 -2
- data/lib/duel/across.rb +18 -18
- data/lib/duel/badge.rb +174 -0
- data/lib/duel/baseline.rb +38 -15
- data/lib/duel/cli.rb +175 -107
- data/lib/duel/comment.rb +80 -71
- data/lib/duel/config.rb +145 -63
- data/lib/duel/context.rb +29 -24
- data/lib/duel/forge.rb +87 -0
- data/lib/duel/init.rb +44 -87
- data/lib/duel/json_report.rb +34 -25
- data/lib/duel/lane.rb +107 -61
- data/lib/duel/lock.rb +1 -1
- data/lib/duel/mark_passed.rb +132 -0
- data/lib/duel/metric.rb +28 -27
- data/lib/duel/native.rb +7 -5
- data/lib/duel/platform.rb +4 -0
- data/lib/duel/process_sample.rb +9 -6
- data/lib/duel/rake_task.rb +4 -5
- data/lib/duel/resource.rb +10 -11
- data/lib/duel/result.rb +22 -14
- data/lib/duel/rubies.rb +6 -2
- data/lib/duel/runner.rb +27 -15
- data/lib/duel/spawn.rb +29 -4
- data/lib/duel/stats.rb +14 -12
- data/lib/duel/summary.rb +31 -29
- data/lib/duel/templates/benchmark_duel.rb.erb +2 -2
- data/lib/duel/templates/duel.gitlab-ci.yml.erb +18 -54
- data/lib/duel/templates/duel.rb.erb +7 -7
- data/lib/duel/templates/perf-caller.yml.erb +22 -5
- data/lib/duel/templates/perf-comment.yml.erb +11 -11
- data/lib/duel/templates/perf-push-jobs.yml.erb +127 -0
- data/lib/duel/templates/perf-push.yml.erb +50 -0
- data/lib/duel/templates/perf.yml.erb +113 -335
- data/lib/duel/testing.rb +20 -25
- data/lib/duel/version.rb +1 -1
- data/lib/duel/worker.rb +16 -9
- data/lib/duel/worker_process.rb +6 -6
- data/lib/duel.rb +88 -33
- data/sig/duel/across.rbs +4 -0
- data/sig/duel/badge.rbs +51 -0
- data/sig/duel/baseline.rbs +7 -2
- data/sig/duel/cli.rbs +31 -20
- data/sig/duel/comment.rbs +14 -15
- data/sig/duel/config.rbs +71 -29
- data/sig/duel/context.rbs +4 -4
- data/sig/duel/forge.rbs +42 -0
- data/sig/duel/init.rbs +8 -26
- data/sig/duel/json_report.rbs +7 -6
- data/sig/duel/lane.rbs +29 -6
- data/sig/duel/mark_passed.rbs +39 -0
- data/sig/duel/metric.rbs +10 -10
- data/sig/duel/native.rbs +3 -0
- data/sig/duel/platform.rbs +1 -0
- data/sig/duel/process_sample.rbs +3 -0
- data/sig/duel/resource.rbs +3 -3
- data/sig/duel/result.rbs +12 -5
- data/sig/duel/rubies.rbs +3 -0
- data/sig/duel/runner.rbs +23 -16
- data/sig/duel/spawn.rbs +7 -0
- data/sig/duel/stats.rbs +4 -1
- data/sig/duel/summary.rbs +8 -0
- data/sig/duel/testing.rbs +2 -2
- data/sig/duel/worker.rbs +6 -5
- data/sig/duel/worker_process.rbs +3 -3
- data/sig/duel.rbs +50 -31
- metadata +9 -1
data/docs/ci.md
CHANGED
|
@@ -12,9 +12,13 @@ example, a series of changes that are each 1.5% slower would each pass.
|
|
|
12
12
|
To catch that kind of slow creep, also compare against your last release
|
|
13
13
|
on a schedule. The slowdowns add up there until they're a regression.
|
|
14
14
|
|
|
15
|
-
The following GitHub Actions workflow does both. `duel init` writes
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
The following GitHub Actions workflow does both. `duel init` writes a
|
|
16
|
+
short workflow that calls Duel's, which is this one with each setting
|
|
17
|
+
as an input (see
|
|
18
|
+
[Call Duel's reusable workflows](#call-duels-reusable-workflows)).
|
|
19
|
+
`duel init --standalone` writes the whole of it, as
|
|
20
|
+
`.github/workflows/perf.yml`, to change as you like, with a second
|
|
21
|
+
workflow that comments on a pull request when a benchmark fails (see
|
|
18
22
|
[Comment on a pull request](#comment-on-a-pull-request)):
|
|
19
23
|
|
|
20
24
|
```yaml
|
|
@@ -50,44 +54,32 @@ jobs:
|
|
|
50
54
|
name: Duel
|
|
51
55
|
runs-on: ubuntu-latest
|
|
52
56
|
# Whether to comment (post, change or none), the run's status (passed,
|
|
53
|
-
# failed or neutral), and
|
|
57
|
+
# failed or neutral), and the branch to mark a push passed on (or
|
|
54
58
|
# nothing), from Duel.
|
|
55
59
|
outputs:
|
|
56
60
|
comment: ${{ steps.compare.outputs.comment }}
|
|
57
61
|
status: ${{ steps.compare.outputs.status }}
|
|
58
62
|
passed: ${{ steps.compare.outputs.passed }}
|
|
59
63
|
steps:
|
|
60
|
-
- uses: actions/checkout@v7
|
|
64
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
61
65
|
with:
|
|
62
66
|
fetch-depth: 0 # the baseline comes from history, tags included
|
|
63
67
|
persist-credentials: false
|
|
64
68
|
# The labels of the pull request (or for a push, of the one that
|
|
65
69
|
# merged it), for c.accept_label in .duel.rb, as a JSON array. They're
|
|
66
70
|
# read as the job runs, and adding the label (or taking it off) runs
|
|
67
|
-
# the job again: see the Perf comment workflow.
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
# what that slowed down was accepted, so it's compared with instead.
|
|
71
|
+
# the job again: see the Perf comment workflow. (On a schedule, Duel
|
|
72
|
+
# finds the last change merged with the label since the last
|
|
73
|
+
# release itself.)
|
|
71
74
|
- name: Find the pull request's labels
|
|
72
75
|
id: labels
|
|
73
|
-
if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push'
|
|
76
|
+
if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push'
|
|
74
77
|
continue-on-error: true # (without them, nothing's accepted)
|
|
75
78
|
env:
|
|
76
79
|
GH_TOKEN: ${{ github.token }}
|
|
77
80
|
PR: ${{ github.event.pull_request.number }}
|
|
78
81
|
QUEUED: ${{ github.event.merge_group.head_ref }}
|
|
79
|
-
ACCEPT_LABEL: 'duel: accept'
|
|
80
|
-
RELEASE_TAGS: "v*"
|
|
81
82
|
run: |
|
|
82
|
-
if [ "$GITHUB_EVENT_NAME" = schedule ]; then
|
|
83
|
-
tag=$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null) || exit 0
|
|
84
|
-
since=$(TZ=UTC git log -1 --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd "$tag")
|
|
85
|
-
merged=$(gh pr list --repo "$GITHUB_REPOSITORY" --state merged --label "$ACCEPT_LABEL" --search "merged:>=$since" --limit 1000 \
|
|
86
|
-
--json mergeCommit --jq '.[].mergeCommit.oid')
|
|
87
|
-
accepted=$(git rev-list "$tag..HEAD" | grep -Fx -m 1 -f <(echo "$merged")) || accepted=
|
|
88
|
-
echo "accepted=$accepted" >> "$GITHUB_OUTPUT"
|
|
89
|
-
exit 0
|
|
90
|
-
fi
|
|
91
83
|
# (In a merge queue, the last pull request queued, which the queue's
|
|
92
84
|
# branch names: gh-readonly-queue/main/pr-123-<sha>.)
|
|
93
85
|
if [ -n "$QUEUED" ]; then
|
|
@@ -101,26 +93,29 @@ jobs:
|
|
|
101
93
|
fi
|
|
102
94
|
echo "labels=$labels" >> "$GITHUB_OUTPUT"
|
|
103
95
|
# (And whatever else your tests need set up: packages, services.)
|
|
104
|
-
- uses: ruby/setup-ruby@v1
|
|
96
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
97
|
+
id: ruby
|
|
105
98
|
with:
|
|
106
99
|
ruby-version: "3.4" # (or none, with a .ruby-version)
|
|
107
100
|
bundler-cache: true
|
|
108
101
|
# Against the branch it targets for a pull request, the queue's base
|
|
109
102
|
# for a merge queue, what was there before for a push (or as
|
|
110
103
|
# c.push_base in .duel.rb says, the last commit Duel passed), and the
|
|
111
|
-
# last release on a schedule (slow creep)
|
|
104
|
+
# last release on a schedule (slow creep), as Duel finds them, from
|
|
105
|
+
# the run's event. Duel adds its report to
|
|
112
106
|
# the job's summary, writes it to duel.md for the comment, and sets
|
|
113
107
|
# the step's outputs to say whether to comment, as c.comment in
|
|
114
108
|
# .duel.rb says, whatever the outcome.
|
|
115
109
|
- name: Compare
|
|
116
110
|
id: compare
|
|
117
111
|
env:
|
|
118
|
-
DUEL_BASE: ${{ github.event_name == 'schedule' && 'last-release' || github.event_name == 'push' && github.event.before || github.event_name == 'merge_group' && github.event.merge_group.base_sha || '' }}
|
|
119
112
|
# (Run by hand, it compares anyway: with nothing changed, the code
|
|
120
113
|
# with itself, which checks the setup.)
|
|
121
114
|
DUEL_FORCE: ${{ github.event_name == 'workflow_dispatch' && '1' || '' }}
|
|
122
115
|
DUEL_LABELS: ${{ steps.labels.outputs.labels }}
|
|
123
|
-
|
|
116
|
+
# (On a schedule, for the last change a label accepted since the
|
|
117
|
+
# last release, which Duel finds with gh.)
|
|
118
|
+
GH_TOKEN: ${{ github.event_name == 'schedule' && github.token || '' }}
|
|
124
119
|
run: bundle exec duel --markdown "$RUNNER_TEMP/duel/duel.md"
|
|
125
120
|
# For a pull request, what Duel said, for the Perf comment workflow,
|
|
126
121
|
# which can't see this job's outputs.
|
|
@@ -136,12 +131,83 @@ jobs:
|
|
|
136
131
|
# The report, for the comments.
|
|
137
132
|
- name: Keep the report
|
|
138
133
|
if: ${{ !cancelled() && (github.event_name == 'pull_request' || github.event_name == 'push') }}
|
|
139
|
-
uses: actions/upload-artifact@v7
|
|
134
|
+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
140
135
|
with:
|
|
141
136
|
name: duel-report
|
|
142
137
|
path: ${{ runner.temp }}/duel/
|
|
143
138
|
if-no-files-found: ignore # none when Duel didn't get to compare
|
|
144
139
|
retention-days: 1
|
|
140
|
+
|
|
141
|
+
# The report, as a new comment on a pushed commit, which notifies its
|
|
142
|
+
# author, when Duel says to, as for a pull request (see the Perf comment
|
|
143
|
+
# workflow). It does only where a regression in a push passes, with
|
|
144
|
+
# c.fail_on = :pull_requests in .duel.rb, so the comment says what the
|
|
145
|
+
# check doesn't. Its last comment is the last one on any commit. This
|
|
146
|
+
# job checks nothing out and runs none of the code.
|
|
147
|
+
commit-comment:
|
|
148
|
+
name: Comment on the commit
|
|
149
|
+
needs: duel
|
|
150
|
+
if: ${{ !cancelled() && github.event_name == 'push' && (needs.duel.outputs.comment == 'post' || needs.duel.outputs.comment == 'change') }}
|
|
151
|
+
runs-on: ubuntu-latest
|
|
152
|
+
permissions:
|
|
153
|
+
contents: write # to comment on the commit with the report
|
|
154
|
+
steps:
|
|
155
|
+
- name: Get the report
|
|
156
|
+
id: report
|
|
157
|
+
continue-on-error: true # there's none when the Duel job failed before comparing
|
|
158
|
+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
159
|
+
with:
|
|
160
|
+
name: duel-report
|
|
161
|
+
path: ${{ runner.temp }}/report
|
|
162
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
163
|
+
if: steps.report.outcome == 'success'
|
|
164
|
+
with:
|
|
165
|
+
ruby-version: ruby
|
|
166
|
+
# Duel's own code, from RubyGems (none of the push's).
|
|
167
|
+
- name: Comment on the commit
|
|
168
|
+
if: steps.report.outcome == 'success'
|
|
169
|
+
env:
|
|
170
|
+
GH_TOKEN: ${{ github.token }}
|
|
171
|
+
DUEL_COMMENT: ${{ needs.duel.outputs.comment }}
|
|
172
|
+
DUEL_STATUS: ${{ needs.duel.outputs.status }}
|
|
173
|
+
run: |
|
|
174
|
+
gem install duel --version '0.3.0' --no-document
|
|
175
|
+
duel comment --report "$RUNNER_TEMP/report" --commit "$GITHUB_SHA" --marker 'duel'
|
|
176
|
+
|
|
177
|
+
# With c.push_base = :last_passed in .duel.rb, a push is compared with
|
|
178
|
+
# the last commit Duel passed, which a branch marks (each branch pushed
|
|
179
|
+
# has its own), so slowdowns too small for any one push to fail add up
|
|
180
|
+
# until they fail one. This job moves the branch (as Duel names it) to
|
|
181
|
+
# a push that passed (or makes it), but never back: where a newer
|
|
182
|
+
# push's run moved it first, it stays. It checks nothing out and runs
|
|
183
|
+
# none of the code. To accept a regression, move the branch yourself
|
|
184
|
+
# (for main, git push origin main:duel/passed/main).
|
|
185
|
+
passed:
|
|
186
|
+
name: Mark the commit passed
|
|
187
|
+
needs: duel
|
|
188
|
+
# One at a time for each branch, so that two runs can't both find no
|
|
189
|
+
# branch and race to make it (a push's run doesn't wait for the one
|
|
190
|
+
# before it). One that's running is never cancelled, and one that's
|
|
191
|
+
# waiting gives way to a newer push's, which moves it further anyway.
|
|
192
|
+
concurrency:
|
|
193
|
+
group: ${{ github.workflow }}-passed-${{ github.ref_name }}
|
|
194
|
+
cancel-in-progress: false
|
|
195
|
+
if: ${{ !cancelled() && github.event_name == 'push' && needs.duel.outputs.passed != '' }}
|
|
196
|
+
runs-on: ubuntu-latest
|
|
197
|
+
permissions:
|
|
198
|
+
contents: write # to move the branch
|
|
199
|
+
steps:
|
|
200
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
201
|
+
with:
|
|
202
|
+
ruby-version: ruby
|
|
203
|
+
# Duel's own code, from RubyGems (none of the push's).
|
|
204
|
+
- name: Move the branch to the commit
|
|
205
|
+
env:
|
|
206
|
+
GH_TOKEN: ${{ github.token }}
|
|
207
|
+
BRANCH: ${{ needs.duel.outputs.passed }}
|
|
208
|
+
run: |
|
|
209
|
+
gem install duel --version '0.3.0' --no-document
|
|
210
|
+
duel mark-passed "$BRANCH"
|
|
145
211
|
```
|
|
146
212
|
|
|
147
213
|
A newer push to a pull request cancels the pull request's run, if it's
|
|
@@ -230,9 +296,11 @@ the pull request's number, `comment`, and `status`. A second workflow,
|
|
|
230
296
|
the Perf workflow completes (`workflow_run`), with your repository's
|
|
231
297
|
own copy of the workflow and a token that can write, so a pull request
|
|
232
298
|
from a fork gets a comment too. It checks nothing out and runs none of
|
|
233
|
-
the pull request's code. It installs Duel from RubyGems
|
|
234
|
-
|
|
235
|
-
|
|
299
|
+
the pull request's code. It installs Duel from RubyGems, exactly the
|
|
300
|
+
release that wrote the workflow (or for Duel's reusable one, the
|
|
301
|
+
release it's from), and runs `duel comment`, so what runs with a token
|
|
302
|
+
that can write can't change under it: a fix to how it comments comes
|
|
303
|
+
with a new release of Duel and the workflow it writes. The pull
|
|
236
304
|
request's code ran in the Duel job, and could have written anything
|
|
237
305
|
into the artifact, so `duel comment` trusts only what Duel could have
|
|
238
306
|
said there: a number that names the pull request whose head the run
|
|
@@ -289,13 +357,13 @@ jobs:
|
|
|
289
357
|
- name: Get the report
|
|
290
358
|
id: report
|
|
291
359
|
continue-on-error: true # there's none when the Duel job failed before comparing
|
|
292
|
-
uses: actions/download-artifact@v8
|
|
360
|
+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
293
361
|
with:
|
|
294
362
|
name: duel-report
|
|
295
363
|
path: ${{ runner.temp }}/report
|
|
296
364
|
run-id: ${{ github.event.workflow_run.id }}
|
|
297
365
|
github-token: ${{ github.token }}
|
|
298
|
-
- uses: ruby/setup-ruby@v1
|
|
366
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
299
367
|
if: steps.report.outcome == 'success'
|
|
300
368
|
with:
|
|
301
369
|
ruby-version: ruby
|
|
@@ -307,7 +375,7 @@ jobs:
|
|
|
307
375
|
GH_TOKEN: ${{ github.token }}
|
|
308
376
|
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
|
|
309
377
|
run: |
|
|
310
|
-
gem install duel --version '
|
|
378
|
+
gem install duel --version '0.3.0' --no-document
|
|
311
379
|
duel comment --report "$RUNNER_TEMP/report" --head "$HEAD_SHA" --marker 'duel'
|
|
312
380
|
|
|
313
381
|
again:
|
|
@@ -354,51 +422,15 @@ By default, a push gets no comment: Duel sets the `comment` output to
|
|
|
354
422
|
the commit job checks nothing out either, and it alone gets the
|
|
355
423
|
`contents: write` permission that a commit comment takes.
|
|
356
424
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
`duel init` again (it keeps `.duel.rb`), or add the job yourself:
|
|
362
|
-
|
|
363
|
-
```yaml
|
|
364
|
-
# .github/workflows/perf.yml, in jobs: (with c.fail_on = :pull_requests)
|
|
365
|
-
# The report, as a new comment on a pushed commit, which notifies its
|
|
366
|
-
# author, when Duel says to, as for a pull request (see the Perf comment
|
|
367
|
-
# workflow). It does only where a regression in a push passes, with
|
|
368
|
-
# c.fail_on = :pull_requests in .duel.rb, so the comment says what the
|
|
369
|
-
# check doesn't. Its last comment is the last one on any commit. This
|
|
370
|
-
# job checks nothing out and runs none of the code.
|
|
371
|
-
commit-comment:
|
|
372
|
-
name: Comment on the commit
|
|
373
|
-
needs: duel
|
|
374
|
-
if: ${{ !cancelled() && github.event_name == 'push' && (needs.duel.outputs.comment == 'post' || needs.duel.outputs.comment == 'change') }}
|
|
375
|
-
runs-on: ubuntu-latest
|
|
376
|
-
permissions:
|
|
377
|
-
contents: write # to comment on the commit with the report
|
|
378
|
-
steps:
|
|
379
|
-
- name: Get the report
|
|
380
|
-
id: report
|
|
381
|
-
continue-on-error: true # there's none when the Duel job failed before comparing
|
|
382
|
-
uses: actions/download-artifact@v8
|
|
383
|
-
with:
|
|
384
|
-
name: duel-report
|
|
385
|
-
path: ${{ runner.temp }}/report
|
|
386
|
-
- name: Comment on the commit
|
|
387
|
-
if: steps.report.outcome == 'success'
|
|
388
|
-
env:
|
|
389
|
-
GH_TOKEN: ${{ github.token }}
|
|
390
|
-
COMMENT: ${{ needs.duel.outputs.comment }}
|
|
391
|
-
STATUS: ${{ needs.duel.outputs.status }}
|
|
392
|
-
run: |
|
|
393
|
-
marker="<!-- duel"
|
|
394
|
-
last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/comments" \
|
|
395
|
-
--jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\"))" | tail -n 1)
|
|
396
|
-
if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
|
|
397
|
-
{ echo "$marker status=$STATUS -->"; cat "$RUNNER_TEMP/report/duel.md"; } > "$RUNNER_TEMP/comment.md"
|
|
398
|
-
gh api --method POST "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
|
|
399
|
-
fi
|
|
425
|
+
Like the comment workflow, the jobs for a push run Duel's own code,
|
|
426
|
+
from RubyGems: `duel comment --commit`, `duel mark-passed` and
|
|
427
|
+
`duel badge`. So a fix to one comes with a release of Duel, and none of
|
|
428
|
+
them runs the push's code.
|
|
400
429
|
|
|
401
|
-
|
|
430
|
+
The workflow that `duel init` writes has the Comment on the commit job
|
|
431
|
+
whatever `.duel.rb` says, as the job only runs where Duel says to
|
|
432
|
+
comment (see [The workflow](#catch-slow-creep)), so setting
|
|
433
|
+
`c.fail_on` later needs nothing of the workflow.
|
|
402
434
|
|
|
403
435
|
## Accept a regression with a label
|
|
404
436
|
|
|
@@ -473,92 +505,24 @@ branch yourself:
|
|
|
473
505
|
git push origin main:duel/passed/main
|
|
474
506
|
```
|
|
475
507
|
|
|
476
|
-
If you set `c.push_base` back to `:before`, delete the branches
|
|
477
|
-
(`git push origin --delete duel/passed/main`)
|
|
478
|
-
|
|
508
|
+
If you set `c.push_base` back to `:before`, you can delete the branches
|
|
509
|
+
too (`git push origin --delete duel/passed/main`): Duel no longer reads
|
|
510
|
+
them.
|
|
479
511
|
|
|
480
|
-
`duel init` writes the Mark the commit passed job
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
yourself:
|
|
485
|
-
|
|
486
|
-
```yaml
|
|
487
|
-
# .github/workflows/perf.yml, in jobs: (with c.push_base = :last_passed)
|
|
488
|
-
# With c.push_base = :last_passed in .duel.rb, a push is compared with
|
|
489
|
-
# the last commit Duel passed, which a branch marks (each branch pushed
|
|
490
|
-
# has its own), so slowdowns too small for any one push to fail add up
|
|
491
|
-
# until they fail one. This job moves the branch to a push that passed
|
|
492
|
-
# (or makes it), but never back: where a newer push's run moved it
|
|
493
|
-
# first, it stays. It checks nothing out and runs none of the code. To
|
|
494
|
-
# accept a regression, move the branch yourself (for main, git push
|
|
495
|
-
# origin main:duel/passed/main).
|
|
496
|
-
passed:
|
|
497
|
-
name: Mark the commit passed
|
|
498
|
-
needs: duel
|
|
499
|
-
# One at a time for each branch, so that two runs can't both find no
|
|
500
|
-
# branch and race to make it (a push's run doesn't wait for the one
|
|
501
|
-
# before it). One that's running is never cancelled, and one that's
|
|
502
|
-
# waiting gives way to a newer push's, which moves it further anyway.
|
|
503
|
-
concurrency:
|
|
504
|
-
group: ${{ github.workflow }}-passed-${{ github.ref_name }}
|
|
505
|
-
cancel-in-progress: false
|
|
506
|
-
if: ${{ !cancelled() && github.event_name == 'push' && needs.duel.outputs.passed == 'true' }}
|
|
507
|
-
runs-on: ubuntu-latest
|
|
508
|
-
permissions:
|
|
509
|
-
contents: write # to move the branch
|
|
510
|
-
steps:
|
|
511
|
-
- name: Move the branch to the commit
|
|
512
|
-
env:
|
|
513
|
-
GH_TOKEN: ${{ github.token }}
|
|
514
|
-
BRANCH: duel/passed/${{ github.ref_name }}
|
|
515
|
-
run: |
|
|
516
|
-
# (Git can't make a branch where another's name is a folder of its
|
|
517
|
-
# name: a branch named duel blocks duel/passed/main. If one does,
|
|
518
|
-
# this names it.)
|
|
519
|
-
blocked() {
|
|
520
|
-
prefix=$BRANCH
|
|
521
|
-
while [ "${prefix%/*}" != "$prefix" ]; do
|
|
522
|
-
prefix=${prefix%/*}
|
|
523
|
-
if gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$prefix" > /dev/null 2>&1; then
|
|
524
|
-
echo "::error::The branch $prefix keeps Duel from making $BRANCH, as Git can't have both. Delete it (git push origin --delete $prefix), or rename it."
|
|
525
|
-
fi
|
|
526
|
-
done
|
|
527
|
-
exit 1
|
|
528
|
-
}
|
|
529
|
-
# (Forward: GitHub moves it only where it's behind the push. Where
|
|
530
|
-
# there's no branch, and making it fails, it looks once more, as
|
|
531
|
-
# something else may have made it: a push of it, say.)
|
|
532
|
-
for _ in 1 2; do
|
|
533
|
-
gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null 2>&1 && exit 0
|
|
534
|
-
at=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$BRANCH" --jq .object.sha 2>/dev/null) || at=
|
|
535
|
-
[ -n "$at" ] && break
|
|
536
|
-
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null && exit 0
|
|
537
|
-
done
|
|
538
|
-
[ -n "$at" ] || blocked
|
|
539
|
-
compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status 2>&1) || case "$compared" in
|
|
540
|
-
# (GitHub can't compare commits with no history in common.)
|
|
541
|
-
*"No common ancestor"*) compared=unrelated ;;
|
|
542
|
-
esac
|
|
543
|
-
case "$compared" in
|
|
544
|
-
# (A newer push's run moved it, or this one's did, run again.)
|
|
545
|
-
ahead | identical) ;;
|
|
546
|
-
# (History rewritten, a force push's, say, or replaced: moved anyway.)
|
|
547
|
-
diverged | behind | unrelated) gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null ;;
|
|
548
|
-
*) echo "::error::Couldn't compare $BRANCH with this push: $compared" && exit 1 ;;
|
|
549
|
-
esac
|
|
550
|
-
|
|
551
|
-
```
|
|
512
|
+
The workflow that `duel init` writes has the Mark the commit passed job
|
|
513
|
+
whatever `.duel.rb` says, as the job only runs where Duel names the
|
|
514
|
+
branch to move (its `passed` output), so setting `c.push_base` later
|
|
515
|
+
needs nothing of the workflow.
|
|
552
516
|
|
|
553
517
|
## Show whether the last push passed
|
|
554
518
|
|
|
555
519
|
With `--badge`, `duel init` adds the Update the badge job, which keeps a
|
|
556
520
|
badge that turns red when Duel fails. After each push to your default
|
|
557
521
|
branch, it writes `badge.svg` to a branch of its own, `duel/badge`, so
|
|
558
|
-
your README can show it:
|
|
522
|
+
your README can show it, linked to your Perf workflow's runs:
|
|
559
523
|
|
|
560
524
|
```markdown
|
|
561
|
-
[](https://github.com/
|
|
525
|
+
[](https://github.com/OWNER/REPO/actions/workflows/perf.yml)
|
|
562
526
|
```
|
|
563
527
|
|
|
564
528
|
The badge says "perf guarded", in green, when Duel passed the push. It
|
|
@@ -598,7 +562,7 @@ keeps `.duel.rb`), or add the job yourself:
|
|
|
598
562
|
# a run for an older push than the badge's. This job writes the badge,
|
|
599
563
|
# alone, to a branch of its own, which the README shows:
|
|
600
564
|
#
|
|
601
|
-
# [](https://github.com/
|
|
565
|
+
# [](https://github.com/OWNER/REPO/actions/workflows/perf.yml)
|
|
602
566
|
#
|
|
603
567
|
# It checks nothing out, runs none of the code, and fetches nothing.
|
|
604
568
|
badge:
|
|
@@ -617,88 +581,18 @@ keeps `.duel.rb`), or add the job yourself:
|
|
|
617
581
|
permissions:
|
|
618
582
|
contents: write # to move the badge's branch
|
|
619
583
|
steps:
|
|
584
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
585
|
+
with:
|
|
586
|
+
ruby-version: ruby
|
|
587
|
+
# Duel's own code, from RubyGems (none of the push's).
|
|
620
588
|
- name: Update the badge
|
|
621
589
|
env:
|
|
622
590
|
GH_TOKEN: ${{ github.token }}
|
|
623
|
-
BRANCH: duel/badge
|
|
624
591
|
RESULT: ${{ needs.duel.result }}
|
|
625
592
|
STATUS: ${{ needs.duel.outputs.status }}
|
|
626
593
|
run: |
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
# this names it.)
|
|
630
|
-
blocked() {
|
|
631
|
-
prefix=$BRANCH
|
|
632
|
-
while [ "${prefix%/*}" != "$prefix" ]; do
|
|
633
|
-
prefix=${prefix%/*}
|
|
634
|
-
if gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$prefix" > /dev/null 2>&1; then
|
|
635
|
-
echo "::error::The branch $prefix keeps Duel from making $BRANCH, as Git can't have both. Delete it (git push origin --delete $prefix), or rename it."
|
|
636
|
-
fi
|
|
637
|
-
done
|
|
638
|
-
exit 1
|
|
639
|
-
}
|
|
640
|
-
# (Where the badge is a newer push's, that push's run has the say.
|
|
641
|
-
# Its commit names the push.)
|
|
642
|
-
last=$(gh api "repos/$GITHUB_REPOSITORY/commits/$BRANCH" --jq .commit.message 2>/dev/null | sed -n 's/^Duel.s badge, for \([0-9a-f]*\)$/\1/p') || true
|
|
643
|
-
if [ -n "$last" ] && [ "$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$last" --jq .status 2>/dev/null)" = ahead ]; then exit 0; fi
|
|
644
|
-
# (Its image, written here rather than fetched from anywhere: green,
|
|
645
|
-
# red where Duel failed the push or found a regression, or grey
|
|
646
|
-
# where the Duel job failed before Duel said either.)
|
|
647
|
-
state="perf guarded" width=133 top="#34D058" bottom="#28A745" right="76.939C78.629 0 80 1.343 80"
|
|
648
|
-
if [ "$STATUS" = failed ]; then
|
|
649
|
-
state="perf regressed" width=142 top="#EA4A5A" bottom="#D73A49" right="85.939C87.629 0 89 1.343 89"
|
|
650
|
-
elif [ "$RESULT" = failure ] && [ "$STATUS" != passed ]; then
|
|
651
|
-
state="not measured" width=138 top="#959DA5" bottom="#6A737D" right="81.939C83.629 0 85 1.343 85"
|
|
652
|
-
fi
|
|
653
|
-
cat > "$RUNNER_TEMP/badge.svg" <<SVG
|
|
654
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="$width" height="20">
|
|
655
|
-
<title>Duel - $state</title>
|
|
656
|
-
<defs>
|
|
657
|
-
<linearGradient id="duel-fill" x1="50%" y1="0%" x2="50%" y2="100%">
|
|
658
|
-
<stop stop-color="#444D56" offset="0%"></stop>
|
|
659
|
-
<stop stop-color="#24292E" offset="100%"></stop>
|
|
660
|
-
</linearGradient>
|
|
661
|
-
<linearGradient id="state-fill" x1="50%" y1="0%" x2="50%" y2="100%">
|
|
662
|
-
<stop stop-color="$top" offset="0%"></stop>
|
|
663
|
-
<stop stop-color="$bottom" offset="100%"></stop>
|
|
664
|
-
</linearGradient>
|
|
665
|
-
</defs>
|
|
666
|
-
<g fill="none" fill-rule="evenodd">
|
|
667
|
-
<g font-family="'DejaVu Sans',Verdana,Geneva,sans-serif" font-size="11">
|
|
668
|
-
<path d="M0,3 C0,1.3431 1.3552,0 3.02702703,0 L53,0 L53,20 L3.02702703,20 C1.3552,20 0,18.6569 0,17 L0,3 Z" fill="url(#duel-fill)" fill-rule="nonzero"></path>
|
|
669
|
-
<text fill="#010101" fill-opacity=".3">
|
|
670
|
-
<tspan x="22.1981982" y="15" aria-hidden="true">Duel</tspan>
|
|
671
|
-
</text>
|
|
672
|
-
<text fill="#FFFFFF">
|
|
673
|
-
<tspan x="22.1981982" y="14">Duel</tspan>
|
|
674
|
-
</text>
|
|
675
|
-
</g>
|
|
676
|
-
<g transform="translate(53)" font-family="'DejaVu Sans',Verdana,Geneva,sans-serif" font-size="11">
|
|
677
|
-
<path d="M0 0h$right 3v14c0 1.657-1.37 3-3.061 3H0V0z" fill="url(#state-fill)" fill-rule="nonzero"></path>
|
|
678
|
-
<text fill="#010101" fill-opacity=".3" aria-hidden="true">
|
|
679
|
-
<tspan x="4" y="15">$state</tspan>
|
|
680
|
-
</text>
|
|
681
|
-
<text fill="#FFFFFF">
|
|
682
|
-
<tspan x="4" y="14">$state</tspan>
|
|
683
|
-
</text>
|
|
684
|
-
</g>
|
|
685
|
-
<g fill="#959DA5">
|
|
686
|
-
<path d="M4.6 3.6L6.9 4.5L14.3 11.9L12.9 13.3L5.5 5.9Z M17.4 3.6L15.1 4.5L7.7 11.9L9.1 13.3L16.5 5.9Z"></path>
|
|
687
|
-
<circle cx="16.6" cy="15.6" r="1.1"></circle>
|
|
688
|
-
<circle cx="5.4" cy="15.6" r="1.1"></circle>
|
|
689
|
-
</g>
|
|
690
|
-
<g stroke="#959DA5" stroke-linecap="round">
|
|
691
|
-
<path d="M12.1 14.5L15.5 11.1 M9.9 14.5L6.5 11.1" stroke-width="1.6"></path>
|
|
692
|
-
<path d="M13.8 12.8L16 15 M8.2 12.8L6 15" stroke-width="1.8"></path>
|
|
693
|
-
</g>
|
|
694
|
-
</g>
|
|
695
|
-
</svg>
|
|
696
|
-
SVG
|
|
697
|
-
tree=$(jq -n --rawfile svg "$RUNNER_TEMP/badge.svg" '{tree: [{path: "badge.svg", mode: "100644", type: "blob", content: $svg}]}' |
|
|
698
|
-
gh api --method POST "repos/$GITHUB_REPOSITORY/git/trees" --input - --jq .sha)
|
|
699
|
-
commit=$(gh api --method POST "repos/$GITHUB_REPOSITORY/git/commits" -f message="Duel's badge, for $GITHUB_SHA" -f tree="$tree" --jq .sha)
|
|
700
|
-
gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$commit" -F force=true > /dev/null 2>&1 ||
|
|
701
|
-
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$commit" > /dev/null || blocked
|
|
594
|
+
gem install duel --version '0.3.0' --no-document
|
|
595
|
+
duel badge duel/badge --status "$STATUS" --result "$RESULT"
|
|
702
596
|
```
|
|
703
597
|
|
|
704
598
|
## Guard other branches
|
|
@@ -730,8 +624,10 @@ bundle exec duel init --check
|
|
|
730
624
|
|
|
731
625
|
It says whether each workflow is the same, differs (and shows how, as
|
|
732
626
|
`diff -u` does), or is missing, and writes nothing. It exits with 1
|
|
733
|
-
where one isn't the same.
|
|
734
|
-
|
|
627
|
+
where one isn't the same. For the short workflows that call Duel's, a
|
|
628
|
+
release mostly changes the tag they call. For the whole ones
|
|
629
|
+
(`--standalone`), copy in the changes you want, so that steps you
|
|
630
|
+
added to the Duel job (to install a database server, say) stay.
|
|
735
631
|
With `--gitlab`, it checks the GitLab CI jobs. In a Rails app, run
|
|
736
632
|
duel-rails's generator with `--check` instead:
|
|
737
633
|
|
|
@@ -741,28 +637,47 @@ bin/rails generate duel:install --check
|
|
|
741
637
|
|
|
742
638
|
## Call Duel's reusable workflows
|
|
743
639
|
|
|
744
|
-
Rather than copy Duel's whole workflows into your repository,
|
|
745
|
-
call Duel's reusable ones, which are
|
|
746
|
-
setting as an input.
|
|
747
|
-
Perf comment workflow that call them, at the tag of the
|
|
748
|
-
run it with, and pass on what your `.duel.rb` sets
|
|
640
|
+
Rather than copy Duel's whole workflows into your repository, the
|
|
641
|
+
workflows that `duel init` writes call Duel's reusable ones, which are
|
|
642
|
+
the same workflows with each setting as an input. It writes a Perf
|
|
643
|
+
workflow and a Perf comment workflow that call them, at the tag of the
|
|
644
|
+
Duel release you run it with, and pass on what your `.duel.rb` sets
|
|
645
|
+
(with `--standalone`, it writes the whole workflows instead):
|
|
749
646
|
|
|
750
647
|
```yaml
|
|
751
648
|
# .github/workflows/perf.yml
|
|
752
649
|
jobs:
|
|
753
650
|
duel:
|
|
754
|
-
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.
|
|
651
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
755
652
|
permissions:
|
|
756
653
|
contents: read
|
|
757
654
|
pull-requests: read # for the pull request's labels (see c.accept_label)
|
|
758
655
|
with:
|
|
759
656
|
ruby-version: "3.4"
|
|
760
|
-
|
|
657
|
+
push:
|
|
658
|
+
needs: duel
|
|
659
|
+
if: ${{ !cancelled() && github.event_name == 'push' }}
|
|
660
|
+
uses: sferik/duel-ruby/.github/workflows/duel-push.yml@v0.3.0
|
|
661
|
+
permissions:
|
|
662
|
+
contents: write # to comment on the commit, move the passed branch, and the badge's
|
|
663
|
+
with:
|
|
664
|
+
comment: ${{ needs.duel.outputs.comment }}
|
|
665
|
+
status: ${{ needs.duel.outputs.status }}
|
|
666
|
+
passed: ${{ needs.duel.outputs.passed }}
|
|
667
|
+
result: ${{ needs.duel.result }}
|
|
761
668
|
```
|
|
762
669
|
|
|
763
670
|
Your workflows keep their triggers, their concurrency and their
|
|
764
|
-
permissions, which Duel's jobs can only narrow. The job
|
|
765
|
-
pull request's code only reads, as it does in
|
|
671
|
+
permissions, which Duel's jobs can only narrow. The Duel job, which runs
|
|
672
|
+
the pull request's code, only reads (`contents: read`), as it does in
|
|
673
|
+
the whole workflow. The jobs for a push that write to the repository
|
|
674
|
+
(the [comment on a pushed commit](#comment-on-a-pushed-commit),
|
|
675
|
+
[marking a push passed](#compare-a-push-with-the-last-commit-that-passed)
|
|
676
|
+
and [the badge](#show-whether-the-last-push-passed)) are Duel's push
|
|
677
|
+
workflow's (`.github/workflows/duel-push.yml`), which your workflow
|
|
678
|
+
calls once the Duel job is done, only for a push, and grants
|
|
679
|
+
`contents: write` to alone. So a pull request's run is never given a
|
|
680
|
+
token that writes (see below).
|
|
766
681
|
|
|
767
682
|
Duel's Perf workflow (`.github/workflows/duel.yml`) takes these inputs:
|
|
768
683
|
|
|
@@ -770,26 +685,32 @@ Duel's Perf workflow (`.github/workflows/duel.yml`) takes these inputs:
|
|
|
770
685
|
| --- | --- | --- |
|
|
771
686
|
| `ruby-version` | `default` | The Ruby the Duel job runs (`default`: the one `.ruby-version` names). |
|
|
772
687
|
| `version-file` | `false` | Whether each version runs on the Ruby its own `.ruby-version` names ([`c.ruby = :version_file`](configuration.md)). |
|
|
773
|
-
| `
|
|
774
|
-
| `runs-on` | `ubuntu-latest` | The runner the Duel job runs on, Linux or
|
|
688
|
+
| `jit` | `none` | The JIT the benchmarks run with on, as Ruby runs one at most: `none`, `yjit` (`RUBY_YJIT_ENABLE=1`), as a Rails app runs, say, or `zjit` (`RUBY_ZJIT_ENABLE=1`), on Ruby 4.0 or later. Duel fails where a version's Ruby doesn't run it (JRuby, or for ZJIT, Ruby 3.4, say). |
|
|
689
|
+
| `runs-on` | `ubuntu-latest` | The runner the Duel job runs on, Linux, macOS or Windows: a larger one, say, for steadier timings. See [On Windows](#on-windows). |
|
|
775
690
|
| `timeout-minutes` | `60` | How long the Duel job may take before it's cancelled. |
|
|
776
691
|
| `working-directory` | `.` | The project's directory, from the repository's root. |
|
|
777
692
|
| `gemfile` | none | A Gemfile of Duel's own, from the project's directory (`gemfiles/duel.gemfile`, say), which keeps Duel out of the project's other bundles. Duel and both versions' workers run in its bundle, so it needs what the benchmarks load (`eval_gemfile "../Gemfile"`, say). |
|
|
778
693
|
| `submodules` | `false` | Whether to check out the repository's submodules too (`true`, or `recursive`), as [actions/checkout](https://github.com/actions/checkout) takes it. |
|
|
779
694
|
| `setup` | none | Shell commands that set up whatever else your tests need (packages, services), before Ruby is set up. |
|
|
695
|
+
| `setup-after-ruby` | none | Shell commands that set up what needs Ruby first (on Windows, a package of Ruby's devkit, from `pacman`, say), before the bundle is installed. See [On Windows](#on-windows). With them, the bundle isn't cached. |
|
|
780
696
|
| `report` | none | A name for the call's report and check (`yjit`, say), where your workflow calls Duel's more than once: see below. |
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
697
|
+
|
|
698
|
+
It takes nothing that `.duel.rb` says, which Duel reads as it runs. It
|
|
699
|
+
says what Duel said, as its outputs, for Duel's push workflow and for
|
|
700
|
+
jobs of your own (a notice in a channel, say): `comment` (`post` or
|
|
701
|
+
`change`, or nothing), `status` (`passed`, `failed` or `neutral`) and
|
|
702
|
+
`passed` (the branch that marks the push passed, `duel/passed/main`
|
|
703
|
+
say, or nothing).
|
|
704
|
+
|
|
705
|
+
Duel's push workflow (`.github/workflows/duel-push.yml`) takes those
|
|
706
|
+
outputs as its inputs of the same names, and `result`, how the Duel
|
|
707
|
+
job's call ended (`needs.duel.result`), which the badge shows where it
|
|
708
|
+
failed. Its jobs run where they say to. It takes `working-directory`
|
|
709
|
+
and `report` too, as given to the Duel job's call, and `badge`
|
|
710
|
+
(`false` by default), whether to
|
|
711
|
+
[keep a badge](#show-whether-the-last-push-passed) for the README. The
|
|
712
|
+
names of the branches its jobs move, and of the badge's, and the
|
|
713
|
+
marker of its comments, come from `working-directory`.
|
|
793
714
|
|
|
794
715
|
To measure each version more than one way, call Duel's Perf workflow
|
|
795
716
|
more than once, each call with a `report` of its own:
|
|
@@ -797,15 +718,24 @@ more than once, each call with a `report` of its own:
|
|
|
797
718
|
```yaml
|
|
798
719
|
jobs:
|
|
799
720
|
yjit:
|
|
800
|
-
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.
|
|
721
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
801
722
|
permissions:
|
|
802
723
|
contents: read
|
|
803
724
|
pull-requests: read
|
|
804
725
|
with:
|
|
805
|
-
|
|
726
|
+
jit: yjit
|
|
806
727
|
report: yjit
|
|
728
|
+
zjit:
|
|
729
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
730
|
+
permissions:
|
|
731
|
+
contents: read
|
|
732
|
+
pull-requests: read
|
|
733
|
+
with:
|
|
734
|
+
ruby-version: "4.0"
|
|
735
|
+
jit: zjit
|
|
736
|
+
report: zjit
|
|
807
737
|
interpreter:
|
|
808
|
-
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.
|
|
738
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
809
739
|
permissions:
|
|
810
740
|
contents: read
|
|
811
741
|
pull-requests: read
|
|
@@ -816,21 +746,99 @@ jobs:
|
|
|
816
746
|
Each call is a check of its own (`yjit / Duel (yjit)`), and the Perf
|
|
817
747
|
comment workflow comments with every call's report, as one comment,
|
|
818
748
|
each under its name. The comment's status is the most any call's
|
|
819
|
-
says: failed, if any failed, and passed only if every one passed.
|
|
820
|
-
|
|
821
|
-
|
|
749
|
+
says: failed, if any failed, and passed only if every one passed. For
|
|
750
|
+
the jobs for a push, call Duel's push workflow after a call, with what
|
|
751
|
+
it said and its `report`:
|
|
752
|
+
|
|
753
|
+
```yaml
|
|
754
|
+
yjit-push:
|
|
755
|
+
needs: yjit
|
|
756
|
+
if: ${{ !cancelled() && github.event_name == 'push' }}
|
|
757
|
+
uses: sferik/duel-ruby/.github/workflows/duel-push.yml@v0.3.0
|
|
758
|
+
permissions:
|
|
759
|
+
contents: write
|
|
760
|
+
with:
|
|
761
|
+
comment: ${{ needs.yjit.outputs.comment }}
|
|
762
|
+
status: ${{ needs.yjit.outputs.status }}
|
|
763
|
+
passed: ${{ needs.yjit.outputs.passed }}
|
|
764
|
+
result: ${{ needs.yjit.result }}
|
|
765
|
+
report: yjit
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
Turn on `badge` in one such call at most, as each call's jobs run on
|
|
769
|
+
their own, and with `c.fail_on = :pull_requests` or
|
|
770
|
+
`c.push_base = :last_passed`, each one comments on a push, or marks it
|
|
771
|
+
passed, as its Duel says.
|
|
772
|
+
|
|
773
|
+
### On Windows
|
|
774
|
+
|
|
775
|
+
The Duel job runs its steps, and `setup` and `setup-after-ruby`, in
|
|
776
|
+
bash on every runner, not PowerShell: on Windows, Git's, and once Ruby
|
|
777
|
+
is set up, the bash of Ruby's devkit (MSYS2). setup-ruby sets the devkit
|
|
778
|
+
up, with its gcc, so a gem's C extension builds without help. A C
|
|
779
|
+
library that an extension links can come from the devkit too, with
|
|
780
|
+
`pacman`, which is there only once Ruby is set up, so install it in
|
|
781
|
+
`setup-after-ruby`, and the job installs the bundle after it. Add a call
|
|
782
|
+
for Windows next to the one for Linux, say:
|
|
783
|
+
|
|
784
|
+
```yaml
|
|
785
|
+
jobs:
|
|
786
|
+
linux:
|
|
787
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
788
|
+
permissions:
|
|
789
|
+
contents: read
|
|
790
|
+
pull-requests: read
|
|
791
|
+
with:
|
|
792
|
+
report: linux
|
|
793
|
+
windows:
|
|
794
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@v0.3.0
|
|
795
|
+
permissions:
|
|
796
|
+
contents: read
|
|
797
|
+
pull-requests: read
|
|
798
|
+
with:
|
|
799
|
+
runs-on: windows-latest
|
|
800
|
+
report: windows
|
|
801
|
+
# (libyaml, say, for psych.)
|
|
802
|
+
setup-after-ruby: pacman --sync --needed --noconfirm "${MINGW_PACKAGE_PREFIX}-libyaml"
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
`MINGW_PACKAGE_PREFIX` is the devkit's (setup-ruby sets it), and so is
|
|
806
|
+
`RI_DEVKIT`, its directory. Paths from bash there look like `/c/...`,
|
|
807
|
+
and Ruby reads `C:/...`: `cygpath -m` turns one into the other. To put
|
|
808
|
+
a directory on the `PATH` (with `$GITHUB_PATH`), mind the order: each
|
|
809
|
+
line goes before those written before it, and a DLL ahead of the
|
|
810
|
+
devkit's (a database's client library's, say) can keep its gcc from
|
|
811
|
+
running. Write them on one line, `;` between, the devkit's first.
|
|
822
812
|
|
|
823
813
|
Duel's Perf comment workflow (`.github/workflows/duel-comment.yml`)
|
|
824
814
|
takes `accept-label`, `marker`, and `perf-workflow` (the name of your
|
|
825
815
|
Perf workflow, `Perf` by default).
|
|
826
816
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
817
|
+
The jobs for pushes, and the badge's, write to the repository, so the
|
|
818
|
+
call of Duel's push workflow grants `contents: write`. GitHub checks
|
|
819
|
+
every job of a workflow it calls against what the caller grants,
|
|
820
|
+
whether the job runs or not, and a run where one asks for more fails
|
|
821
|
+
before it starts. That's why they're a workflow of their own: were they
|
|
822
|
+
the Perf workflow's, its call, and so a pull request's run, would have
|
|
823
|
+
to grant `contents: write` too.
|
|
824
|
+
|
|
825
|
+
With an accept label, your Perf comment workflow grants
|
|
830
826
|
`actions: write`, to run the Duel job again. The checks are named for
|
|
831
827
|
your job and Duel's, as in `duel / Duel`. To update Duel's workflows,
|
|
832
|
-
change the tag. `duel init --check
|
|
833
|
-
|
|
828
|
+
change the tag. `duel init --check` compares the workflows that call
|
|
829
|
+
them, and `duel init --check --standalone` the whole ones.
|
|
830
|
+
|
|
831
|
+
A tag can be moved, so you can name the commit it's at instead, with
|
|
832
|
+
the tag beside it, as Dependabot keeps them:
|
|
833
|
+
|
|
834
|
+
```yaml
|
|
835
|
+
uses: sferik/duel-ruby/.github/workflows/duel.yml@<commit> # v0.3.0
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
Duel's workflows, the reusable ones and those `duel init` writes, name
|
|
839
|
+
each action they use by its commit too, and the jobs that write to the
|
|
840
|
+
repository (or comment) install exactly the release of Duel that wrote
|
|
841
|
+
them (`gem install duel --version '0.3.0'`), not the newest one.
|
|
834
842
|
|
|
835
843
|
## Run Duel on GitLab CI
|
|
836
844
|
|
|
@@ -876,7 +884,7 @@ log and its `duel.md` artifact have the report.
|
|
|
876
884
|
protected, so only your protected branches' pipelines have it, to
|
|
877
885
|
comment on a pushed commit and to mark a push passed.
|
|
878
886
|
|
|
879
|
-
The comment on a merge request comes from `duel comment
|
|
887
|
+
The comment on a merge request comes from `duel comment`, on GitLab CI,
|
|
880
888
|
installed from RubyGems in a `ruby:slim` image, as on GitHub, so a fix
|
|
881
889
|
to it comes with a release of Duel. It trusts only a `DUEL_COMMENT` and
|
|
882
890
|
a `DUEL_STATUS` that Duel says, and comments only if the merge
|
|
@@ -924,12 +932,10 @@ duel:
|
|
|
924
932
|
DUEL_OUTPUT: duel.env # whether to comment, and mark a push passed
|
|
925
933
|
rules:
|
|
926
934
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
935
|
+
# (Duel compares a push with the commit before it, and a schedule's
|
|
936
|
+
# run with the last release, as CI_PIPELINE_SOURCE says.)
|
|
927
937
|
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
928
|
-
variables:
|
|
929
|
-
DUEL_BASE: $CI_COMMIT_BEFORE_SHA
|
|
930
938
|
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
931
|
-
variables:
|
|
932
|
-
DUEL_BASE: last-release
|
|
933
939
|
# (Run by hand, it compares anyway: with nothing changed, the code
|
|
934
940
|
# with itself, which checks the setup.)
|
|
935
941
|
- if: $CI_PIPELINE_SOURCE == "web"
|
|
@@ -971,17 +977,18 @@ duel:comment:
|
|
|
971
977
|
variables:
|
|
972
978
|
GIT_STRATEGY: none # it runs none of the code
|
|
973
979
|
script:
|
|
974
|
-
- gem install duel --version '
|
|
980
|
+
- gem install duel --version '0.3.0' --no-document
|
|
975
981
|
# (The merge request's head: in a merged results pipeline, not the
|
|
976
982
|
# commit that merges it.)
|
|
977
|
-
- duel comment --
|
|
983
|
+
- duel comment --report . --head "${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-$CI_COMMIT_SHA}" --marker 'duel'
|
|
978
984
|
|
|
979
985
|
# The report, as a new comment on a pushed commit, when Duel says to, as
|
|
980
986
|
# for a merge request: only where a regression in a push passes (see
|
|
981
987
|
# c.fail_on), so the comment says what the check doesn't. Its last comment
|
|
982
|
-
# is the commit before's.
|
|
988
|
+
# is the commit before's. It runs `duel comment`, from RubyGems, signed in
|
|
989
|
+
# with DUEL_TOKEN.
|
|
983
990
|
duel:commit-comment:
|
|
984
|
-
image:
|
|
991
|
+
image: ruby:slim
|
|
985
992
|
stage: .post
|
|
986
993
|
needs: [duel]
|
|
987
994
|
rules:
|
|
@@ -990,31 +997,19 @@ duel:commit-comment:
|
|
|
990
997
|
variables:
|
|
991
998
|
GIT_STRATEGY: none # it runs none of the code
|
|
992
999
|
script:
|
|
993
|
-
-
|
|
994
|
-
-
|
|
995
|
-
case "$DUEL_COMMENT" in post|change) ;; *) exit 0 ;; esac
|
|
996
|
-
report=duel.md
|
|
997
|
-
[ -f "$report" ] || exit 0
|
|
998
|
-
api="$CI_API_V4_URL/projects/$CI_PROJECT_ID"
|
|
999
|
-
token="PRIVATE-TOKEN: $DUEL_TOKEN"
|
|
1000
|
-
marker="<!-- duel"
|
|
1001
|
-
me=$(curl -sf -H "$token" "$CI_API_V4_URL/user" | jq .id)
|
|
1002
|
-
last=$(curl -sf -H "$token" "$api/repository/commits/$CI_COMMIT_BEFORE_SHA/comments?per_page=100" |
|
|
1003
|
-
jq -r --argjson me "$me" --arg marker "$marker status=" '.[] | select(.author.id == $me) | .note | split("\n")[0] | rtrimstr("\r") | select(startswith($marker))' | tail -n 1)
|
|
1004
|
-
if [ "$DUEL_COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$DUEL_STATUS -->" ]; }; then
|
|
1005
|
-
{ echo "$marker status=$DUEL_STATUS -->"; cat "$report"; } | jq -Rs '{note: .}' |
|
|
1006
|
-
curl -sf -H "$token" -H "Content-Type: application/json" --data @- "$api/repository/commits/$CI_COMMIT_SHA/comments" > /dev/null
|
|
1007
|
-
fi
|
|
1000
|
+
- gem install duel --version '0.3.0' --no-document
|
|
1001
|
+
- duel comment --report . --commit "$CI_COMMIT_SHA" --marker 'duel'
|
|
1008
1002
|
|
|
1009
1003
|
# With c.push_base = :last_passed in .duel.rb, a push is compared with the
|
|
1010
1004
|
# last commit Duel passed, which a branch marks (duel/passed/main for
|
|
1011
1005
|
# main), so slowdowns too small for any one push to fail add up until they
|
|
1012
|
-
# fail one. This job moves the branch
|
|
1013
|
-
# but never back: where a newer push's job
|
|
1014
|
-
#
|
|
1015
|
-
#
|
|
1006
|
+
# fail one. This job moves the branch (as Duel names it, DUEL_PASSED) to a
|
|
1007
|
+
# push that passed (or makes it), but never back: where a newer push's job
|
|
1008
|
+
# moved it first, it stays. It runs `duel mark-passed`, from RubyGems,
|
|
1009
|
+
# signed in with DUEL_TOKEN. To accept a regression, move the branch
|
|
1010
|
+
# yourself (for main, git push origin main:duel/passed/main).
|
|
1016
1011
|
duel:passed:
|
|
1017
|
-
image:
|
|
1012
|
+
image: ruby:slim
|
|
1018
1013
|
stage: .post
|
|
1019
1014
|
needs: [duel]
|
|
1020
1015
|
# One at a time, as each deletes the branch and makes it again: two at
|
|
@@ -1025,32 +1020,9 @@ duel:passed:
|
|
|
1025
1020
|
variables:
|
|
1026
1021
|
GIT_STRATEGY: none # it runs none of the code
|
|
1027
1022
|
script:
|
|
1028
|
-
-
|
|
1029
|
-
-
|
|
1030
|
-
|
|
1031
|
-
api="$CI_API_V4_URL/projects/$CI_PROJECT_ID"
|
|
1032
|
-
token="PRIVATE-TOKEN: $DUEL_TOKEN"
|
|
1033
|
-
branch="duel/passed/$CI_COMMIT_BRANCH"
|
|
1034
|
-
at=$(curl -sf -H "$token" "$api/repository/branches/$(echo "$branch" | sed 's|/|%2F|g')" | jq -r '.commit.id // empty') || at=
|
|
1035
|
-
if [ -n "$at" ]; then
|
|
1036
|
-
base=$(curl -sf -H "$token" "$api/repository/merge_base?refs%5B%5D=$CI_COMMIT_SHA&refs%5B%5D=$at" | jq -r '.id // empty') || base=
|
|
1037
|
-
[ -n "$base" ] || { echo "Couldn't compare $branch with this push" && exit 1; }
|
|
1038
|
-
# (A newer push's job moved it, or this one's did, run again.)
|
|
1039
|
-
[ "$base" = "$CI_COMMIT_SHA" ] && exit 0
|
|
1040
|
-
fi
|
|
1041
|
-
curl -s -o /dev/null -H "$token" -X DELETE "$api/repository/branches/$(echo "$branch" | sed 's|/|%2F|g')"
|
|
1042
|
-
curl -sf -o /dev/null -H "$token" --data-urlencode "branch=$branch" --data-urlencode "ref=$CI_COMMIT_SHA" "$api/repository/branches" && exit 0
|
|
1043
|
-
# (Git can't make a branch where another's name is a folder of its
|
|
1044
|
-
# name: a branch named duel blocks duel/passed/main. If one does,
|
|
1045
|
-
# this names it.)
|
|
1046
|
-
prefix=$branch
|
|
1047
|
-
while [ "${prefix%/*}" != "$prefix" ]; do
|
|
1048
|
-
prefix=${prefix%/*}
|
|
1049
|
-
if curl -sf -o /dev/null -H "$token" "$api/repository/branches/$(echo "$prefix" | sed 's|/|%2F|g')"; then
|
|
1050
|
-
echo "The branch $prefix keeps Duel from making $branch, as Git can't have both. Delete it (git push origin --delete $prefix), or rename it."
|
|
1051
|
-
fi
|
|
1052
|
-
done
|
|
1053
|
-
exit 1
|
|
1023
|
+
- '[ -n "$DUEL_PASSED" ] || exit 0'
|
|
1024
|
+
- gem install duel --version '0.3.0' --no-document
|
|
1025
|
+
- duel mark-passed "$DUEL_PASSED"
|
|
1054
1026
|
```
|
|
1055
1027
|
|
|
1056
1028
|
## Run each version on its own Ruby on CI
|
|
@@ -1062,64 +1034,51 @@ runs `duel` where no version manager looks. That's enough while both
|
|
|
1062
1034
|
versions ask for that Ruby. A branch that upgrades Ruby needs the
|
|
1063
1035
|
baseline's Ruby installed too, where Duel finds it. For example, for a
|
|
1064
1036
|
project with a `.ruby-version`, in the
|
|
1065
|
-
[GitHub Actions workflow](#catch-slow-creep),
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1037
|
+
[GitHub Actions workflow](#catch-slow-creep), once your Ruby and its
|
|
1038
|
+
bundle are set up, ask Duel which commit the Compare step compares
|
|
1039
|
+
with: `bundle exec duel base` prints it, as the run will find it, for
|
|
1040
|
+
whatever event the run is for (where `HEAD` left the main branch for a
|
|
1041
|
+
pull request, the commit before a push, or the last commit Duel passed,
|
|
1042
|
+
and the last release on a schedule), with `.duel.rb`'s settings, or
|
|
1043
|
+
nothing, without a baseline, such as for a branch's first push, or
|
|
1044
|
+
before your first release. When that commit's `.ruby-version` names
|
|
1069
1045
|
another Ruby than yours, install that Ruby with a second
|
|
1070
1046
|
`ruby/setup-ruby` step, with the bundle for it (`bundler-cache: true`),
|
|
1071
|
-
|
|
1072
|
-
chruby does
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
Duel does by default: if `.duel.rb` sets `c.main_branch` or
|
|
1078
|
-
`c.release_tags`, set the step's `MAIN_BRANCH` or `RELEASE_TAGS` to
|
|
1079
|
-
match. `duel init` adds these steps for a project that has a
|
|
1047
|
+
link it into `~/.rubies`, where Duel looks for Rubies the way that
|
|
1048
|
+
chruby does, and put your own Ruby first on the `PATH` again, which the
|
|
1049
|
+
second step took the place of. The baseline's workers load the same
|
|
1050
|
+
bundle as the candidate's, and gems installed for one Ruby version don't
|
|
1051
|
+
load on another, so without that bundle they can't load the code to
|
|
1052
|
+
compare. `duel init` adds these steps for a project that has a
|
|
1080
1053
|
`.ruby-version`:
|
|
1081
1054
|
|
|
1082
1055
|
```yaml
|
|
1083
|
-
# (
|
|
1056
|
+
# (After the step that sets up the candidate's Ruby, id: ruby.)
|
|
1084
1057
|
# Each version runs on the Ruby its own .ruby-version names (see
|
|
1085
1058
|
# .duel.rb). When the baseline's names another Ruby than this code's,
|
|
1086
|
-
# that one is installed too, and linked where Duel
|
|
1087
|
-
# chruby would),
|
|
1088
|
-
#
|
|
1089
|
-
#
|
|
1090
|
-
# base, the commit before a push (or the last commit Duel passed, PASSED, if there is
|
|
1091
|
-
# one: see the Mark the commit passed job), or on a schedule the last
|
|
1092
|
-
# release, the newest tag before HEAD that RELEASE_TAGS matches
|
|
1093
|
-
# (or ACCEPTED, the last change accepted since then). (If
|
|
1094
|
-
# .duel.rb sets c.main_branch or c.release_tags, set MAIN_BRANCH or
|
|
1095
|
-
# RELEASE_TAGS to match.)
|
|
1059
|
+
# that one is installed too, with its bundle, and linked where Duel
|
|
1060
|
+
# finds it (as chruby would), and the project's own Ruby, which runs
|
|
1061
|
+
# Duel, comes first again. The baseline is the one the Compare step
|
|
1062
|
+
# compares with, as Duel finds it (duel base).
|
|
1096
1063
|
- name: Find the baseline's Ruby
|
|
1097
1064
|
id: baseline
|
|
1098
1065
|
env:
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
MAIN_BRANCH: origin/${{ github.base_ref || github.event.repository.default_branch }}
|
|
1103
|
-
RELEASE_TAGS: "v*"
|
|
1104
|
-
ACCEPTED: ${{ steps.labels.outputs.accepted }}
|
|
1066
|
+
# (On a schedule, for the last change a label accepted since the
|
|
1067
|
+
# last release, which Duel finds with gh.)
|
|
1068
|
+
GH_TOKEN: ${{ github.event_name == 'schedule' && github.token || '' }}
|
|
1105
1069
|
run: |
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
merge_group) base=$QUEUE_BASE ;;
|
|
1111
|
-
schedule) base=${ACCEPTED:-$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null)} || base= ;;
|
|
1112
|
-
*) base=$(git merge-base HEAD "$MAIN_BRANCH" 2>/dev/null) || base= ;;
|
|
1113
|
-
esac
|
|
1114
|
-
ruby_of() { git show "$1:./.ruby-version" 2>/dev/null | awk 'NF { print $1; exit }'; }
|
|
1070
|
+
base=$(bundle exec duel base)
|
|
1071
|
+
# (None where the commit has no .ruby-version: git fails, which
|
|
1072
|
+
# fails the pipeline, under pipefail.)
|
|
1073
|
+
ruby_of() { git show "$1:./.ruby-version" 2>/dev/null | awk 'NF { print $1; exit }' || true; }
|
|
1115
1074
|
ruby=
|
|
1116
1075
|
# (None without a baseline: a branch's first push, or no release yet.)
|
|
1117
|
-
if [ -n "$base" ]
|
|
1076
|
+
if [ -n "$base" ]; then
|
|
1118
1077
|
ruby=$(ruby_of "$base")
|
|
1119
1078
|
[ "$ruby" = "$(ruby_of HEAD)" ] && ruby=
|
|
1120
1079
|
fi
|
|
1121
1080
|
echo "ruby=$ruby" >> "$GITHUB_OUTPUT"
|
|
1122
|
-
- uses: ruby/setup-ruby@v1
|
|
1081
|
+
- uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0
|
|
1123
1082
|
id: baseline-ruby
|
|
1124
1083
|
if: steps.baseline.outputs.ruby != ''
|
|
1125
1084
|
with:
|
|
@@ -1131,7 +1090,14 @@ match. `duel init` adds these steps for a project that has a
|
|
|
1131
1090
|
if: steps.baseline.outputs.ruby != ''
|
|
1132
1091
|
env:
|
|
1133
1092
|
PREFIX: ${{ steps.baseline-ruby.outputs.ruby-prefix }}
|
|
1093
|
+
RUBY_PREFIX: ${{ steps.ruby.outputs.ruby-prefix }}
|
|
1094
|
+
MSYS: winsymlinks:nativestrict # (on Windows, bash's ln links, not copies)
|
|
1134
1095
|
run: |
|
|
1096
|
+
# (The project's own Ruby first again, for the steps after: it
|
|
1097
|
+
# runs Duel.)
|
|
1098
|
+
echo "$RUBY_PREFIX/bin" >> "$GITHUB_PATH"
|
|
1099
|
+
# (On Windows, as bash's /c/..., not C:\..., which it can't run.)
|
|
1100
|
+
if command -v cygpath > /dev/null; then PREFIX=$(cygpath -u "$PREFIX"); fi
|
|
1135
1101
|
mkdir -p ~/.rubies
|
|
1136
1102
|
ln -sfn "$PREFIX" ~/.rubies/ruby-"$("$PREFIX/bin/ruby" -e 'print RUBY_VERSION')"
|
|
1137
1103
|
```
|