duel-rails 0.1.0 → 0.1.2

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: 6bcc25c75b990e312e5fb3a458f5e3eace8b5dbbe02fcb8c50f0ca0df01d8f54
4
- data.tar.gz: a6b29676404b6e35d14321d05f428d902d230d169f084abd65afd7104081fed1
3
+ metadata.gz: 071eed2da6a655fb491f21479c313937875acddc148f87a9c194798492f9f998
4
+ data.tar.gz: fc054a813446a26d4bdc9a4d8206900bb159f29f77da64e9194b5c30e89b69ef
5
5
  SHA512:
6
- metadata.gz: 85ed8cb50f379354f0ba9a5769688fbcc1608bb4ee8dfff8e7586e2f736ed4db193bb99d82c7d76a37b6177175cb010364e60e0e83e6a6aec4fc11539ec30767
7
- data.tar.gz: a514a4ddd962ac4b5c5711ec829ccb14a95d9e46cd1be6fc4a289d0bae2518995e49216f57c15e0e6d321832951f611c49e5db4563a5af580475f573f1fae682
6
+ metadata.gz: 616d941adc922119cc512a5616e7a45a7ca9aa1138215112404d112f4829c45d28d0bb26452c4beb8310d9d789a62d86546b4443eab9076602a4252af710ae22
7
+ data.tar.gz: 48e2327b9da27b1b34f1ce6eacd4a19abf237a7ee9f893b82e5b6cb361d21c7e3644fdb709411c90988c28b3add7a8c12b62f2797346960fcb166db816a451e6
data/CHANGELOG.md CHANGED
@@ -7,6 +7,89 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.2] - 2026-11-02
11
+
12
+ ### Added
13
+
14
+ - The `.duel.rb` that `rails generate duel:install` writes shows Duel's
15
+ new settings: `c.fail_on`, to fail a regression only in a pull
16
+ request, `c.accept_label`, a pull request label that accepts a
17
+ regression, and `c.push_base`, to compare a push with the last commit
18
+ that Duel passed.
19
+ - The workflow that `rails generate duel:install` writes passes a pull
20
+ request's labels to Duel, for `c.accept_label`, comments on a pushed
21
+ commit when only a pull request fails (`c.fail_on`), and with
22
+ `c.push_base = :last_passed`, marks a push passed with a branch of its
23
+ own (`duel/passed/main` for `main`).
24
+ - The workflow runs for a merge queue (`merge_group`), and compares its
25
+ group with the queue's base, so the Duel check can be required with a
26
+ merge queue.
27
+
28
+ ### Changed
29
+
30
+ - To upgrade an app that ran `rails generate duel:install` before 0.1.2,
31
+ run it again, and let it overwrite `.github/workflows/perf.yml` (or
32
+ `perf-<its path>.yml`, for an app in a subdirectory), then carry over
33
+ any edits of your own. Keep your `.duel.rb`. Kept, the old workflow
34
+ comments on a pull request itself, and with the new one, every
35
+ comment comes twice.
36
+ - A pull request gets its comment from a second workflow that the
37
+ generator writes, `.github/workflows/perf-comment.yml` (or
38
+ `perf-<its path>-comment.yml`), which runs once the Perf workflow has
39
+ (`workflow_run`), with a token that can write, so a pull request from
40
+ a fork gets a comment too. It runs none of the pull request's code.
41
+ The Perf workflow no longer has a Comment job, and for an app in a
42
+ subdirectory, it's named for the directory, as `Perf (apps/blog)`.
43
+ - The workflow cancels a pull request's run when a newer push to the
44
+ pull request starts one. Every other run, such as a push's to `main`,
45
+ still runs to the end.
46
+
47
+ ### Fixed
48
+
49
+ - The workflow compares a pull request with the branch that it targets,
50
+ not the main branch. A pull request into a stable branch, or into
51
+ another pull request's branch, was compared with `main`.
52
+
53
+ ## [0.1.1] - 2026-10-26
54
+
55
+ ### Changed
56
+
57
+ - The workflow that `rails generate duel:install` writes no longer
58
+ comments on every pull request. By default, it comments only when a
59
+ benchmark fails or Duel couldn't compare, and `c.comment` in
60
+ `.duel.rb` chooses otherwise (`:always` for the old behavior,
61
+ `:results`, or `:never`). The generated `.duel.rb` shows the setting.
62
+ - The workflow never edits a comment. It used to update one comment on
63
+ every push, and now posts a new one each time it comments, so the pull
64
+ request keeps every report. When a run wouldn't get a comment of its
65
+ own, the workflow still posts one if its last comment on the pull
66
+ request had another status, so after a failure the first run that
67
+ passes says so.
68
+
69
+ ### Security
70
+
71
+ - The workflow that `rails generate duel:install` writes no longer gives
72
+ the job that runs a pull request's code the `pull-requests: write`
73
+ permission. The Duel job only reads (`contents: read`, and its
74
+ checkout keeps no credentials), and keeps the report as an artifact
75
+ for a day. A Comment job of its own, which checks nothing out and runs
76
+ none of the app's code, downloads the report and comments with it, for
77
+ a pull request from the same repository.
78
+
79
+ ### Fixed
80
+
81
+ - With `c.ruby = :version_file`, the workflow installs the bundle for
82
+ the baseline's Ruby too, when it differs from the candidate's. The
83
+ baseline's workers load that bundle, and gems installed for one Ruby
84
+ version don't load on another, so a branch that changed the Ruby's
85
+ minor version failed before it compared anything.
86
+
87
+ - With a `.ruby-version`, the generated workflow installs the baseline's
88
+ Ruby for every event that compares, not only for a pull request: the
89
+ commit before a push, the last release on a schedule, and where HEAD
90
+ left the main branch for a pull request and a manual run, when its
91
+ `.ruby-version` names another Ruby than HEAD's.
92
+
10
93
  ## [0.1.0] - 2026-10-24
