release_flow 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed923d96287e3f32f00b20bb783cb6ebdaa46e60c78397af348d02744b65283a
4
- data.tar.gz: a8021809a338794139ddf41b1fba7099d175418e63fa181f008cd26312a447ce
3
+ metadata.gz: 4079dd2b515c2be854deaa259c49cbd9a8daa82c497481e00538c72331b86b17
4
+ data.tar.gz: 6d5198564a37b4686e58033e1f693aea95d8fdbbcba7da77cf351912b518af09
5
5
  SHA512:
6
- metadata.gz: 9688d07473f50f93c1171a4d45d419825eb15b6583c85d06c147ca73cc897bf66786fa09bc7d340215448bf36a9f5006abaf6d1726c6749b3fc003802cbb1f42
7
- data.tar.gz: 972f65d6e2222673a0d73043b68b6f9d01d4200f99f373b7de01311da891e414359c013fbfa048b27dbf4aa8785235489f17ae20d10d071d530b85a3f0252424
6
+ metadata.gz: dbf99cab219db90c780cf33bf933f9eb65df49e65c3fcf6ca7de55326b300aa57e0c17043cd4c78bcbee8e43334517454eb80f30495c04055437cef01b153776
7
+ data.tar.gz: e6e14eca96e10bd87c8c0aac031c8503766a9342ade5aa9e3fdbeb8148e8753574e5a8303733dfb08a9ec36c92921e04fe3885b2ce222d0afae703def9f6c89c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.3.0
6
+
7
+ - `bin/release status` shows where the release chain stands, changing nothing: the last release shipped, the `main` and `next` heads, CI on `next` with job counts, each open merge-back, changelog and release PR with its check progress and mergeability, what waits on what, and the command to run next.
8
+ - `--wait` on `prepare`, `cut`, `ship` and `merge-back` follows the PR the command opened until the next step is yours, printing a line with the elapsed time at each stage change: the changelog and merge-back PRs until they merge, and for `cut`, CI on `next` and then the release PR's checks. A failing check or a closed PR exits non-zero, naming it; `--timeout MINUTES` (default 45) bounds the wait, and Ctrl-C stops it with exit 130, changing nothing.
9
+ - `cut --if-needed` waits without failing while CI is still running on the commit it would cut, so a CI run finishing on an older commit no longer turns the release workflow red; CI that failed still fails it, and `cut` by hand still refuses.
10
+ - `cut` refuses when `ci_workflow` has never run on the integration branch, naming the setting, instead of waiting on CI that will never report.
11
+ - Under GitHub Actions, a release that waits (`prepare` behind one under way, `cut` behind CI) also shows as a notice on the run and in its step summary.
12
+
5
13
  ## 0.2.1
6
14
 
7
15
  - `prepare` names a project's first release when `CHANGELOG.md` holds only an empty `## [Unreleased]`, instead of crashing with `undefined method 'each_line' for nil`, and the file it writes ends with a single newline.
data/README.md CHANGED
@@ -79,6 +79,43 @@ A setting it doesn't know stops `bin/release` with the list of those it does.
79
79
  bin/release prepare # name the release: gather changelog.d/ into CHANGELOG.md, by PR into next
80
80
  bin/release cut # push release/<name>, which deploys staging, and open its PR into main
81
81
  bin/release ship # merge the reviewed commit, publish v<name>, merge main back into next
