duel-rails 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c9e748bfafe8fa99ec68348af035b11eff2acb55667d4a19673c28434879052
4
- data.tar.gz: 3332736f9955c3718117a75561ab7cf54cbaf80513d3c4e8590d0bfe5d224c9b
3
+ metadata.gz: 81ef95643e521662165107851a57bf291c2ef90d8f3ebf7260c761353afdea1d
4
+ data.tar.gz: c48b15ef972f117df95abcfc8d46303c8b10f30d7758e7aa24551a36f6e5a725
5
5
  SHA512:
6
- metadata.gz: fd47a29c4976ec55ec33c7cfb70bc86c9b5673bbfaf445db9eaa06ee6d76a7aa17203dee610f059fd1f3e239a9250868d919ae44358ebafa7475f81484985986
7
- data.tar.gz: 589eb2468415a54e669772293e1b0727904e44e0a6318e7a0ab529d2237a797f8cac981d1f221746a240e50ff31451ae4b698c1ac92a5323a88cd7a038b643a4
6
+ metadata.gz: 3ccf58afcefb2d852c7eb7692c4a6436e07cc0581f50144a734c3ba73bf87681613a9ea4a615d978ad9c39ad919844a2801a7ef635292739e3efecf22e7415e6
7
+ data.tar.gz: 33df2071653cce8e5492ca9f8cda1b5c697358b082ae56255ef4f53143fad1fcbe06528802525a5a7095b8b4671466b1c298507292c75e7af10d15a7702c3d61
data/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.6] - 2026-11-10
11
+
12
+ ### Added
13
+
14
+ - The generator's workflows do what `duel init`'s do with the label that
15
+ accepts a regression: the comment workflow runs the Duel job again
16
+ when the label is added or taken off, and on a schedule, the Duel job
17
+ compares with the last change merged with the label since the last
18
+ release.
19
+
20
+ ### Fixed
21
+
22
+ - The comment workflow fences a fork's report that has a NUL byte as it
23
+ does any other (see Duel's changelog).
24
+ - The Mark the commit passed job runs one at a time for each branch, so
25
+ two pushes that pass before the branch exists can't both try to make
26
+ it (see Duel's changelog).
27
+
10
28
  ## [0.1.5] - 2026-11-08
11
29
 
12
30
  ### Changed
@@ -232,7 +250,8 @@ Rails 7.2 or later, and Ruby 3.4 or later.
232
250
  CI.
233
251
  - RBS signatures in sig/, checked with Steep.
234
252
 
235
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.5...HEAD
253
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.6...HEAD
254
+ [0.1.6]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.5...duel-rails-v0.1.6
236
255
  [0.1.5]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.4...duel-rails-v0.1.5
237
256
  [0.1.4]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.3...duel-rails-v0.1.4
238
257
  [0.1.3]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.2...duel-rails-v0.1.3
data/README.md CHANGED
@@ -10,7 +10,7 @@ them query the database, render views, or allocate more.
10
10
 
11
11
  ```sh
12
12
  $ bin/rake duel
13
- Comparing 3 benchmarks, 2 at a time: baseline /src/.8e2f1c4 against candidate /src/my_app (slower: a 99.0% interval above 1.02)
13
+ Comparing 3 benchmarks, 2 at a time: baseline /src/.8e2f1c4 against candidate /src/my_app (slower: a 99.0% interval above 1.02, over 12 worker processes of each version)
14
14
  posts: index 2.7s n=4 cpu 1.004 [0.991, 1.018] same active_record_queries 1→2 rails_views 4→7 allocations 988→1530
15
15
  ...
16
16
  REGRESSION posts: index: worse active_record_queries, rails_views, allocations in every measurement
@@ -451,8 +451,8 @@ and the bundle, in the app's directory (`working-directory`).
451
451
  ## YJIT
452
452
 
453
453
  Rails 7.2 and later turn YJIT on as the app boots. When YJIT is on,
454
- Duel warms each benchmark up for two seconds before it measures it, so
455
- that YJIT has compiled your app's code first.
454
+ Duel warms each benchmark up until it's steady, for up to ten seconds,
455
+ before it measures it, so that YJIT has compiled your app's code first.
456
456
 
457
457
  ## Requirements
458
458
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Rails
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
@@ -98,6 +98,10 @@ module Duel
98
98
  found.nil? || found.push_base == :last_passed
99
99
  end
100
100
 
101
+ # The label that accepts a regression, for the workflows, as for
102
+ # `duel init` (see Duel::Init#accept_label).
103
+ def accept_label = settings&.accept_label
104
+
101
105
  # Whether the workflow keeps a badge for the README (--badge), as for
102
106
  # `duel init` (see Duel::Init#badge?).
103
107
  def badge? = options.fetch(:badge)
@@ -10,12 +10,27 @@ name: Perf comment<%= " (#{working_directory})" if working_directory %>
10
10
  # ran), it trusts only what that job could have said: the pull request's
11
11
  # number, if it names the pull request the run compared, and the comment
12
12
  # and the status, if they're ones Duel says. A fork's report, which the
13
- # fork's code wrote, is shown as text. (The workflow must be on the
14
- # default branch before it runs at all.)
13
+ # fork's code wrote, is shown as text.
14
+ <% if accept_label -%>
15
+ #
16
+ # And when the label that accepts a regression (c.accept_label in
17
+ # .duel.rb) is added to a pull request, or taken off, it runs the Duel
18
+ # job again, which reads the labels as it runs: a run that failed, once
19
+ # the label's added, or one that passed, once it's taken off.
20
+ <% end -%>
21
+ #
22
+ # (The workflow must be on the default branch before it runs at all.)
15
23
  on:
16
24
  workflow_run:
17
25
  workflows: ["Perf<%= " (#{working_directory})" if working_directory %>"]
18
26
  types: [completed]
27
+ <% if accept_label -%>
28
+ # (This repository's own workflow, as for the comment, with a token
29
+ # that can run a workflow again: it checks nothing out, and runs none
30
+ # of the pull request's code.)
31
+ pull_request_target:
32
+ types: [labeled, unlabeled]
33
+ <% end -%>
19
34
 
20
35
  permissions: {}
21
36
 
@@ -56,12 +71,16 @@ jobs:
56
71
  # ran the fork's code, which could have written anything in it. In
57
72
  # a code block, fenced with more backticks than any run of them in
58
73
  # the report, it can't mention anyone, link anywhere or show an
59
- # image. (And it's cut short where a comment couldn't hold it.)
74
+ # image. It's cut short where a comment couldn't hold it, and loses
75
+ # any NUL bytes, which GitHub wouldn't take, and grep reads it as
76
+ # text whatever's in it, so it finds every run of backticks.
60
77
  report() {
61
78
  if [ "${head#* }" = "$GITHUB_REPOSITORY" ]; then cat "$RUNNER_TEMP/report/duel.md" && return; fi
62
- fence=$(grep -o '``*' "$RUNNER_TEMP/report/duel.md" | awk '{ if (length > n) n = length } END { n = (n < 3) ? 3 : n + 1; while (n-- > 0) printf "`" }')
79
+ text="$RUNNER_TEMP/report.txt"
80
+ LC_ALL=C tr -d '\000' < "$RUNNER_TEMP/report/duel.md" | head -c 60000 > "$text"
81
+ fence=$(LC_ALL=C grep -ao '``*' "$text" | awk '{ if (length > n) n = length } END { n = (n < 3) ? 3 : n + 1; while (n-- > 0) printf "`" }')
63
82
  printf 'From a fork, so shown as text:\n\n%s\n' "$fence"
64
- head -c 60000 "$RUNNER_TEMP/report/duel.md"
83
+ cat "$text"
65
84
  printf '\n%s\n' "$fence"
66
85
  }
67
86
  marker="<!-- duel<%= " #{working_directory}" if working_directory %>"
@@ -73,3 +92,32 @@ jobs:
73
92
  { echo "$marker status=$STATUS -->"; report; } > "$RUNNER_TEMP/comment.md"
74
93
  gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
75
94
  fi
95
+ <% if accept_label -%>
96
+
97
+ again:
98
+ name: Run Duel again
99
+ if: >-
100
+ github.event_name == 'pull_request_target' && github.event.label.name == '<%= accept_label.gsub("'", "''") %>'
101
+ runs-on: ubuntu-latest
102
+ permissions:
103
+ actions: write # to run the Perf workflow's jobs again
104
+ steps:
105
+ - name: Run Duel again
106
+ env:
107
+ GH_TOKEN: ${{ github.token }}
108
+ GH_REPO: ${{ github.repository }}
109
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
110
+ ACTION: ${{ github.event.action }}
111
+ run: |
112
+ # The newest Perf run of the pull request's head commit, once it's
113
+ # done (one that's running may have read the labels already).
114
+ id=$(gh run list --workflow "Perf<%= " (#{working_directory})" if working_directory %>" --event pull_request --commit "$HEAD_SHA" --limit 1 \
115
+ --json databaseId --jq '.[0].databaseId // empty')
116
+ [ -n "$id" ] || exit 0
117
+ gh run watch "$id" --interval 30 > /dev/null || true
118
+ conclusion=$(gh run view "$id" --json conclusion --jq .conclusion)
119
+ case "$ACTION:$conclusion" in
120
+ labeled:failure) gh run rerun "$id" --failed ;;
121
+ unlabeled:success) gh run rerun "$id" ;;
122
+ esac
123
+ <% end -%>
@@ -47,6 +47,51 @@ jobs:
47
47
  with:
