duel-rails 0.1.1 → 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: 4e5ae40fccca2ac222b0b74531bf35a79df8e05555f58210c966c505f13800a6
4
- data.tar.gz: 166a8ea74a1000fdb64f859475bab318b9f9c31aa60e0e78837f49369dc184dd
3
+ metadata.gz: 071eed2da6a655fb491f21479c313937875acddc148f87a9c194798492f9f998
4
+ data.tar.gz: fc054a813446a26d4bdc9a4d8206900bb159f29f77da64e9194b5c30e89b69ef
5
5
  SHA512:
6
- metadata.gz: e5c8ef296bf6e55639b68f90e76ecee308bc4c054e9c3c2f19351e9a5a7568f76ab597399ccc9d1b58bf67762db264ebb47fe6a5f2e80bd256f72880ba1be8dd
7
- data.tar.gz: 3c9c0b98b9e589de2da84e9f9fbea1b0182a956f273adca6437a44870df91645f24f69e1af0d77f8c4ca917539f230b39ac619b48fc12263daed473565cc0ce8
6
+ metadata.gz: 616d941adc922119cc512a5616e7a45a7ca9aa1138215112404d112f4829c45d28d0bb26452c4beb8310d9d789a62d86546b4443eab9076602a4252af710ae22
7
+ data.tar.gz: 48e2327b9da27b1b34f1ce6eacd4a19abf237a7ee9f893b82e5b6cb361d21c7e3644fdb709411c90988c28b3add7a8c12b62f2797346960fcb166db816a451e6
data/CHANGELOG.md CHANGED
@@ -7,6 +7,49 @@ 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
+
10
53
  ## [0.1.1] - 2026-10-26
11
54
 
12
55
  ### Changed
@@ -135,6 +178,7 @@ Rails 7.2 or later, and Ruby 3.4 or later.
135
178
  CI.
136
179
  - RBS signatures in sig/, checked with Steep.
137
180
 
138
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.1...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
139
183
  [0.1.1]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.0...duel-rails-v0.1.1
140
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 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). |
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Rails
5
- VERSION = "0.1.1"
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.
@@ -25,4 +25,17 @@ Duel.configure do |c|
25
25
  # :results (passed or failed), :failures (failed, or couldn't compare),
26
26
  # or :never.
27
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
28
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,27 +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
+
11
19
  # The Duel job runs the branch's code (its benchmarks too), so it only
12
- # reads. Commenting is the Comment job's, which runs none of it.
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.
13
23
  permissions:
14
24
  contents: read
25
+ pull-requests: read # for the pull request's labels (see c.accept_label)
15
26
 
16
27
  jobs:
17
28
  duel:
18
29
  name: Duel
19
30
  runs-on: ubuntu-latest
20
- # Whether the Comment job comments (post, change or none), and the
21
- # run's status (passed, failed or neutral), from Duel.
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.
22
34
  outputs:
23
35
  comment: ${{ steps.compare.outputs.comment }}
24
36
  status: ${{ steps.compare.outputs.status }}
37
+ passed: ${{ steps.compare.outputs.passed }}
25
38
  <% if working_directory -%>
26
39
  # The app is in a subdirectory of the repository: Duel runs there, and
27
40
  # checks out the whole repository for the baseline.
@@ -52,20 +65,27 @@ jobs:
52
65
  # .duel.rb). When the baseline's names another Ruby than this code's,
53
66
  # that one is installed too, and linked where Duel finds it (as
54
67
  # chruby would), before the app's own Ruby, which runs Duel. The
55
- # baseline is the Compare step's: where HEAD left the main branch
56
- # (for a pull request, and run by hand), the commit before a push, or
57
- # on a schedule the last release, the newest tag before HEAD that
58
- # RELEASE_TAGS matches. (If .duel.rb sets c.main_branch or
59
- # c.release_tags, set MAIN_BRANCH or RELEASE_TAGS to match.)
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.)
60
75
  - name: Find the baseline's Ruby
61
76
  id: baseline
62
77
  env:
63
78
  BEFORE: ${{ github.event.before }}
64
- MAIN_BRANCH: origin/${{ github.event.repository.default_branch }}
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 }}
65
82
  RELEASE_TAGS: "v*"
66
83
  run: |
67
84
  case "$GITHUB_EVENT_NAME" in