82
+ bin/release status # where the release stands, and the command that comes next
83
+ ```
84
+
85
+ **Where it stands.** `bin/release status` changes nothing. It prints the
86
+ last release shipped, the heads of `main` and `next`, CI on `next`'s head
87
+ with its job counts, and each open merge-back, changelog and release PR with
88
+ its check progress and whether it can merge. It ends on what is waiting on
89
+ what, and the command to run next:
90
+
91
+ ```text
92
+ == Release status in me/app ==
93
+ shipped: v2026.10.20
94
+ heads: main at def5678, next at abc1234; main is in next
95
+ next: v2026.10.27 is cut, on release/2026.10.27
96
+ CI on next at abc1234: passed, jobs 20/20 passed, 0 running, 0 failed
97
+ release PR #42 (release/2026.10.27 at abc1234): https://github.com/me/app/pull/42
98
+ checks 14/20 passed, 6 running, 0 failed; mergeable
99
+ Waiting: release PR #42's checks are still running.
100
+ Next: bin/release ship 42 abc1234 once checks pass and it's reviewed on staging.
101
+ ```
102
+
103
+ **Wait for it.** `prepare`, `cut`, `ship` and `merge-back` return once
104
+ they've opened their PR. Add `--wait` and they follow it until the next step
105
+ is yours, printing a line, with the time since it started, each time its
106
+ stage changes: `prepare` and `merge-back` (and `ship`, for its merge-back)
107
+ until the PR merges, and `cut` until CI on `next` has finished and then
108
+ until every check on the release PR has passed. A failing check or a closed
109
+ PR is named and exits non-zero. It polls every 20 seconds and gives up after
110
+ 45 minutes, or `--timeout MINUTES`. Ctrl-C stops watching and changes
111
+ nothing; `bin/release status` picks up from there.
112
+
113
+ ```text
114
+ [0m00s] CI on next at abc1234: finished
115
+ [0m00s] release PR #42: no checks reported yet
116
+ [0m20s] release PR #42: checks running, 1/2 passed, 1 running, 0 failed
117
+ [1m00s] release PR #42: all 2 checks passed
118
+ Next: review it on staging, then bin/release ship 42 abc1234.
82
119
  ```
83
120
 
84
121
  Every command takes `--dry-run`. A release is named for the day,
@@ -14,6 +14,8 @@ module ReleaseFlow
14
14
  o.banner = "#{Release::USAGE} (see #{config.guide})"
15
15
  o.on("--dry-run", "Print the plan without changing anything") { options[:dry_run] = true }
16
16
  o.on("--if-needed", "prepare, cut: when there's nothing to do yet, say so and stop without failing") { options[:if_needed] = true }
17
+ o.on("--wait", "prepare, cut, ship, merge-back: follow the PR it opened until the next step is yours") { options[:wait] = true }
18
+ o.on("--timeout MINUTES", Integer, "with --wait: give up after this long (default 45)") { |m| options[:timeout] = m * 60 }
17
19
  o.on("-h", "--help", "Show this") { options[:help] = true }
18
20
  end
19
21
  args = parser.parse(argv)
@@ -21,6 +23,9 @@ module ReleaseFlow
21
23
 
22
24
  Release.new(options, root: root, config: config).run(*args)
23
25
  0
26
+ rescue Release::Stopped => e
27
+ warn("bin/release: #{e.message}")
28
+ 130
24
29
  rescue Error, OptionParser::ParseError => e
25
30
  warn("bin/release: #{e.message}")
26
31
  1
@@ -11,13 +11,16 @@ require "tmpdir"
11
11
  module ReleaseFlow
12
12
  class Release
13
13
  class Error < ReleaseFlow::Error; end
14
+ class Stopped < Error; end
14
15
 
15
16
  CLEAN_GIT_ENV = GitEnv::HASH
16
17
  TEMPLATE = ".github/PULL_REQUEST_TEMPLATE/release.md"
17
18
  SHIP_USAGE = "bin/release ship [<PR> <commit reviewed on staging>]"
18
- USAGE = "usage: bin/release prepare | cut | #{SHIP_USAGE.delete_prefix("bin/release ")} | merge-back | check"
19
+ USAGE = "usage: bin/release prepare | cut | #{SHIP_USAGE.delete_prefix("bin/release ")} | merge-back | check | status"
19
20
  ONCE_READY = "once its checks pass and any required approval is given"
20
21
  BODY_LIMIT = 60_000
22
+ INTERVAL = 20
23
+ TIMEOUT = 45 * 60
21
24
 
22
25
  def initialize(options, root: Dir.pwd, config: nil)
23
26
  @opts = options
@@ -28,6 +31,7 @@ module ReleaseFlow
28
31
  def run(command, *args)
29
32
  @repo = GithubOrigin.repo(@root) or raise Error, "origin isn't a GitHub repository, so there's no telling which one to act on"
30
33
  case command
34
+ when "status" then status
31
35
  when "prepare" then prepare
32
36
  when "cut" then cut
33
37
  when "ship" then ship(*args)
@@ -37,12 +41,26 @@ module ReleaseFlow
37
41
  end
38
42
  end
39
43
 
44
+ def status
45
+ fetch
46
+ changelog = next_changelog
47
+ named = Changelog.named_release(changelog)
48
+ head = git("rev-parse", "origin/#{integration}")
49
+ say(Status.report(
50
+ repo: @repo, integration: integration, production: production, shipped: latest_shipped,
51
+ integration_head: head, production_head: git("rev-parse", "origin/#{production}"),
52
+ merged_back: ancestor?("origin/#{production}", "origin/#{integration}"),
53
+ waiting: Changelog.unreleased(changelog, fragments_at("origin/#{integration}").values).size,
54
+ named: (named unless shipped?(named)), ci: ci_progress(head), prs: open_flow_prs
55
+ ))
56
+ end
57
+
40
58
  def prepare
41
59
  fetch
42
60
  changelog = next_changelog
43
61
  fragments = fragments_at("origin/#{integration}")
44
62
  if (under_way = release_under_way(changelog))
45
- return say("#{under_way}, so the next release waits for it.") if @opts[:if_needed]
63
+ return notice("#{under_way}, so the next release waits for it.", title: "The next release waits") if @opts[:if_needed]
46
64
 
47
65
  raise Error, "#{under_way}: finish that release before starting another"
48
66
  end
@@ -59,7 +77,10 @@ module ReleaseFlow
59
77
  url = propose("changelog/#{name}", at: commit, base: integration, title: "Changelog for release #{name}",
60
78
  body: "Gathers `changelog.d/` and `[Unreleased]` into v#{name} so `bin/release cut` can cut it.\n", auto_merge: true)
61
79
  say(" → #{url}, merging into #{integration} #{ONCE_READY}")
62
- say("Then: bin/release cut, once it has merged.")
80
+ return say("Then: bin/release cut, once it has merged.") unless waiting?
81
+
82
+ follow_pr(url, "changelog PR", until_merged: true)
83
+ say("Next: bin/release cut --wait.")
63
84
  end
64
85
 
65
86
  def cut
@@ -75,7 +96,10 @@ module ReleaseFlow
75
96
  raise Error, "#{open.delete_prefix("refs/heads/")} is still open: ship it or delete it before cutting another" if open
76
97
  commit, waiting = cut_point(name)
77
98
  raise Error, "#{production} isn't in #{integration} yet: #{production_catch_up}" unless ancestor?("origin/#{production}", commit)
78
- require_passing_ci(commit, name)
99
+ follow_ci(commit) if waiting?
100
+ unless ci_passed?(commit, name)
101
+ return notice("CI hasn't finished on #{commit[0, 7]} yet; the cut runs again when it does.", title: "The release cut waits for CI")
102
+ end
79
103
 
80
104
  say("== Cut #{branch} in #{@repo} ==")
81
105
  say(" at #{commit[0, 7]}; #{waiting} later commit#{"s" unless waiting == 1} on next wait#{"s" if waiting == 1} for the next release") if waiting.positive?
@@ -84,7 +108,10 @@ module ReleaseFlow
84
108
  url = propose(branch, at: commit, base: production, title: "Release #{name}",
85
109
  body: release_body(branch, Changelog.section(git("show", "#{commit}:CHANGELOG.md"), name)))
86
110
  say(" → #{url}")
87
- say("Then: review it on staging, and run bin/release ship.")
111
+ return say("Then: review it on staging, and run bin/release ship.") unless waiting?
112
+
113
+ follow_pr(url, "release PR", until_merged: false)
114
+ say("Next: review it on staging, then bin/release ship #{url.split("/").last} #{commit[0, 7]}.")
88
115
  end
89
116
 
90
117
  def ship(pr = nil, sha = nil)
@@ -127,6 +154,10 @@ module ReleaseFlow
127
154
  already_current = out.include?("no new commits on the base branch")
128
155
  say(" ! GitHub couldn't bring #{url} up to date; press Update branch on it") unless updated || already_current
129
156
  say(" → #{url}, merging into #{integration} #{ONCE_READY}")
157
+ return unless waiting?
158
+
159
+ follow_pr(url, "merge-back PR", until_merged: true)
160
+ say("Done: #{production} is back in #{integration}.")
130
161
  end
131
162
 
132
163
  private
@@ -140,12 +171,22 @@ module ReleaseFlow
140
171
  end
141
172
 
142
173
  def dry_run? = @opts[:dry_run]
174
+ def waiting? = @opts[:wait] && !dry_run?
143
175
  def say(msg) = puts(msg)
144
176
  def dry(msg) = say(" [dry-run] would #{msg}")
145
177
  def next_changelog = git("show", "origin/#{integration}:CHANGELOG.md")
146
178
  def integration = @config.integration_branch
147
179
  def production = @config.production_branch
148
180
 
181
+ # A wait nobody reads in a workflow log goes unseen, so Actions also shows it on the run and its summary.
182
+ def notice(msg, title:)
183
+ say(msg)
184
+ return unless ENV["GITHUB_ACTIONS"] == "true"
185
+
186
+ say("::notice title=#{title}::#{msg.gsub("%", "%25").gsub("\r", "%0D").gsub("\n", "%0A")}")
187
+ File.write(ENV["GITHUB_STEP_SUMMARY"], "#{msg}\n", mode: "a") if ENV["GITHUB_STEP_SUMMARY"]
188
+ end
189
+
149
190
  def fragments_at(commit)
150
191
  git("ls-tree", "--name-only", commit, "#{Changelog::FRAGMENTS}/").lines(chomp: true)
151
192
  .select { |path| Changelog.fragment?(path) }.to_h { |path| [path, git("show", "#{commit}:#{path}")] }
@@ -172,6 +213,88 @@ module ReleaseFlow
172
213
  def template_repo = @config.template
173
214
  def pr_info(pr) = JSON.parse(gh("pr", "view", pr, "--json", "state,headRefName,headRefOid,baseRefName,mergeCommit"))
174
215
 
216
+ # Polls until the block says :done, printing a line only when the stage it reports changes.
217
+ def watch(subject)
218
+ clock = @opts.fetch(:clock) { -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) } }
219
+ timeout = @opts.fetch(:timeout, TIMEOUT)
220
+ started = clock.call
221
+ last = nil
222
+ loop do
223
+ stage, line, verdict = yield
224
+ elapsed = (clock.call - started).to_i
225
+ say(format(" [%dm%02ds] %s: %s", elapsed / 60, elapsed % 60, subject, line)) unless stage == last
226
+ $stdout.flush
227
+ last = stage
228
+ return if verdict == :done
229
+ raise Error, "#{subject}: #{line}" if verdict == :failed
230
+ raise Error, "stopped waiting on #{subject} after #{timeout / 60} min; nothing was changed. bin/release status shows where it stands" if elapsed >= timeout
231
+
232
+ @opts.fetch(:sleeper) { method(:sleep) }.call(@opts.fetch(:interval, INTERVAL))
233
+ end
234
+ rescue Interrupt
235
+ raise Stopped, "stopped watching #{subject}; nothing was changed. bin/release status shows where it stands"
236
+ end
237
+
238
+ def follow_pr(url, label, until_merged:)
239
+ watch("#{label} ##{url.split("/").last}") do
240
+ pr = JSON.parse(gh("pr", "view", url, "--json", "state,mergeable,statusCheckRollup"))
241
+ checks = Status.tally(pr["statusCheckRollup"] || [])
242
+ verdict = Status.verdict(checks)
243
+ if pr["state"] == "MERGED" then [:merged, "merged", :done]
244
+ elsif pr["state"] == "CLOSED" then [:closed, "closed without merging", :failed]
245
+ elsif verdict == :failed then [:failed, "checks failed, #{Status.checks(checks)}", :failed]
246
+ elsif pr["mergeable"] == "CONFLICTING" then [:conflicts, "has conflicts with its base", :failed]
247
+ elsif verdict == :passed && until_merged then [:passed, "all #{checks[:total]} checks passed; waiting for it to merge"]
248
+ elsif verdict == :passed then [:passed, "all #{checks[:total]} checks passed", :done]
249
+ elsif checks[:total].zero? then [:none, "no checks reported yet"]
250
+ else [:running, "checks running, #{Status.checks(checks)}"]
251
+ end
252
+ end
253
+ end
254
+
255
+ # Waits for every CI run on the commit to finish; ci_passed? then judges them.
256
+ def follow_ci(commit)
257
+ watch("CI on #{integration} at #{commit[0, 7]}") do
258
+ ci = ci_progress(commit)
259
+ require_ci_on_integration unless ci[:ran]
260
+ if ci[:finished] then [:finished, "finished", :done]
261
+ elsif ci[:ran] then [:running, "running, jobs #{Status.checks(ci)}"]
262
+ else [:none, "not started"]
263
+ end
264
+ end
265
+ end
266
+
267
+ def latest_shipped
268
+ git("tag", "--merged", "origin/#{production}", "--sort=-creatordate", "--list", "v*").lines(chomp: true)
269
+ .filter_map { |tag| tag[/\Av(#{Changelog::NAME})\z/o, 1] }.first
270
+ end
271
+
272
+ def ci_progress(commit)
273
+ runs = JSON.parse(gh("run", "list", "--workflow", @config.ci_workflow, "--commit", commit, "--event", "push", "--json", "databaseId,status,conclusion"))
274
+ return {passed: 0, running: 0, failed: 0, total: 0, failing: [], ran: false} if runs.empty?
275
+
276
+ jobs = JSON.parse(gh("run", "view", runs.first["databaseId"].to_s, "--json", "jobs"))["jobs"]
277
+ Status.tally(jobs).merge(ran: true, finished: runs.all? { |run| run["status"] == "completed" })
278
+ end
279
+
280
+ # One call for every open PR, kept to the branches the flow opens.
281
+ def open_flow_prs
282
+ prs = JSON.parse(gh("pr", "list", "--state", "open", "--limit", "100", "--json",
283
+ "number,url,headRefName,headRefOid,baseRefName,mergeable,statusCheckRollup"))
284
+ prs.filter_map do |pr|
285
+ kind = flow_kind(pr["headRefName"], pr["baseRefName"]) or next
286
+ {kind: kind, number: pr["number"], url: pr["url"], branch: pr["headRefName"], head: pr["headRefOid"],
287
+ mergeable: pr["mergeable"], checks: Status.tally(pr["statusCheckRollup"] || [])}
288
+ end
289
+ end
290
+
291
+ def flow_kind(branch, base)
292
+ return :release if base == production && branch.match?(Candidate::BRANCH)
293
+ return unless base == integration
294
+
295
+ {"merge-back/" => :merge_back, "changelog/" => :changelog}.find { |prefix, _| branch.start_with?(prefix) }&.last
296
+ end
297
+
175
298
  def release_under_way(changelog)
176
299
  named = Changelog.named_release(changelog)
177
300
  return "v#{named} is named but hasn't shipped" if named && !shipped?(named)
@@ -193,17 +316,30 @@ module ReleaseFlow
193
316
  "run bin/release ship #{unshipped["number"]} #{unshipped["headRefOid"][0, 7]} to publish it and merge #{production} back"
194
317
  end
195
318
 
196
- def require_passing_ci(commit, name)
319
+ # Under --if-needed a CI run still going is a wait, not a failure: its completion runs cut again.
320
+ def ci_passed?(commit, name)
197
321
  runs = JSON.parse(gh("run", "list", "--workflow", @config.ci_workflow, "--commit", commit, "--event", "push", "--json", "status,conclusion"))
198
322
  unless runs.any? && runs.all? { |run| run["status"] == "completed" }
323
+ require_ci_on_integration if runs.empty?
324
+ return false if @opts[:if_needed]
325
+
199
326
  raise Error, "CI hasn't passed on #{commit[0, 7]} yet: run cut again once it has"
200
327
  end
201
- return if runs.all? { |run| run["conclusion"] == "success" }
328
+ return true if runs.all? { |run| run["conclusion"] == "success" }
202
329
 
203
330
  raise Error, "CI failed on #{commit[0, 7]}, where v#{name} would be cut. If it was a flake, re-run its failed jobs; otherwise " \
204
331
  "fix it by a PR into #{integration}, its changelog line under ## v#{name}. Then cut again (AUTO_RELEASE does once CI passes)"
205
332
  end
206
333
 
334
+ # A workflow that never ran on the integration branch is misnamed, not slow, so waiting on it would never end.
335
+ def require_ci_on_integration
336
+ ran = JSON.parse(gh("run", "list", "--workflow", @config.ci_workflow, "--branch", integration, "--event", "push", "--limit", "1", "--json", "databaseId"))
337
+ return if ran.any?
338
+
339
+ raise Error, "#{@config.ci_workflow} has never run on #{integration}, so there's no CI for cut to wait on: " \
340
+ "set ci_workflow in #{FILE} to the workflow that runs your checks on pushes to #{integration}"
341
+ end
342
+
207
343
  def fetch
208
344
  @remote_refs = nil
209
345
  git("fetch", "-q", "--prune", "--tags", "origin")
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReleaseFlow
4
+ # What bin/release status prints: where the release chain stands, from facts Release gathers, and the command that comes next.
5
+ module Status
6
+ PASSED = %w[SUCCESS SKIPPED NEUTRAL].freeze
7
+ RUNNING = %w[PENDING EXPECTED QUEUED IN_PROGRESS WAITING REQUESTED].freeze
8
+ KINDS = {release: "release PR", merge_back: "merge-back PR", changelog: "changelog PR"}.freeze
9
+ MERGEABLE = {"MERGEABLE" => "mergeable", "CONFLICTING" => "has conflicts"}.freeze
10
+ AUTO = " (the release workflow runs it when AUTO_RELEASE is on)"
11
+
12
+ module_function
13
+
14
+ # items: a PR's statusCheckRollup (check runs and status contexts) or a workflow run's jobs.
15
+ def tally(items)
16
+ counts = {passed: 0, running: 0, failed: 0, total: items.size, failing: []}
17
+ items.each do |item|
18
+ outcome = outcome(item)
19
+ counts[outcome] += 1
20
+ counts[:failing] << (item["name"] || item["context"]) if outcome == :failed
21
+ end
22
+ counts
23
+ end
24
+
25
+ def outcome(item)
26
+ result = (item["conclusion"] || item["state"]).to_s.upcase
27
+ status = item["status"].to_s.upcase
28
+ return :running if result.empty? || RUNNING.include?(result) || !["", "COMPLETED"].include?(status)
29
+
30
+ PASSED.include?(result) ? :passed : :failed
31
+ end
32
+
33
+ def verdict(counts)
34
+ return :failed if counts[:failed].positive?
35
+ return :running if counts[:running].positive? || counts[:total].zero?
36
+
37
+ :passed
38
+ end
39
+
40
+ def checks(counts)
41
+ return "no checks reported yet" if counts[:total].zero?
42
+
43
+ line = "#{counts[:passed]}/#{counts[:total]} passed, #{counts[:running]} running, #{counts[:failed]} failed"
44
+ counts[:failing].any? ? "#{line} (#{counts[:failing].join(", ")})" : line
45
+ end
46
+
47
+ def report(facts)
48
+ [*lines(facts), *advice(facts)].join("\n")
49
+ end
50
+
51
+ def lines(facts)
52
+ integration, production = facts.values_at(:integration, :production)
53
+ prs = facts[:prs].sort_by { |pr| KINDS.keys.index(pr[:kind]) }
54
+ ["== Release status in #{facts[:repo]} ==",
55
+ " shipped: #{facts[:shipped] ? "v#{facts[:shipped]}" : "nothing yet"}",
56
+ " heads: #{production} at #{short(facts[:production_head])}, #{integration} at #{short(facts[:integration_head])}; " +
57
+ (facts[:merged_back] ? "#{production} is in #{integration}" : "#{production} isn't in #{integration} yet"),
58
+ " #{integration}: #{waiting_line(facts)}",
59
+ " CI on #{integration} at #{short(facts[:integration_head])}: #{ci_line(facts[:ci])}",
60
+ *prs.flat_map do |pr|
61
+ [" #{KINDS[pr[:kind]]} ##{pr[:number]} (#{pr[:branch]} at #{short(pr[:head])}): #{pr[:url]}",
62
+ " #{"checks " if pr[:checks][:total].positive?}#{checks(pr[:checks])}; #{MERGEABLE.fetch(pr[:mergeable], "mergeability not known yet")}"]
63
+ end]
64
+ end
65
+
66
+ def waiting_line(facts)
67
+ if (named = facts[:named])
68
+ cut = facts[:prs].any? { |pr| pr[:branch] == "release/#{named}" }
69
+ return cut ? "v#{named} is cut, on release/#{named}" : "v#{named} is named, waiting to be cut"
70
+ end
71
+ return "no changelog entries waiting" if facts[:waiting].zero?
72
+
73
+ (facts[:waiting] == 1) ? "1 changelog entry waits for a release" : "#{facts[:waiting]} changelog entries wait for a release"
74
+ end
75
+
76
+ def ci_line(ci)
77
+ return "not started" unless ci[:ran]
78
+
79
+ "#{verdict(ci)}, jobs #{checks(ci)}"
80
+ end
81
+
82
+ # The first open PR in KINDS order decides, since a release under way blocks the next one.
83
+ def advice(facts)
84
+ pr = facts[:prs].min_by { |p| KINDS.keys.index(p[:kind]) }
85
+ waiting, next_step = pr ? pr_advice(pr, facts) : branch_advice(facts)
86
+ [("Waiting: #{waiting}." if waiting), next_step].compact
87
+ end
88
+
89
+ def pr_advice(pr, facts)
90
+ label = "#{KINDS[pr[:kind]]} ##{pr[:number]}"
91
+ base = (pr[:kind] == :release) ? facts[:production] : facts[:integration]
92
+ checks = pr[:checks]
93
+ return [nil, "Next: resolve #{label}'s conflicts with #{base}; then bin/release status."] if pr[:mergeable] == "CONFLICTING"
94
+ if verdict(checks) == :failed
95
+ return ["#{label} has failing checks: #{checks[:failing].join(", ")}",
96
+ "Next: re-run the failed jobs if it was a flake, or fix them by a PR into #{pr[:branch]}; then bin/release status."]
97
+ end
98
+
99
+ case pr[:kind]
100
+ when :release
101
+ ship = "bin/release ship #{pr[:number]} #{short(pr[:head])}"
102
+ return [nil, "Next: review it on staging, then #{ship}."] if verdict(checks) == :passed
103
+
104
+ ["#{label}'s checks are still running", "Next: #{ship} once checks pass and it's reviewed on staging."]
105
+ when :merge_back
106
+ ["#{label} merges itself once its checks pass", "Next: nothing until it merges; bin/release status shows when it has."]
107
+ else
108
+ ["#{label} merges itself once its checks pass",
109
+ "Next: bin/release cut once it has merged and CI passes on #{facts[:integration]}, or bin/release cut --wait then."]
110
+ end
111
+ end
112
+
113
+ def branch_advice(facts)
114
+ integration = facts[:integration]
115
+ return [nil, "Next: bin/release merge-back."] unless facts[:merged_back]
116
+ return named_advice(facts) if facts[:named]
117
+ return [nil, "Next: bin/release prepare#{AUTO}."] if facts[:waiting].positive?
118
+
119
+ [nil, "Nothing to release: no changelog entries on #{integration}."]
120
+ end
121
+
122
+ def named_advice(facts)
123
+ ci = facts[:ci]
124
+ at = "#{facts[:integration]} at #{short(facts[:integration_head])}"
125
+ case (ci[:ran] ? verdict(ci) : :running)
126
+ when :passed then [nil, "Next: bin/release cut#{AUTO}."]
127
+ when :failed
128
+ ["CI failed on #{at}",
129
+ "Next: re-run the failed jobs if it was a flake, or fix it by a PR into #{facts[:integration]}; then bin/release cut."]
130
+ else ["CI on #{at} is still running", "Next: bin/release cut once it passes, or bin/release cut --wait now."]
131
+ end
132
+ end
133
+
134
+ def short(sha) = sha.to_s[0, 7]
135
+ end
136
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReleaseFlow
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/release_flow.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "release_flow/config"
10
10
  require_relative "release_flow/github_origin"
11
11
  require_relative "release_flow/changelog"
12
12
  require_relative "release_flow/candidate"
13
+ require_relative "release_flow/status"
13
14
  require_relative "release_flow/release"
14
15
  require_relative "release_flow/installer"
15
16
  require_relative "release_flow/cli"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: release_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Chmura
@@ -33,6 +33,7 @@ files:
33
33
  - lib/release_flow/github_origin.rb
34
34
  - lib/release_flow/installer.rb
35
35
  - lib/release_flow/release.rb
36
+ - lib/release_flow/status.rb
36
37
  - lib/release_flow/version.rb
37
38
  - templates/.github/PULL_REQUEST_TEMPLATE/release.md.erb
38
39
  - templates/.github/workflows/next_release.yml.erb