48
48
  fetch-depth: 0 # the baseline comes from history, tags included
49
49
  persist-credentials: false
50
+ # The labels of the pull request (or for a push, of the one that
51
+ # merged it), for c.accept_label in .duel.rb, as a JSON array. They're
52
+ # read as the job runs, and adding the label (or taking it off) runs
53
+ # the job again: see the Perf comment workflow.
54
+ <% if accept_label -%>
55
+ # On a schedule, the last commit since the last release that merged a
56
+ # pull request with the label (ACCEPT_LABEL, as .duel.rb names it):
57
+ # what that slowed down was accepted, so it's compared with instead.
58
+ <% end -%>
59
+ - name: Find the pull request's labels
60
+ id: labels
61
+ if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push'<% if accept_label %> || github.event_name == 'schedule'<% end %>
62
+ continue-on-error: true # (without them, nothing's accepted)
63
+ env:
64
+ GH_TOKEN: ${{ github.token }}
65
+ PR: ${{ github.event.pull_request.number }}
66
+ QUEUED: ${{ github.event.merge_group.head_ref }}
67
+ <% if accept_label -%>
68
+ ACCEPT_LABEL: '<%= accept_label.gsub("'", "''") %>'
69
+ RELEASE_TAGS: "v*"
70
+ <% end -%>
71
+ run: |
72
+ <% if accept_label -%>
73
+ if [ "$GITHUB_EVENT_NAME" = schedule ]; then
74
+ tag=$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null) || exit 0
75
+ since=$(TZ=UTC git log -1 --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd "$tag")
76
+ merged=$(gh pr list --repo "$GITHUB_REPOSITORY" --state merged --label "$ACCEPT_LABEL" --search "merged:>=$since" --limit 1000 \
77
+ --json mergeCommit --jq '.[].mergeCommit.oid')
78
+ accepted=$(git rev-list "$tag..HEAD" | grep -Fx -m 1 -f <(echo "$merged")) || accepted=
79
+ echo "accepted=$accepted" >> "$GITHUB_OUTPUT"
80
+ exit 0
81
+ fi
82
+ <% end -%>
83
+ # (In a merge queue, the last pull request queued, which the queue's
84
+ # branch names: gh-readonly-queue/main/pr-123-<sha>.)
85
+ if [ -n "$QUEUED" ]; then
86
+ PR=${QUEUED##*/pr-}
87
+ PR=${PR%%-*}
88
+ fi
89
+ if [ -n "$PR" ]; then
90
+ labels=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/labels" --jq '[.[].name]')
91
+ else
92
+ labels=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq '[.[0].labels[]?.name]')
93
+ fi
94
+ echo "labels=$labels" >> "$GITHUB_OUTPUT"
50
95
  <% if database == "postgresql" -%>