11
94
 
12
95
  The first release. duel-rails is a Duel plugin for Rails apps, open
@@ -95,5 +178,7 @@ Rails 7.2 or later, and Ruby 3.4 or later.
95
178
  CI.
96
179
  - RBS signatures in sig/, checked with Steep.
97
180
 
98
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.0...HEAD
181
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.2...HEAD
182
+ [0.1.2]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.1...duel-rails-v0.1.2
183
+ [0.1.1]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.0...duel-rails-v0.1.1
99
184
  [0.1.0]: https://github.com/sferik/duel-ruby/releases/tag/duel-rails-v0.1.0
data/README.md CHANGED
@@ -68,7 +68,8 @@ production does, with everything of its own:
68
68
  | `config/environments/benchmark.rb` | The environment that each version boots in, based on production. |
69
69
  | `duel/requests_duel.rb` | A benchmark of each of your app's first 10 routes that a GET reaches without parameters. |
70
70
  | `duel/boot_duel.rb` | A benchmark of your app's boot. See [Benchmark your app's boot](#benchmark-your-apps-boot). |
71
- | `.github/workflows/perf.yml` | A GitHub Actions workflow that runs Duel on pull requests, on pushes to `main`, and nightly against your last release, and comments on each pull request with Duel's report, updating one comment on every push. See [Report on a pull request](https://github.com/sferik/duel-ruby#report-on-a-pull-request). For an app in a subdirectory of its repository, the workflow is at the repository's root. See [An app in a monorepo](#an-app-in-a-monorepo). |
71
+ | `.github/workflows/perf.yml` | A GitHub Actions workflow that runs Duel on pull requests, on pushes to `main`, and nightly against your last release, and has the second workflow comment on a pull request with Duel's report when a benchmark fails. It never edits a comment, and after a failure, posts one more when a run passes. To comment on every run, or never, set `c.comment` in `.duel.rb`: see [Choose when to comment on a pull request](https://github.com/sferik/duel-ruby/blob/main/docs/configuration.md#choose-when-to-comment-on-a-pull-request) and [Report on a pull request](https://github.com/sferik/duel-ruby#report-on-a-pull-request). For an app in a subdirectory of its repository, the workflow is at the repository's root. See [An app in a monorepo](#an-app-in-a-monorepo). |
72
+ | `.github/workflows/perf-comment.yml` | A second workflow, which comments on a pull request with the report once the first has run, with a token that can write, so a pull request from a fork gets a comment too. It runs none of the pull request's code. See [Comment on a pull request](https://github.com/sferik/duel-ruby/blob/main/docs/ci.md#comment-on-a-pull-request). |
72
73
 
73
74
  The generator also adds `gem "stackprof", platforms: :mri` to your
74
75
  `Gemfile`'s `development` group, unless it has StackProf already, so
@@ -326,8 +327,9 @@ Each Ruby must be installed where Duel finds it: with rbenv, chruby,
326
327
  mise, or asdf, or as the Ruby that runs Duel. For more information, see
327
328
  Duel's [Run each version on its own Ruby](https://github.com/sferik/duel-ruby/blob/main/docs/configuration.md#run-each-version-on-its-own-ruby).
328
329
  On GitHub Actions, the generated workflow installs your app's Ruby, and,
329
- for a pull request, also the main branch's, so a pull request that
330
- upgrades Ruby works there too.
330
+ when the baseline's `.ruby-version` names another Ruby, that one too, so
331
+ a pull request, a push, or a nightly run against your last release
332
+ works there when your app upgrades Ruby.
331
333
 
332
334
  To run both versions on the Ruby that runs Duel, remove
333
335
  `c.ruby = :version_file`.
@@ -428,7 +430,9 @@ end
428
430
  ```
429
431
 
430
432
  duel-rails also tells Duel to compare a change to `app/`, `config/`,
431
- `db/`, `lib/`, `Gemfile`, `Gemfile.lock`, or `.ruby-version`.
433
+ `db/`, `lib/`, `Gemfile`, `Gemfile.lock`, or `.ruby-version`, as well
434
+ as one to your benchmarks (`duel/`) or `.duel.rb`, which Duel always
435
+ watches.
432
436
 
433
437
  ## An app in a monorepo
434
438
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Rails
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -43,13 +43,16 @@ module Duel
43
43
 
44
44
  def create_boot_benchmark = template("boot_duel.rb.tt", "duel/boot_duel.rb")
45
45
 
46
- # The workflow, at the repository's root: perf.yml, or, for an app in
47
- # a subdirectory, perf-<its path>.yml (perf-apps-blog.yml), so that
48
- # each of a monorepo's apps can have its own.
46
+ # The workflows, at the repository's root: perf.yml, and
47
+ # perf-comment.yml, which comments on a pull request with the
48
+ # report, or, for an app in a subdirectory, perf-<its path>.yml
49
+ # (perf-apps-blog.yml) and perf-<its path>-comment.yml, so that each
50
+ # of a monorepo's apps can have its own.
49
51
  def create_workflow
50
52
  dir = working_directory
51
- name = dir ? "perf-#{dir.tr("/", "-")}.yml" : "perf.yml"
52
- template("perf.yml.tt", File.join(repository, ".github", "workflows", name))
53
+ name = dir ? "perf-#{dir.tr("/", "-")}" : "perf"
54
+ template("perf.yml.tt", File.join(repository, ".github", "workflows", "#{name}.yml"))
55
+ template("perf-comment.yml.tt", File.join(repository, ".github", "workflows", "#{name}-comment.yml"))
53
56
  end
54
57
 
55
58
  # The plugin that gives each worker its database's server.
@@ -20,4 +20,22 @@ Duel.configure do |c|
20
20
  # fixtures: :all, or seeds: true.
21
21
  c.use :rails, database: <%= database ? ":#{database}" : "nil" %>
22
22
  <% end -%>
23
+
24
+ # When the workflow comments on a pull request with the report: :always,
25
+ # :results (passed or failed), :failures (failed, or couldn't compare),
26
+ # or :never.
27
+ # c.comment = :failures
28
+
29
+ # Which runs a regression fails: :every_run, or :pull_requests, for a
30
+ # project where people push to main directly (on GitHub Actions, another
31
+ # run warns and passes, and a pushed commit gets the comment instead).
32
+ # c.fail_on = :every_run
33
+
34
+ # A label that accepts a regression in a pull request (nil for none).
35
+ # c.accept_label = "duel: accept"
36
+
37
+ # What the workflow compares a push with: :before (the commit before it),
38
+ # or :last_passed (the last commit Duel passed, which a branch,
39
+ # duel/passed/main, marks), so small slowdowns add up until they fail.
40
+ # c.push_base = :before
23
41
  end
@@ -0,0 +1,59 @@
1
+ name: Perf comment<%= " (#{working_directory})" if working_directory %>
2
+
3
+ # Duel's report, as a new comment on the pull request, when Duel says to:
4
+ # always (post), or only when its last comment's status differs from the
5
+ # run's (change), so the latest comment is never stale. It never edits or
6
+ # deletes a comment. It runs once the Perf workflow has, with this
7
+ # repository's own workflow and a token that can write, so a pull request
8
+ # from a fork gets a comment too. It checks nothing out and runs none of
9
+ # the pull request's code, and of what the Duel job kept (where that code
10
+ # ran), it trusts only what that job could have said: the pull request's
11
+ # number, if it names the pull request the run compared, and the comment
12
+ # and the status, if they're ones Duel says. (The workflow must be on the
13
+ # default branch before it runs at all.)
14
+ on:
15
+ workflow_run:
16
+ workflows: ["Perf<%= " (#{working_directory})" if working_directory %>"]
17
+ types: [completed]
18
+
19
+ permissions: {}
20
+
21
+ jobs:
22
+ comment:
23
+ name: Comment
24
+ if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'cancelled' }}
25
+ runs-on: ubuntu-latest
26
+ permissions:
27
+ actions: read # to get the report from the Perf run
28
+ pull-requests: write # to comment on the pull request with the report
29
+ steps:
30
+ - name: Get the report
31
+ id: report
32
+ continue-on-error: true # there's none when the Duel job failed before comparing
33
+ uses: actions/download-artifact@v8
34
+ with:
35
+ name: duel-report
36
+ path: ${{ runner.temp }}/report
37
+ run-id: ${{ github.event.workflow_run.id }}
38
+ github-token: ${{ github.token }}
39
+ - name: Comment on the pull request
40
+ if: steps.report.outcome == 'success'
41
+ env:
42
+ GH_TOKEN: ${{ github.token }}
43
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
44
+ run: |
45
+ said() { grep -xE "$1=($2)" "$RUNNER_TEMP/report/comment.env" | tail -n 1 | cut -d= -f2; }
46
+ PR=$(said pr '[0-9]+')
47
+ COMMENT=$(said comment 'post|change')
48
+ STATUS=$(said status 'passed|failed|neutral')
49
+ [ -n "$PR" ] && [ -n "$COMMENT" ] && [ -n "$STATUS" ] || exit 0
50
+ [ "$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq .head.sha)" = "$HEAD_SHA" ] || exit 0
51
+ marker="<!-- duel<%= " #{working_directory}" if working_directory %>"
52
+ # The first line of the last comment Duel posted here: its marker,
53
+ # with its status (none in Duel 0.1.0's, which counts as another).
54
+ last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
55
+ --jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\") or . == \"$marker -->\")" | tail -n 1)
56
+ if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
57
+ { echo "$marker status=$STATUS -->"; cat "$RUNNER_TEMP/report/duel.md"; } > "$RUNNER_TEMP/comment.md"
58
+ gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
59
+ fi
@@ -1,21 +1,40 @@
1
- name: Perf
1
+ name: Perf<%= " (#{working_directory})" if working_directory %>
2
2
 
3
3
  on:
4
4
  pull_request:
5
+ merge_group: # (a merge queue's)
5
6
  push:
6
- branches: [main]
7
+ branches: [main] # (and any other branch to guard, a stable one, say)
7
8
  schedule:
8
9
  - cron: "0 4 * * *"
9
10
  workflow_dispatch:
10
11
 
12
+ # A pull request's newer push cancels its run, if that's still going, as
13
+ # only its newest commit's result counts. Every other run (a push's, say)
14
+ # runs to the end, so that each push is compared.
15
+ concurrency:
16
+ group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
17
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
18
+
19
+ # The Duel job runs the branch's code (its benchmarks too), so it only
20
+ # reads. Commenting on a commit is the Comment on the commit job's, which
21
+ # runs none of it, and commenting on a pull request is the Perf comment
22
+ # workflow's.
11
23
  permissions:
12
24
  contents: read
13
- pull-requests: write # to comment on a pull request with the report
25
+ pull-requests: read # for the pull request's labels (see c.accept_label)
14
26
 
15
27
  jobs:
16
28
  duel:
17
29
  name: Duel
18
30
  runs-on: ubuntu-latest
31
+ # Whether to comment (post, change or none), the run's status (passed,
32
+ # failed or neutral), and whether to mark a push passed (true, or
33
+ # nothing), from Duel.
34
+ outputs:
35
+ comment: ${{ steps.compare.outputs.comment }}
36
+ status: ${{ steps.compare.outputs.status }}
37
+ passed: ${{ steps.compare.outputs.passed }}
19
38
  <% if working_directory -%>
20
39
  # The app is in a subdirectory of the repository: Duel runs there, and
21
40
  # checks out the whole repository for the baseline.
@@ -27,6 +46,7 @@ jobs:
27
46
  - uses: actions/checkout@v7
28
47
  with:
29
48
  fetch-depth: 0 # the baseline comes from history, tags included
49
+ persist-credentials: false
30
50
  <% if database == "postgresql" -%>
31
51
  # Each worker starts a PostgreSQL server of its own (duel-postgresql).
32
52
  - run: sudo apt-get install -y postgresql libpq-dev
@@ -42,24 +62,59 @@ jobs:
42
62
  <% end -%>
43
63
  <% if version_file? -%>
44
64
  # Each version runs on the Ruby its own .ruby-version names (see
45
- # .duel.rb): for a pull request that upgrades Ruby, the main branch's
46
- # too, linked where Duel finds it (as chruby would). It's set up
47
- # before the app's own Ruby, which runs Duel.
65
+ # .duel.rb). When the baseline's names another Ruby than this code's,
66
+ # that one is installed too, and linked where Duel finds it (as
67
+ # chruby would), before the app's own Ruby, which runs Duel. The
68
+ # baseline is the Compare step's: where HEAD left the branch a pull
69
+ # request targets (or run by hand, the main branch), a merge queue's
70
+ # base, the commit before a push (or the last commit Duel passed, PASSED, if there is
71
+ # 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
73
+ # .duel.rb sets c.main_branch or c.release_tags, set MAIN_BRANCH or
74
+ # RELEASE_TAGS to match.)
48
75
  - name: Find the baseline's Ruby
49
76
  id: baseline
50
- if: github.event_name == 'pull_request'
51
- run: echo "ruby=$(git show "origin/$GITHUB_BASE_REF:./.ruby-version" 2>/dev/null)" >> "$GITHUB_OUTPUT"
77
+ env:
78
+ BEFORE: ${{ github.event.before }}
79
+ QUEUE_BASE: ${{ github.event.merge_group.base_sha }}
80
+ PASSED: origin/duel/passed<%= "-#{working_directory.tr("/", "-")}" if working_directory %>/${{ github.ref_name }}
81
+ MAIN_BRANCH: origin/${{ github.base_ref || github.event.repository.default_branch }}
82
+ RELEASE_TAGS: "v*"
83
+ run: |
84
+ case "$GITHUB_EVENT_NAME" in
85
+ push)
86
+ base=$BEFORE
87
+ if git merge-base --is-ancestor "$PASSED" HEAD 2>/dev/null; then base=$PASSED; fi ;;
88
+ merge_group) base=$QUEUE_BASE ;;
89
+ schedule) base=$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null) || base= ;;
90
+ *) base=$(git merge-base HEAD "$MAIN_BRANCH" 2>/dev/null) || base= ;;
91
+ esac
92
+ ruby_of() { git show "$1:./.ruby-version" 2>/dev/null | awk 'NF { print $1; exit }'; }
93
+ ruby=
94
+ # (None without a baseline: a branch's first push, or no release yet.)
95
+ if [ -n "$base" ] && git cat-file -e "$base^{commit}" 2>/dev/null; then
96
+ ruby=$(ruby_of "$base")
97
+ [ "$ruby" = "$(ruby_of HEAD)" ] && ruby=
98
+ fi
99
+ echo "ruby=$ruby" >> "$GITHUB_OUTPUT"
52
100
  - uses: ruby/setup-ruby@v1
53
101
  id: baseline-ruby
54
102
  if: steps.baseline.outputs.ruby != ''
55
103
  with:
104
+ <% if working_directory -%>
105
+ working-directory: <%= working_directory %>
106
+ <% end -%>
56
107
  ruby-version: ${{ steps.baseline.outputs.ruby }}
108
+ # The bundle for this Ruby too, which the baseline's workers load.
109
+ # (Gems installed for one Ruby version don't load on another.)
110
+ bundler-cache: true
57
111
  - name: Link the baseline's Ruby where Duel finds it
58
112
  if: steps.baseline.outputs.ruby != ''
113
+ env:
114
+ PREFIX: ${{ steps.baseline-ruby.outputs.ruby-prefix }}
59
115
  run: |
60
- prefix="${{ steps.baseline-ruby.outputs.ruby-prefix }}"
61
116
  mkdir -p ~/.rubies
62
- ln -sfn "$prefix" ~/.rubies/ruby-"$("$prefix/bin/ruby" -e 'print RUBY_VERSION')"
117
+ ln -sfn "$PREFIX" ~/.rubies/ruby-"$("$PREFIX/bin/ruby" -e 'print RUBY_VERSION')"
63
118
  <% end -%>
64
119
  - uses: ruby/setup-ruby@v1
65
120
  with:
@@ -70,40 +125,122 @@ jobs:
70
125
  ruby-version: "<%= ruby_version %>"
71
126
  <% end -%>
72
127
  bundler-cache: true
73
- # Against the main branch for a pull request, what was there before
74
- # for a push, and the last release on a schedule (slow creep). Duel
75
- # adds its report to the job's summary, and writes it to duel.md for
76
- # the comment.
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
+ # Against the branch it targets for a pull request, the queue's base
153
+ # for a merge queue, what was there before for a push (or as
154
+ # c.push_base in .duel.rb says, the last commit Duel passed), and the
155
+ # last release on a schedule (slow creep). Duel adds its report to
156
+ # the job's summary, writes it to duel.md for the comment, and sets
157
+ # the step's outputs to say whether to comment, as c.comment in
158
+ # .duel.rb says, whatever the outcome.
77
159
  - name: Compare
160
+ id: compare
78
161
  env:
79
- DUEL_BASE: ${{ github.event_name == 'schedule' && 'last-release' || github.event_name == 'push' && github.event.before || '' }}
162
+ 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 || '' }}
80
163
  # (Run by hand, it compares anyway: with nothing changed, the code
81
164
  # with itself, which checks the setup.)
82
165
  DUEL_FORCE: ${{ github.event_name == 'workflow_dispatch' && '1' || '' }}
166
+ DUEL_LABELS: ${{ steps.labels.outputs.labels }}
167
+ run: bundle exec duel --markdown "$RUNNER_TEMP/duel/duel.md"
168
+ # For a pull request, what Duel said, for the Perf comment workflow,
169
+ # which can't see this job's outputs.
170
+ - name: Say whether to comment
171
+ if: ${{ !cancelled() && github.event_name == 'pull_request' }}
172
+ env:
173
+ PR: ${{ github.event.pull_request.number }}
174
+ COMMENT: ${{ steps.compare.outputs.comment }}
175
+ STATUS: ${{ steps.compare.outputs.status }}
83
176
  run: |
84
- # (A branch's first push, or one that rewrote history, has no
85
- # commit before it here to compare against.)
86
- if [ "$GITHUB_EVENT_NAME" = push ] && ! git cat-file -e "$DUEL_BASE^{commit}" 2>/dev/null; then
87
- echo "::notice::No commit before this push to compare against"
88
- exit 0
89
- fi
90
- bundle exec duel --markdown "$RUNNER_TEMP/duel.md"
91
- # The report, as a comment on the pull request: one comment, updated
92
- # on every push. (A pull request from a fork gets no comment, as its
93
- # token can't write one: the job's summary has the report.)
94
- - name: Comment on the pull request
95
- if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
177
+ mkdir -p "$RUNNER_TEMP/duel"
178
+ printf 'pr=%s\ncomment=%s\nstatus=%s\n' "$PR" "$COMMENT" "$STATUS" > "$RUNNER_TEMP/duel/comment.env"
179
+ # The report, for the comments.
180
+ - name: Keep the report
181
+ if: ${{ !cancelled() && (github.event_name == 'pull_request' || github.event_name == 'push') }}
182
+ uses: actions/upload-artifact@v7
183
+ with:
184
+ name: duel-report
185
+ path: ${{ runner.temp }}/duel/
186
+ if-no-files-found: ignore # none when Duel didn't get to compare
187
+ retention-days: 1
188
+
189
+ # The report, as a new comment on a pushed commit, which notifies its
190
+ # author, when Duel says to, as for a pull request (see the Perf comment
191
+ # workflow). It does only where a regression in a push passes, with
192
+ # c.fail_on = :pull_requests in .duel.rb, so the comment says what the
193
+ # check doesn't. Its last comment is the last one on any commit. This
194
+ # job checks nothing out and runs none of the code.
195
+ commit-comment:
196
+ name: Comment on the commit
197
+ needs: duel
198
+ if: ${{ !cancelled() && github.event_name == 'push' && (needs.duel.outputs.comment == 'post' || needs.duel.outputs.comment == 'change') }}
199
+ runs-on: ubuntu-latest
200
+ permissions:
201
+ contents: write # to comment on the commit with the report
202
+ steps:
203
+ - name: Get the report
204
+ id: report
205
+ continue-on-error: true # there's none when the Duel job failed before comparing
206
+ uses: actions/download-artifact@v8
207
+ with:
208
+ name: duel-report
209
+ path: ${{ runner.temp }}/report
210
+ - name: Comment on the commit
211
+ if: steps.report.outcome == 'success'
96
212
  env:
97
213
  GH_TOKEN: ${{ github.token }}
98
- PR: ${{ github.event.pull_request.number }}
214
+ COMMENT: ${{ needs.duel.outputs.comment }}
215
+ STATUS: ${{ needs.duel.outputs.status }}
99
216
  run: |
100
- [ -f "$RUNNER_TEMP/duel.md" ] || exit 0
101
- marker="<!-- duel<%= " #{working_directory}" if working_directory %> -->"
102
- { echo "$marker"; cat "$RUNNER_TEMP/duel.md"; } > "$RUNNER_TEMP/comment.md"
103
- ids=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
104
- --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id")
105
- if [ -n "$ids" ]; then
106
- gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/${ids%%$'\n'*}" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
107
- else
108
- gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
217
+ marker="<!-- duel<%= " #{working_directory}" if working_directory %>"
218
+ last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/comments" \
219
+ --jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\"))" | tail -n 1)
220
+ if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
221
+ { echo "$marker status=$STATUS -->"; cat "$RUNNER_TEMP/report/duel.md"; } > "$RUNNER_TEMP/comment.md"
222
+ gh api --method POST "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
109
223
  fi
224
+
225
+ # With c.push_base = :last_passed in .duel.rb, a push is compared with
226
+ # the last commit Duel passed, which a branch marks (each branch pushed
227
+ # has its own), so slowdowns too small for any one push to fail add up
228
+ # until they fail one. This job moves the branch to a push that passed
229
+ # (or makes it). It checks nothing out and runs none of the code. To
230
+ # accept a regression, move the branch yourself (for main, git push
231
+ # origin main:duel/passed<%= "-#{working_directory.tr("/", "-")}" if working_directory %>/main).
232
+ passed:
233
+ name: Mark the commit passed
234
+ needs: duel
235
+ if: ${{ !cancelled() && github.event_name == 'push' && needs.duel.outputs.passed == 'true' }}
236
+ runs-on: ubuntu-latest
237
+ permissions:
238
+ contents: write # to move the branch
239
+ steps:
240
+ - name: Move the branch to the commit
241
+ env:
242
+ GH_TOKEN: ${{ github.token }}
243
+ BRANCH: duel/passed<%= "-#{working_directory.tr("/", "-")}" if working_directory %>/${{ github.ref_name }}
244
+ run: |
245
+ gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null 2>&1 ||
246
+ gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Berlin
@@ -75,6 +75,7 @@ files:
75
75
  - lib/generators/duel/install/templates/benchmark.rb.tt
76
76
  - lib/generators/duel/install/templates/boot_duel.rb.tt
77
77
  - lib/generators/duel/install/templates/duel.rb.tt
78
+ - lib/generators/duel/install/templates/perf-comment.yml.tt
78
79
  - lib/generators/duel/install/templates/perf.yml.tt
79
80
  - lib/generators/duel/install/templates/requests_duel.rb.tt
80
81
  - sig/duel/rails.rbs