Class: Kettle::Dev::ReleaseCLI
- Inherits:
-
Object
- Object
- Kettle::Dev::ReleaseCLI
- Defined in:
- lib/kettle/dev/release_cli.rb
Constant Summary collapse
- QUIET_ENV =
{ "KETTLE_JEM_QUIET" => "true", "KETTLE_JEM_DEBUG" => "false", "KETTLE_DEV_DEBUG" => "false", "SMORG_RB_DEBUG" => "false", "DEBUG" => nil, "BUNDLE_QUIET" => "true", "BUNDLE_DEBUG" => "false", "BUNDLER_DEBUG" => "false", "BUNDLE_VERBOSE" => "false", "DEBUG_RESOLVER" => nil, "DEBUG_RESOLVER_TREE" => nil, "BUNDLER_DEBUG_RESOLVER" => nil, "BUNDLER_DEBUG_RESOLVER_TREE" => nil, "DEBUG_COMPACT_INDEX" => nil, "MOLINILLO_DEBUG" => nil, "BUNDLE_SILENCE_DEPRECATIONS" => "true", "BUNDLE_SILENCE_ROOT_WARNING" => "true", "BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES" => "true" }.freeze
- DEBUG_TRUE_VALUES =
%w[1 true yes on].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(start_step: 0, local_ci: false, version: nil, appraisal_task: nil, skip_steps: nil) ⇒ ReleaseCLI
constructor
A new instance of ReleaseCLI.
- #normalize_appraisal_task(value) ⇒ Object
- #normalize_skip_steps(value) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(start_step: 0, local_ci: false, version: nil, appraisal_task: nil, skip_steps: nil) ⇒ ReleaseCLI
Returns a new instance of ReleaseCLI.
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/kettle/dev/release_cli.rb', line 110 def initialize(start_step: 0, local_ci: false, version: nil, appraisal_task: nil, skip_steps: nil) @root = Kettle::Dev::CIHelpers.project_root @git = Kettle::Dev::GitAdapter.new @start_step = (start_step || 0).to_i @start_step = 0 if @start_step < 0 @skip_steps = normalize_skip_steps(skip_steps) @local_ci = !!local_ci @version_override = Kettle::Dev::Versioning.normalize_explicit_version(version) @appraisal_task = normalize_appraisal_task(appraisal_task || ENV["KETTLE_RELEASE_APPRAISAL_TASK"]) end |
Class Method Details
.run_cmd!(cmd) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kettle/dev/release_cli.rb', line 42 def run_cmd!(cmd) # For Bundler-invoked build/release, explicitly prefix SKIP_GEM_SIGNING so # the signing step is skipped even when Bundler scrubs ENV. # Always do this on CI to avoid interactive prompts; locally only when explicitly requested. if ENV["SKIP_GEM_SIGNING"] && /\Abundle(\s+exec)?\s+rake\s+(build|release)\b/.match?(cmd) cmd = "SKIP_GEM_SIGNING=true #{cmd}" end puts "$ #{cmd}" # Pass a plain Hash for the environment to satisfy tests and avoid ENV object oddities env_hash = command_env # Some commands are interactive (e.g., `bundle exec rake release` prompting for RubyGems MFA). # Using capture3 detaches STDIN, preventing prompts from working. For such commands, use system # so they inherit the current TTY and can read the user's input. interactive = /\Abundle(\s+exec)?\s+rake\s+release\b/.match?(cmd) || /\Agem\s+push\b/.match?(cmd) || /\A(bundle\s+exec\s+)?kettle-changelog\b/.match?(cmd) if interactive ok = system(env_hash, cmd) unless ok exit_code = $?.respond_to?(:exitstatus) ? $?.exitstatus : 1 abort("Command failed: #{cmd} (exit #{exit_code})") end return end # Non-interactive: capture output so we can surface clear diagnostics on failure stdout_str, stderr_str, status = Open3.capture3(env_hash, cmd) # Echo command output to match prior behavior $stdout.print(stdout_str) unless stdout_str.nil? || stdout_str.empty? $stderr.print(stderr_str) unless stderr_str.nil? || stderr_str.empty? unless status.success? exit_code = status.exitstatus # Keep the original prefix to avoid breaking any tooling/tests that grep for it, # but add the exit status and a brief diagnostic tail from stderr. diag = "" unless stderr_str.to_s.empty? tail = stderr_str.lines.last(20).join diag = "\n--- STDERR (last 20 lines) ---\n#{tail}".rstrip end abort("Command failed: #{cmd} (exit #{exit_code})#{diag}") end end |
Instance Method Details
#normalize_appraisal_task(value) ⇒ Object
362 363 364 365 366 367 368 369 |
# File 'lib/kettle/dev/release_cli.rb', line 362 def normalize_appraisal_task(value) task = value.to_s.strip return "appraisal:generate" if task.empty? return "appraisal:generate" if task == "generate" || task == "appraisal:generate" return "appraisal:update" if task == "update" || task == "appraisal:update" abort("Unsupported appraisal task #{value.inspect}; use appraisal:generate or appraisal:update.") end |
#normalize_skip_steps(value) ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/kettle/dev/release_cli.rb', line 371 def normalize_skip_steps(value) raw_steps = Array(value).flat_map { |part| part.to_s.split(",") }.map(&:strip).reject(&:empty?) raw_steps.map do |raw| abort("Invalid skip_steps value #{raw.inspect}; use comma-separated release step numbers from 0 to 19.") unless raw.match?(/\A\d+\z/) step = raw.to_i abort("Invalid skip_steps value #{raw.inspect}; release steps are numbered 0 to 19.") unless step.between?(0, 19) step end.uniq end |
#run ⇒ Object
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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/kettle/dev/release_cli.rb', line 121 def run run_pre_release_checks! if run_step?(0) # 1. Ensure Bundler version ā ensure_bundler_2_7_plus! if run_step?(1) version = nil committed = nil trunk = nil feature = nil # 2. Version detection and sanity checks + prompt if run_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 => e warn("[kettle-release] gem.coop release check failed: #{e.class}: #{e.}") warn(e.backtrace.first(3).map { |l| " " + l }.join("\n")) if ENV["KETTLE_DEV_DEBUG"] warn("Proceeding without gem.coop 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] # Ensure latest_for_series actually matches our current series; ignore otherwise. 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 # Determine the sanity-check target correctly for the current series. # If gem.coop has a newer overall series than our current series, only compare # against the latest published in our current series. If that cannot be determined # (e.g., offline), skip the sanity check rather than treating the overall as target. target = if (cur_series <=> overall_series) == -1 latest_for_series else latest_overall end # IMPORTANT: Never treat a higher different-series "latest_overall" as a downgrade target. # If our current series is behind overall and gem.coop does not report a latest_for_series, # then we cannot determine the correct target for this series and should skip the check. if (cur_series <=> overall_series) == -1 && target.nil? puts "Could not determine latest released version from gem.coop (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 gem.coop (offline?). Proceeding without sanity check." end else puts "Could not determine latest released version from gem.coop (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") # Initial validation: Ensure README.md and LICENSE.txt have identical sets of copyright years; also ensure current year present when matched validate_copyright_years! # Ensure README KLOC badge reflects current CHANGELOG coverage denominator begin update_readme_kloc_badge! rescue => e warn("Failed to update KLOC badge in README: #{e.class}: #{e.}") end # Update Rakefile.example header banner with current version and date begin update_rakefile_example_header!(version) rescue => e warn("Failed to update Rakefile.example header: #{e.class}: #{e.}") end end prepare_rubocop_lts_local_branch! if rubocop_lts_release_preflight_needed? # 3. bin/setup run_cmd!("bin/setup") if run_step?(3) # 4. bin/rake run_cmd!("bin/rake") if run_step?(4) # 5. appraisal:generate (optional) + canonical docs build if run_step?(5) appraisals_path = File.join(@root, "Appraisals") if File.file?(appraisals_path) puts "Appraisals detected at #{Kettle::Dev.display_path(appraisals_path)}. Running: bin/rake #{@appraisal_task}" run_cmd!("bin/rake #{@appraisal_task}") else puts "No Appraisals file found; skipping #{@appraisal_task}" end puts "Generating docs site via canonical task: bin/rake yard" run_cmd!("bin/rake yard") end # 6. git user + commit release prep if run_step?(6) ensure_git_user! version ||= detect_version committed = commit_release_prep!(version) end # 7. optional local CI via act maybe_run_local_ci_before_push!(committed, force: local_ci?) if run_step?(7) # 8. ensure trunk synced if run_step?(8) && !local_ci? trunk = detect_trunk_branch feature = current_branch puts "Trunk branch detected: #{trunk}" ensure_trunk_synced_before_push!(trunk, feature) elsif run_step?(8) puts "Local CI release mode: skipping remote trunk sync before publishing." end # 9. push branches push! if run_step?(9) && !local_ci? # 10. monitor CI after push monitor_workflows_after_push! if run_step?(10) && !local_ci? # 11. merge feature into trunk and push if run_step?(11) && !local_ci? trunk ||= detect_trunk_branch feature ||= current_branch merge_feature_into_trunk_and_push!(trunk, feature) end # 12. checkout trunk and pull if run_step?(12) && !local_ci? trunk ||= detect_trunk_branch checkout!(trunk) pull!(trunk) end # 13. signing guidance and checks if run_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? # In CI, avoid interactive prompts when no TTY is present (e.g., act or GitHub Actions "CI validation"). # Non-interactive CI runs should not abort here; later signing checks are either stubbed in tests # or will be handled explicitly by ensure_signing_setup_or_skip!. 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 # 14. build if run_step?(14) puts "Running build (you may be prompted for the signing key password)..." run_cmd!("bundle exec rake build") end # 15. release and tag if run_step?(15) if local_ci? version ||= detect_version release_gem_and_tag_locally!(version) else puts "Running release (you may be prompted for signing key password and RubyGems MFA OTP)..." run_cmd!("bundle exec rake release") end end # 16. generate checksums # Checksums are generated after release to avoid including checksums/ in gem package # Rationale: Running gem_checksums before release may commit checksums/ and cause Bundler's # release build to include them in the gem, thus altering the artifact, and invalidating the checksums. if run_step?(16) # Generate checksums for the just-built artifact, commit them, then validate run_cmd!("bin/gem_checksums") version ||= detect_version validate_checksums!(version, stage: "after release") end # 17. push checksum commit (gem_checksums already commits) if run_step?(17) push! if local_ci? end # 18. create GitHub release (optional) if run_step?(18) version ||= detect_version maybe_create_github_release!(version) end # 19. push tags to remotes (final step) if run_step?(19) && !local_ci? # Final success message begin version ||= detect_version gem_name = detect_gem_name puts "\nš Release #{gem_name} v#{version} Complete š" rescue => e Kettle::Dev.debug_error(e, __method__) # Fallback if detection fails for any reason puts "\nš Release v#{version || "unknown"} Complete š" end end |