51
96
  # Each worker starts a PostgreSQL server of its own (duel-postgresql).
52
97
  - run: sudo apt-get install -y postgresql libpq-dev
@@ -69,7 +114,8 @@ jobs:
69
114
  # request targets (or run by hand, the main branch), a merge queue's
70
115
  # base, the commit before a push (or the last commit Duel passed, PASSED, if there is
71
116
  # one: see the Mark the commit passed job), or on a schedule the last
72
- # release, the newest tag before HEAD that RELEASE_TAGS matches. (If
117
+ # release, the newest tag before HEAD that RELEASE_TAGS matches<% if accept_label %>
118
+ # (or ACCEPTED, the last change accepted since then)<% end %>. (If
73
119
  # .duel.rb sets c.main_branch or c.release_tags, set MAIN_BRANCH or
74
120
  # RELEASE_TAGS to match.)
75
121
  - name: Find the baseline's Ruby
@@ -80,13 +126,16 @@ jobs:
80
126
  PASSED: origin/duel/passed<%= "-#{working_directory.tr("/", "-")}" if working_directory %>/${{ github.ref_name }}
81
127
  MAIN_BRANCH: origin/${{ github.base_ref || github.event.repository.default_branch }}
82
128
  RELEASE_TAGS: "v*"
129
+ <% if accept_label -%>
130
+ ACCEPTED: ${{ steps.labels.outputs.accepted }}
131
+ <% end -%>
83
132
  run: |
84
133
  case "$GITHUB_EVENT_NAME" in
85
134
  push)
86
135
  base=$BEFORE
87
136
  if git merge-base --is-ancestor "$PASSED" HEAD 2>/dev/null; then base=$PASSED; fi ;;
88
137
  merge_group) base=$QUEUE_BASE ;;
89
- schedule) base=$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null) || base= ;;
138
+ schedule) base=${ACCEPTED:-$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null)} || base= ;;
90
139
  *) base=$(git merge-base HEAD "$MAIN_BRANCH" 2>/dev/null) || base= ;;
