80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/kettle/dev/release_cli.rb', line 80
def run
ensure_bundler_2_7_plus!
version = nil
committed = nil
trunk = nil
feature = nil
if @start_step <= 2
version = detect_version
puts "Detected version: #{version.inspect}"
latest_overall = nil
latest_for_series = nil
begin
gem_name = detect_gem_name
latest_overall, latest_for_series = latest_released_versions(gem_name, version)
rescue StandardError => e
warn("[kettle-release] RubyGems check failed: #{e.class}: #{e.message}")
warn(e.backtrace.first(3).map { |l| " " + l }.join("\n")) if ENV["DEBUG"]
warn("Proceeding without RubyGems latest version info.")
end
if latest_overall
msg = "Latest released: #{latest_overall}"
if latest_for_series && latest_for_series != latest_overall
msg += " | Latest for series #{Gem::Version.new(version).segments[0, 2].join(".")}.x: #{latest_for_series}"
elsif latest_for_series
msg += " (matches current series)"
end
puts msg
cur = Gem::Version.new(version)
overall = Gem::Version.new(latest_overall)
cur_series = cur.segments[0, 2]
overall_series = overall.segments[0, 2]
if latest_for_series
lfs_series = Gem::Version.new(latest_for_series).segments[0, 2]
latest_for_series = nil unless lfs_series == cur_series
end
target = if (cur_series <=> overall_series) == -1
latest_for_series
else
latest_overall
end
if (cur_series <=> overall_series) == -1 && target.nil?
puts "Could not determine latest released version from RubyGems (offline?). Proceeding without sanity check."
elsif target
bump = Kettle::Dev::Versioning.classify_bump(target, version)
case bump
when :same
series = cur_series.join(".")
warn("version.rb (#{version}) matches the latest released version for series #{series} (#{target}).")
abort("Aborting: version bump required. Bump PATCH/MINOR/MAJOR/EPIC.")
when :downgrade
series = cur_series.join(".")
warn("version.rb (#{version}) is lower than the latest released version for series #{series} (#{target}).")
abort("Aborting: version must be bumped above #{target}.")
else
label = {epic: "EPIC", major: "MAJOR", minor: "MINOR", patch: "PATCH"}[bump] || bump.to_s.upcase
puts "Proposed bump type: #{label} (from #{target} -> #{version})"
end
else
puts "Could not determine latest released version from RubyGems (offline?). Proceeding without sanity check."
end
else
puts "Could not determine latest released version from RubyGems (offline?). Proceeding without sanity check."
end
puts "Have you updated lib/**/version.rb and CHANGELOG.md for v#{version}? [y/N]"
print("> ")
ans = Kettle::Dev::InputAdapter.gets&.strip
abort("Aborted: please update version.rb and CHANGELOG.md, then re-run.") unless ans&.downcase&.start_with?("y")
validate_copyright_years!
begin
update_readme_kloc_badge!
rescue StandardError => e
warn("Failed to update KLOC badge in README: #{e.class}: #{e.message}")
end
begin
(version)
rescue StandardError => e
warn("Failed to update Rakefile.example header: #{e.class}: #{e.message}")
end
end
run_cmd!("bin/setup") if @start_step <= 3
run_cmd!("bin/rake") if @start_step <= 4
if @start_step <= 5
appraisals_path = File.join(@root, "Appraisals")
if File.file?(appraisals_path)
puts "Appraisals detected at #{appraisals_path}. Running: bin/rake appraisal:update"
run_cmd!("bin/rake appraisal:update")
else
puts "No Appraisals file found; skipping appraisal:update"
end
end
if @start_step <= 6
ensure_git_user!
version ||= detect_version
committed = commit_release_prep!(version)
end
maybe_run_local_ci_before_push!(committed) if @start_step <= 7
if @start_step <= 8
trunk = detect_trunk_branch
feature = current_branch
puts "Trunk branch detected: #{trunk}"
ensure_trunk_synced_before_push!(trunk, feature)
end
push! if @start_step <= 9
monitor_workflows_after_push! if @start_step <= 10
if @start_step <= 11
trunk ||= detect_trunk_branch
feature ||= current_branch
merge_feature_into_trunk_and_push!(trunk, feature)
end
if @start_step <= 12
trunk ||= detect_trunk_branch
checkout!(trunk)
pull!(trunk)
end
if @start_step <= 13
if ENV.fetch("SKIP_GEM_SIGNING", "false").casecmp("false").zero?
puts "TIP: For local dry-runs or testing the release workflow, set SKIP_GEM_SIGNING=true to avoid PEM password prompts."
if Kettle::Dev::InputAdapter.tty?
print("Proceed with signing enabled? This may hang waiting for a PEM password. [y/N]: ")
ans = Kettle::Dev::InputAdapter.gets&.strip
unless ans&.downcase&.start_with?("y")
abort("Aborted. Re-run with SKIP_GEM_SIGNING=true bundle exec kettle-release (or set it in your environment).")
end
else
warn("Non-interactive shell detected (non-TTY); skipping interactive signing confirmation.")
end
end
ensure_signing_setup_or_skip!
end
if @start_step <= 14
puts "Running build (you may be prompted for the signing key password)..."
run_cmd!("bundle exec rake build")
end
if @start_step <= 15
puts "Running release (you may be prompted for signing key password and RubyGems MFA OTP)..."
run_cmd!("bundle exec rake release")
end
if @start_step <= 16
run_cmd!("bin/gem_checksums")
version ||= detect_version
validate_checksums!(version, stage: "after release")
end
if @start_step <= 17
version ||= detect_version
maybe_create_github_release!(version)
end
push_tags! if @start_step <= 18
begin
version ||= detect_version
gem_name = detect_gem_name
puts "\nš Release #{gem_name} v#{version} Complete š"
rescue StandardError => e
Kettle::Dev.debug_error(e, __method__)
puts "\nš Release v#{version || "unknown"} Complete š"
end
end
|