68
- push) base=$BEFORE ;;
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 ;;
69
89
  schedule) base=$(git describe --tags --abbrev=0 --match "$RELEASE_TAGS" HEAD^ 2>/dev/null) || base= ;;
70
90
  *) base=$(git merge-base HEAD "$MAIN_BRANCH" 2>/dev/null) || base= ;;
71
91
  esac
@@ -105,50 +125,80 @@ jobs:
105
125
  ruby-version: "<%= ruby_version %>"
106
126
  <% end -%>
107
127
  bundler-cache: true
108
- # Against the main branch for a pull request, what was there before
109
- # for a push, and the last release on a schedule (slow creep). Duel
110
- # adds its report to the job's summary, writes it to duel.md for the
111
- # comment, and sets the step's outputs to say whether to comment, as
112
- # c.comment in .duel.rb says, whatever the outcome.
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.
113
159
  - name: Compare
114
160
  id: compare
115
161
  env:
116
- 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 || '' }}
117
163
  # (Run by hand, it compares anyway: with nothing changed, the code
118
164
  # with itself, which checks the setup.)
119
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 }}
120
176
  run: |
121
- # (A branch's first push, or one that rewrote history, has no
122
- # commit before it here to compare against.)
123
- if [ "$GITHUB_EVENT_NAME" = push ] && ! git cat-file -e "$DUEL_BASE^{commit}" 2>/dev/null; then
124
- echo "::notice::No commit before this push to compare against"
125
- exit 0
126
- fi
127
- bundle exec duel --markdown "$RUNNER_TEMP/duel.md"
128
- # The report, for the Comment job.
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.
129
180
  - name: Keep the report
130
- if: ${{ !cancelled() && github.event_name == 'pull_request' }}
181
+ if: ${{ !cancelled() && (github.event_name == 'pull_request' || github.event_name == 'push') }}
131
182
  uses: actions/upload-artifact@v7
132
183
  with:
133
184
  name: duel-report
134
- path: ${{ runner.temp }}/duel.md
185
+ path: ${{ runner.temp }}/duel/
135
186
  if-no-files-found: ignore # none when Duel didn't get to compare
136
187
  retention-days: 1
137
188
 
138
- # The report, as a new comment on the pull request, when Duel says to:
139
- # always (post), or only when its last comment's status differs from
140
- # this run's (change), so the latest comment is never stale. It never
141
- # edits or deletes a comment. This job checks nothing out and runs none
142
- # of the branch's code, so it alone can write. (A pull request from a
143
- # fork gets no comment, as its token can't write one: the Duel job's
144
- # summary has the report.)
145
- comment:
146
- name: Comment
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
147
197
  needs: duel
148
- if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && (needs.duel.outputs.comment == 'post' || needs.duel.outputs.comment == 'change') }}
198
+ if: ${{ !cancelled() && github.event_name == 'push' && (needs.duel.outputs.comment == 'post' || needs.duel.outputs.comment == 'change') }}
149
199
  runs-on: ubuntu-latest
150
200
  permissions:
151
- pull-requests: write # to comment on the pull request with the report
201
+ contents: write # to comment on the commit with the report
152
202
  steps:
153
203
  - name: Get the report
154
204
  id: report
@@ -157,20 +207,40 @@ jobs:
157
207
  with:
158
208
  name: duel-report
159
209
  path: ${{ runner.temp }}/report
160
- - name: Comment on the pull request
210
+ - name: Comment on the commit
161
211
  if: steps.report.outcome == 'success'
162
212
  env:
163
213
  GH_TOKEN: ${{ github.token }}
164
- PR: ${{ github.event.pull_request.number }}
165
214
  COMMENT: ${{ needs.duel.outputs.comment }}
166
215
  STATUS: ${{ needs.duel.outputs.status }}
167
216
  run: |
168
217
  marker="<!-- duel<%= " #{working_directory}" if working_directory %>"
169
- # The first line of the last comment Duel posted here: its marker,
170
- # with its status (none in Duel 0.1.0's, which counts as another).
171
- last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
172
- --jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\") or . == \"$marker -->\")" | tail -n 1)
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)
173
220
  if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
174
221
  { echo "$marker status=$STATUS -->"; cat "$RUNNER_TEMP/report/duel.md"; } > "$RUNNER_TEMP/comment.md"
175
- gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
222
+ gh api --method POST "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
176
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.1
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