duel-rails 0.1.6 → 0.1.8
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/CHANGELOG.md +22 -1
- data/README.md +3 -1
- data/lib/duel/rails/version.rb +1 -1
- data/lib/generators/duel/install/install_generator.rb +61 -14
- data/lib/generators/duel/install/templates/perf-comment.yml.tt +17 -42
- data/lib/generators/duel/install/templates/perf.yml.tt +14 -9
- data/sig/duel/rails.rbs +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d979498ecebfdd28819166ca2213526b2f896d884768ce83d3b587af03a5897
|
|
4
|
+
data.tar.gz: 9aadce2e4a34cc790028f25e4494f6090734d40bb51446591ca1c7200c2d4e80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7ef4f7fc60b8bae95e87ada152590579dd3dd60a46b7606dd3f894391523e3ea1cb00d4c59de0587791989276c9cf3eb85d0a0c2044f91240aac043d34cef017
|
|
7
|
+
data.tar.gz: c3ea9ee90b33743ec21716e70fe30819a93b16f8eb2ef0f1d0614f5cf7e11941ab8424846a7754b1926aedec5d603cb414a90d35d608062d2454f732a67cc5a0
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.8] - 2026-11-12
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `bin/rails generate duel:install --check` says how the app's
|
|
15
|
+
workflows differ from what the generator writes, as a diff, writes
|
|
16
|
+
nothing, and exits with 1 where one does.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- The generator's comment workflow is Duel's: it posts a report from a
|
|
21
|
+
fork's pull request as Markdown, like any other, instead of as text in
|
|
22
|
+
a code block, and runs `duel comment`, from RubyGems, which also hides
|
|
23
|
+
Duel's earlier comments as outdated.
|
|
24
|
+
|
|
25
|
+
## [0.1.7] - 2026-11-10
|
|
26
|
+
|
|
27
|
+
No changes of its own: released in step with the other Duel gems.
|
|
28
|
+
|
|
10
29
|
## [0.1.6] - 2026-11-10
|
|
11
30
|
|
|
12
31
|
### Added
|
|
@@ -250,7 +269,9 @@ Rails 7.2 or later, and Ruby 3.4 or later.
|
|
|
250
269
|
CI.
|
|
251
270
|
- RBS signatures in sig/, checked with Steep.
|
|
252
271
|
|
|
253
|
-
[Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.
|
|
272
|
+
[Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.8...HEAD
|
|
273
|
+
[0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.7...duel-rails-v0.1.8
|
|
274
|
+
[0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.6...duel-rails-v0.1.7
|
|
254
275
|
[0.1.6]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.5...duel-rails-v0.1.6
|
|
255
276
|
[0.1.5]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.4...duel-rails-v0.1.5
|
|
256
277
|
[0.1.4]: https://github.com/sferik/duel-ruby/compare/duel-rails-v0.1.3...duel-rails-v0.1.4
|
data/README.md
CHANGED
|
@@ -80,7 +80,9 @@ production does, with everything of its own:
|
|
|
80
80
|
[duel-mysql](https://github.com/sferik/duel-ruby/tree/main/plugins/mysql) too.
|
|
81
81
|
Run `bundle install` again.
|
|
82
82
|
|
|
83
|
-
4. Review the generated files, and commit them.
|
|
83
|
+
4. Review the generated files, and commit them. After you upgrade
|
|
84
|
+
duel-rails, `bin/rails generate duel:install --check` shows how your
|
|
85
|
+
workflows differ from what it writes now, and writes nothing.
|
|
84
86
|
|
|
85
87
|
5. Run the benchmarks against your main branch:
|
|
86
88
|
|
data/lib/duel/rails/version.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "erb"
|
|
3
4
|
require "open3"
|
|
4
5
|
require "pathname"
|
|
5
6
|
require "rails/generators"
|
|
@@ -22,6 +23,8 @@ module Duel
|
|
|
22
23
|
desc: "Each worker's database (default: as the app's own)"
|
|
23
24
|
class_option :badge, type: :boolean, default: false,
|
|
24
25
|
desc: "Write a job that keeps a badge for the README (it needs contents: write)"
|
|
26
|
+
class_option :check, type: :boolean, default: false,
|
|
27
|
+
desc: "Say how the workflows differ from what it writes (with the same options), and write nothing"
|
|
25
28
|
|
|
26
29
|
# The adapters each worker's database can stand in for, by the
|
|
27
30
|
# database duel-rails calls it.
|
|
@@ -37,28 +40,23 @@ module Duel
|
|
|
37
40
|
# Controllers of Rails's own (its health check, Active Storage...).
|
|
38
41
|
FRAMEWORK = %r{\A(rails|active_storage|action_mailbox|turbo)/}
|
|
39
42
|
|
|
40
|
-
def create_config = template("duel.rb.tt", ".duel.rb")
|
|
43
|
+
def create_config = (template("duel.rb.tt", ".duel.rb") unless checking?)
|
|
41
44
|
|
|
42
|
-
def create_environment = template("benchmark.rb.tt", "config/environments/benchmark.rb")
|
|
45
|
+
def create_environment = (template("benchmark.rb.tt", "config/environments/benchmark.rb") unless checking?)
|
|
43
46
|
|
|
44
|
-
def create_benchmarks = template("requests_duel.rb.tt", "duel/requests_duel.rb")
|
|
47
|
+
def create_benchmarks = (template("requests_duel.rb.tt", "duel/requests_duel.rb") unless checking?)
|
|
45
48
|
|
|
46
|
-
def create_boot_benchmark = template("boot_duel.rb.tt", "duel/boot_duel.rb")
|
|
49
|
+
def create_boot_benchmark = (template("boot_duel.rb.tt", "duel/boot_duel.rb") unless checking?)
|
|
47
50
|
|
|
48
|
-
# The workflows, at the repository's root
|
|
49
|
-
# perf-comment.yml, which comments on a pull request with the
|
|
50
|
-
# report, or, for an app in a subdirectory, perf-<its path>.yml
|
|
51
|
-
# (perf-apps-blog.yml) and perf-<its path>-comment.yml, so that each
|
|
52
|
-
# of a monorepo's apps can have its own.
|
|
51
|
+
# The workflows, at the repository's root (see #workflows).
|
|
53
52
|
def create_workflow
|
|
54
|
-
|
|
55
|
-
name = dir ? "perf-#{dir.tr("/", "-")}" : "perf"
|
|
56
|
-
template("perf.yml.tt", File.join(repository, ".github", "workflows", "#{name}.yml"))
|
|
57
|
-
template("perf-comment.yml.tt", File.join(repository, ".github", "workflows", "#{name}-comment.yml"))
|
|
53
|
+
workflows.each { |source, path| template(source, path) } unless checking?
|
|
58
54
|
end
|
|
59
55
|
|
|
60
56
|
# The plugin that gives each worker its database's server.
|
|
61
57
|
def add_plugin
|
|
58
|
+
return if checking?
|
|
59
|
+
|
|
62
60
|
plugin = PLUGINS[database]
|
|
63
61
|
gem(plugin, group: :development) if plugin && !gemfile.include?(plugin)
|
|
64
62
|
end
|
|
@@ -66,11 +64,56 @@ module Duel
|
|
|
66
64
|
# StackProf, for profiles of regressions: it runs on CRuby only, so
|
|
67
65
|
# it's left out of JRuby's and TruffleRuby's bundles.
|
|
68
66
|
def add_stackprof
|
|
69
|
-
gem("stackprof", platforms: :mri, group: :development) unless gemfile.include?("stackprof")
|
|
67
|
+
gem("stackprof", platforms: :mri, group: :development) unless checking? || gemfile.include?("stackprof")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# With --check, says whether each workflow is what it writes, or how
|
|
71
|
+
# it differs (as diff -u has it), or that it's missing, as `duel init
|
|
72
|
+
# --check` does, and exits with 1 where one isn't (a generator's
|
|
73
|
+
# failure doesn't change its exit status otherwise).
|
|
74
|
+
def check_workflows
|
|
75
|
+
return unless checking?
|
|
76
|
+
|
|
77
|
+
differ = workflows.count { |source, path| !same?(source, path) }
|
|
78
|
+
exit(1) if differ.positive?
|
|
70
79
|
end
|
|
71
80
|
|
|
72
81
|
private
|
|
73
82
|
|
|
83
|
+
def checking? = options.fetch(:check)
|
|
84
|
+
|
|
85
|
+
# The workflows' templates, by where they're written: perf.yml, and
|
|
86
|
+
# perf-comment.yml, which comments on a pull request with the
|
|
87
|
+
# report, or, for an app in a subdirectory, perf-<its path>.yml
|
|
88
|
+
# (perf-apps-blog.yml) and perf-<its path>-comment.yml, so that each
|
|
89
|
+
# of a monorepo's apps can have its own.
|
|
90
|
+
def workflows
|
|
91
|
+
dir = working_directory
|
|
92
|
+
name = dir ? "perf-#{dir.tr("/", "-")}" : "perf"
|
|
93
|
+
{"perf.yml.tt" => File.join(repository, ".github", "workflows", "#{name}.yml"),
|
|
94
|
+
"perf-comment.yml.tt" => File.join(repository, ".github", "workflows", "#{name}-comment.yml")}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Whether the workflow at +path+ is what the template +source+ makes,
|
|
98
|
+
# saying so, or how it differs, or that it's missing.
|
|
99
|
+
def same?(source, path)
|
|
100
|
+
shown = Pathname(path).relative_path_from(destination_root).to_s
|
|
101
|
+
unless File.file?(path)
|
|
102
|
+
say_status :missing, shown
|
|
103
|
+
return false
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
content = ERB.new(File.read(find_in_source_paths(source)), trim_mode: "-").result(template_binding)
|
|
107
|
+
differences, = Open3.capture2("diff", "-u", "-L", shown, "-L", "#{shown} (duel:install)", path, "-", stdin_data: content)
|
|
108
|
+
say_status(differences.empty? ? :identical : :differs, shown)
|
|
109
|
+
say differences unless differences.empty?
|
|
110
|
+
differences.empty?
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# A binding for a template, as Thor's: of the generator, and none of
|
|
114
|
+
# a method's variables.
|
|
115
|
+
def template_binding = binding
|
|
116
|
+
|
|
74
117
|
# The app's settings, which decide the workflow's jobs, as for
|
|
75
118
|
# `duel init` (see Duel::Init#settings): its .duel.rb's, which
|
|
76
119
|
# create_config has written by now (or kept), or nil where it doesn't
|
|
@@ -161,6 +204,10 @@ module Duel
|
|
|
161
204
|
path = Pathname(File.realpath(destination_root)).relative_path_from(File.realpath(repository)).to_s
|
|
162
205
|
path unless path == "."
|
|
163
206
|
end
|
|
207
|
+
|
|
208
|
+
# What marks the workflow's comment on a pull request, as `duel
|
|
209
|
+
# init`'s does (see Duel::Init#marker).
|
|
210
|
+
def marker = ["duel", working_directory].compact.join(" ")
|
|
164
211
|
end
|
|
165
212
|
end
|
|
166
213
|
end
|
|
@@ -3,14 +3,15 @@ name: Perf comment<%= " (#{working_directory})" if working_directory %>
|
|
|
3
3
|
# Duel's report, as a new comment on the pull request, when Duel says to:
|
|
4
4
|
# always (post), or only when its last comment's status differs from the
|
|
5
5
|
# run's (change), so the latest comment is never stale. It never edits or
|
|
6
|
-
# deletes a comment
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
6
|
+
# deletes a comment, but hides Duel's earlier ones as outdated, so the
|
|
7
|
+
# newest is the one in view. It runs once the Perf workflow has, with
|
|
8
|
+
# this repository's own workflow and a token that can write, so a pull
|
|
9
|
+
# request from a fork gets a comment too. It checks nothing out and runs
|
|
10
|
+
# none of the pull request's code, only `duel comment` (see Duel's
|
|
11
|
+
# docs/ci.md), which trusts only what the Duel job could have said in
|
|
12
|
+
# what it kept: the pull request's number, if it names the pull request
|
|
13
|
+
# the run compared, and the comment and the status, if they're ones Duel
|
|
14
|
+
# says. Its report, a fork's too, is the comment, as Markdown.
|
|
14
15
|
<% if accept_label -%>
|
|
15
16
|
#
|
|
16
17
|
# And when the label that accepts a regression (c.accept_label in
|
|
@@ -52,46 +53,20 @@ jobs:
|
|
|
52
53
|
path: ${{ runner.temp }}/report
|
|
53
54
|
run-id: ${{ github.event.workflow_run.id }}
|
|
54
55
|
github-token: ${{ github.token }}
|
|
56
|
+
- uses: ruby/setup-ruby@v1
|
|
57
|
+
if: steps.report.outcome == 'success'
|
|
58
|
+
with:
|
|
59
|
+
ruby-version: ruby
|
|
60
|
+
# Duel's own code, from RubyGems (none of the pull request's), so a
|
|
61
|
+
# fix to how it comments comes with a release of Duel.
|
|
55
62
|
- name: Comment on the pull request
|
|
56
63
|
if: steps.report.outcome == 'success'
|
|
57
64
|
env:
|
|
58
65
|
GH_TOKEN: ${{ github.token }}
|
|
59
66
|
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
|
|
60
67
|
run: |
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
COMMENT=$(said comment 'post|change')
|
|
64
|
-
STATUS=$(said status 'passed|failed|neutral')
|
|
65
|
-
[ -n "$PR" ] && [ -n "$COMMENT" ] && [ -n "$STATUS" ] || exit 0
|
|
66
|
-
# (The pull request's head commit, and the repository it's from.)
|
|
67
|
-
head=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '"\(.head.sha) \(.head.repo.full_name)"')
|
|
68
|
-
[ "${head%% *}" = "$HEAD_SHA" ] || exit 0
|
|
69
|
-
# The report, as Markdown for a branch of this repository (whose
|
|
70
|
-
# author can push here anyway), but for a fork's, as text: its run
|
|
71
|
-
# ran the fork's code, which could have written anything in it. In
|
|
72
|
-
# a code block, fenced with more backticks than any run of them in
|
|
73
|
-
# the report, it can't mention anyone, link anywhere or show an
|
|
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.
|
|
77
|
-
report() {
|
|
78
|
-
if [ "${head#* }" = "$GITHUB_REPOSITORY" ]; then cat "$RUNNER_TEMP/report/duel.md" && return; fi
|
|
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 "`" }')
|
|
82
|
-
printf 'From a fork, so shown as text:\n\n%s\n' "$fence"
|
|
83
|
-
cat "$text"
|
|
84
|
-
printf '\n%s\n' "$fence"
|
|
85
|
-
}
|
|
86
|
-
marker="<!-- duel<%= " #{working_directory}" if working_directory %>"
|
|
87
|
-
# The first line of the last comment Duel posted here: its marker,
|
|
88
|
-
# with its status (none in Duel 0.1.0's, which counts as another).
|
|
89
|
-
last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
|
|
90
|
-
--jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\") or . == \"$marker -->\")" | tail -n 1)
|
|
91
|
-
if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
|
|
92
|
-
{ echo "$marker status=$STATUS -->"; report; } > "$RUNNER_TEMP/comment.md"
|
|
93
|
-
gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
|
|
94
|
-
fi
|
|
68
|
+
gem install duel --version '~> 0.1.8' --no-document
|
|
69
|
+
duel comment --report "$RUNNER_TEMP/report" --head "$HEAD_SHA" --marker '<%= marker.gsub("'") { "'\\''" } %>'
|
|
95
70
|
<% if accept_label -%>
|
|
96
71
|
|
|
97
72
|
again:
|
|
@@ -318,13 +318,15 @@ jobs:
|
|
|
318
318
|
<% end -%>
|
|
319
319
|
<% if badge? -%>
|
|
320
320
|
|
|
321
|
-
# Duel's badge, for the README: green (perf guarded)
|
|
322
|
-
# regressed), as the last push to the default
|
|
323
|
-
# left it. It's red where
|
|
324
|
-
# even one that passed (with
|
|
325
|
-
#
|
|
326
|
-
#
|
|
327
|
-
# to
|
|
321
|
+
# Duel's badge, for the README: green (perf guarded), red (perf
|
|
322
|
+
# regressed) or grey (not measured), as the last push to the default
|
|
323
|
+
# branch that Duel compared left it. It's red where Duel failed the push
|
|
324
|
+
# or found a regression, even one that passed (with
|
|
325
|
+
# c.fail_on = :pull_requests in .duel.rb), and grey where the Duel job
|
|
326
|
+
# failed before Duel could judge the push (its runner ran out of memory,
|
|
327
|
+
# say). A push with nothing to compare leaves it as it was, and so does
|
|
328
|
+
# a run for an older push than the badge's. This job writes the badge,
|
|
329
|
+
# alone, to a branch of its own, which the README shows:
|
|
328
330
|
#
|
|
329
331
|
# [}" if working_directory %>/badge.svg)](https://github.com/sferik/duel-ruby)
|
|
330
332
|
#
|
|
@@ -370,10 +372,13 @@ jobs:
|
|
|
370
372
|
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
|
|
371
373
|
if [ -n "$last" ] && [ "$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$last" --jq .status 2>/dev/null)" = ahead ]; then exit 0; fi
|
|
372
374
|
# (Its image, written here rather than fetched from anywhere: green,
|
|
373
|
-
#
|
|
375
|
+
# red where Duel failed the push or found a regression, or grey
|
|
376
|
+
# where the Duel job failed before Duel said either.)
|
|
374
377
|
state="perf guarded" width=133 top="#34D058" bottom="#28A745" right="76.939C78.629 0 80 1.343 80"
|
|
375
|
-
if [ "$
|
|
378
|
+
if [ "$STATUS" = failed ]; then
|
|
376
379
|
state="perf regressed" width=142 top="#EA4A5A" bottom="#D73A49" right="85.939C87.629 0 89 1.343 89"
|
|
380
|
+
elif [ "$RESULT" = failure ] && [ "$STATUS" != passed ]; then
|
|
381
|
+
state="not measured" width=138 top="#959DA5" bottom="#6A737D" right="81.939C83.629 0 85 1.343 85"
|
|
377
382
|
fi
|
|
378
383
|
cat > "$RUNNER_TEMP/badge.svg" <<SVG
|
|
379
384
|
<svg xmlns="http://www.w3.org/2000/svg" width="$width" height="20">
|
data/sig/duel/rails.rbs
CHANGED
|
@@ -227,8 +227,23 @@ module Duel
|
|
|
227
227
|
def add_plugin: () -> void
|
|
228
228
|
def add_stackprof: () -> void
|
|
229
229
|
|
|
230
|
+
# With --check, says how each workflow differs, and exits with 1
|
|
231
|
+
# where one does.
|
|
232
|
+
def check_workflows: () -> void
|
|
233
|
+
|
|
230
234
|
private
|
|
231
235
|
|
|
236
|
+
def checking?: () -> bool
|
|
237
|
+
|
|
238
|
+
# The workflows' templates, by where they're written.
|
|
239
|
+
def workflows: () -> Hash[String, String]
|
|
240
|
+
|
|
241
|
+
# Whether the workflow at +path+ is what +source+ makes, saying so.
|
|
242
|
+
def same?: (String source, String path) -> bool
|
|
243
|
+
|
|
244
|
+
# A binding for a template, of the generator.
|
|
245
|
+
def template_binding: () -> Binding
|
|
246
|
+
|
|
232
247
|
@settings: Config?
|
|
233
248
|
|
|
234
249
|
# The app's settings, which decide the workflow's jobs (nil where
|
|
@@ -259,6 +274,9 @@ module Duel
|
|
|
259
274
|
def ruby_version: () -> String?
|
|
260
275
|
def repository: () -> String
|
|
261
276
|
def working_directory: () -> String?
|
|
277
|
+
|
|
278
|
+
# What marks the workflow's comment on a pull request.
|
|
279
|
+
def marker: () -> String
|
|
262
280
|
end
|
|
263
281
|
end
|
|
264
282
|
end
|