91
140
  esac
92
141
  ruby_of() { git show "$1:./.ruby-version" 2>/dev/null | awk 'NF { print $1; exit }'; }
@@ -125,30 +174,6 @@ jobs:
125
174
  ruby-version: "<%= ruby_version %>"
126
175
  <% end -%>
127
176
  bundler-cache: true
128
- # The labels of the pull request (or for a push, of the one that
129
- # merged it), for c.accept_label in .duel.rb, as a JSON array. They're
130
- # read as the job runs, so after adding the label, run it again.
131
- - name: Find the pull request's labels
132
- id: labels
133
- if: github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'push'
134
- continue-on-error: true # (without them, nothing's accepted)
135
- env:
136
- GH_TOKEN: ${{ github.token }}
137
- PR: ${{ github.event.pull_request.number }}
138
- QUEUED: ${{ github.event.merge_group.head_ref }}
139
- run: |
140
- # (In a merge queue, the last pull request queued, which the queue's
141
- # branch names: gh-readonly-queue/main/pr-123-<sha>.)
142
- if [ -n "$QUEUED" ]; then
143
- PR=${QUEUED##*/pr-}
144
- PR=${PR%%-*}
145
- fi
146
- if [ -n "$PR" ]; then
147
- labels=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/labels" --jq '[.[].name]')
148
- else
149
- labels=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq '[.[0].labels[]?.name]')
150
- fi
151
- echo "labels=$labels" >> "$GITHUB_OUTPUT"
152
177
  # Against the branch it targets for a pull request, the queue's base
153
178
  # for a merge queue, what was there before for a push (or as
154
179
  # c.push_base in .duel.rb says, the last commit Duel passed), and the
@@ -164,6 +189,9 @@ jobs:
164
189
  # with itself, which checks the setup.)
165
190
  DUEL_FORCE: ${{ github.event_name == 'workflow_dispatch' && '1' || '' }}
166
191
  DUEL_LABELS: ${{ steps.labels.outputs.labels }}
192
+ <% if accept_label -%>
193
+ DUEL_ACCEPTED: ${{ steps.labels.outputs.accepted }}
194
+ <% end -%>
167
195
  run: bundle exec duel --markdown "$RUNNER_TEMP/duel/duel.md"
168
196
  # For a pull request, what Duel said, for the Perf comment workflow,
169
197
  # which can't see this job's outputs.
@@ -236,6 +264,13 @@ jobs:
236
264
  passed:
237
265
  name: Mark the commit passed
238
266
  needs: duel
267
+ # One at a time for each branch, so that two runs can't both find no
268
+ # branch and race to make it (a push's run doesn't wait for the one
269
+ # before it). One that's running is never cancelled, and one that's
270
+ # waiting gives way to a newer push's, which moves it further anyway.
271
+ concurrency:
272
+ group: ${{ github.workflow }}-passed-${{ github.ref_name }}
273
+ cancel-in-progress: false
239
274
  if: ${{ !cancelled() && github.event_name == 'push' && needs.duel.outputs.passed == 'true' }}
240
275
  runs-on: ubuntu-latest
241
276
  permissions:
@@ -259,13 +294,16 @@ jobs:
259
294
  done
260
295
  exit 1
261
296
  }
262
- # (Forward: GitHub moves it only where it's behind the push.)
263
- gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null 2>&1 && exit 0
264
- at=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$BRANCH" --jq .object.sha 2>/dev/null) || at=
265
- if [ -z "$at" ]; then
266
- gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null || blocked
267
- exit 0
268
- fi
297
+ # (Forward: GitHub moves it only where it's behind the push. Where
298
+ # there's no branch, and making it fails, it looks once more, as
299
+ # something else may have made it: a push of it, say.)
300
+ for _ in 1 2; do
301
+ gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null 2>&1 && exit 0
302
+ at=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$BRANCH" --jq .object.sha 2>/dev/null) || at=
303
+ [ -n "$at" ] && break
304
+ gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null && exit 0
305
+ done
306
+ [ -n "$at" ] || blocked
269
307
  compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status 2>&1) || case "$compared" in
270
308
  # (GitHub can't compare commits with no history in common.)
271
309
  *"No common ancestor"*) compared=unrelated ;;
data/sig/duel/rails.rbs CHANGED
@@ -242,6 +242,9 @@ module Duel
242
242
  # Whether the workflow marks a push passed.
243
243
  def mark_passed?: () -> bool
244
244
 
245
+ # The label that accepts a regression, for the workflows, or nil.
246
+ def accept_label: () -> String?
247
+
245
248
  # Whether the workflow keeps a badge for the README.
246
249
  def badge?: () -> bool
247
250
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Berlin