Class: Kettle::Dev::PreReleaseCLI
- Inherits:
-
Object
- Object
- Kettle::Dev::PreReleaseCLI
- Defined in:
- lib/kettle/dev/pre_release_cli.rb
Overview
PreReleaseCLI: run pre-release checks before invoking full release workflow. Checks:
1) Ensure GitHub Actions workflow actions are pinned to current SHAs.
2) Normalize Markdown image URLs using Addressable normalization.
3) Validate Markdown image links resolve via HTTP(S) HEAD.
Usage: Kettle::Dev::PreReleaseCLI.new(check_num: 1).run
Defined Under Namespace
Modules: HTTP, Markdown Classes: ImageUrlCache
Constant Summary collapse
- IMAGE_URL_CACHE_TTL_SECONDS =
7 * 24 * 60 * 60
Instance Method Summary collapse
-
#check_github_actions_sha_pins! ⇒ void
Check 1: Ensure GitHub Actions workflow action refs are current SHA pins.
-
#check_markdown_images_http! ⇒ void
Check 3: Validate Markdown image links by HTTP HEAD (no rescue for parse failures).
-
#check_markdown_uri_normalization! ⇒ void
Check 2: Normalize Markdown image URLs Compares URLs to Addressable-normalized form and rewrites Markdown when needed.
-
#initialize(check_num: 1) ⇒ PreReleaseCLI
constructor
A new instance of PreReleaseCLI.
-
#run ⇒ void
Execute configured checks starting from @check_num.
Constructor Details
#initialize(check_num: 1) ⇒ PreReleaseCLI
Returns a new instance of PreReleaseCLI.
268 269 270 271 272 273 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 268 def initialize(check_num: 1) @check_num = (check_num || 1).to_i @check_num = 1 if @check_num < 1 @image_url_cache_path = configured_image_url_cache_path @refresh_image_url_cache = env_truthy?(ENV["KETTLE_IMAGE_URL_CACHE_REFRESH"]) end |
Instance Method Details
#check_github_actions_sha_pins! ⇒ void
This method returns an undefined value.
Check 1: Ensure GitHub Actions workflow action refs are current SHA pins.
297 298 299 300 301 302 303 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 297 def check_github_actions_sha_pins! puts "[kettle-pre-release] Check 1: Validate GitHub Actions SHA pins" status = Kettle::Dev::GhaShaPinsCLI.new(["--root", Dir.pwd, "--check", "--upgrade", "major"]).run! return nil if status.zero? Kettle::Dev::ExitAdapter.abort("GitHub Actions SHA pin validation failed") end |
#check_markdown_images_http! ⇒ void
This method returns an undefined value.
Check 3: Validate Markdown image links by HTTP HEAD (no rescue for parse failures)
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 357 def check_markdown_images_http! puts "[kettle-pre-release] Check 3: Validate Markdown image links (HTTP HEAD)" urls = Markdown.extract_image_urls_from_files puts "[kettle-pre-release] Found #{urls.size} unique image URL(s)." cache = image_url_cache failures = [] urls.each do |url| print(" -> #{url} … ") if cache && !@refresh_image_url_cache && cache.fresh_success?(url) puts "OK (cached)" next end ok = HTTP.head_ok?(url) if ok puts "OK" cache&.write_success(url) else puts "FAIL" failures << url end end if failures.any? warn("[kettle-pre-release] #{failures.size} image URL(s) failed validation:") failures.each { |u| warn(" - #{u}") } Kettle::Dev::ExitAdapter.abort("Image link validation failed") else puts "[kettle-pre-release] All image links validated." end nil end |
#check_markdown_uri_normalization! ⇒ void
This method returns an undefined value.
Check 2: Normalize Markdown image URLs
Compares URLs to Addressable-normalized form and rewrites Markdown when needed.
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 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 308 def check_markdown_uri_normalization! puts "[kettle-pre-release] Check 2: Normalize Markdown image URLs" files = Markdown.project_markdown_files changed = [] total_candidates = 0 files.each do |file| begin original = File.read(file) rescue => e warn("[kettle-pre-release] Could not read #{Kettle::Dev.display_path(file)}: #{e.class}: #{e.}") next end text = original.dup urls = Markdown.extract_image_urls_from_text(text) next if urls.empty? total_candidates += urls.size updated = text.dup modified = false urls.each do |url_str| addr = Addressable::URI.parse(url_str) normalized = addr.normalize.to_s next if normalized == url_str # Replace exact occurrences of the URL in the markdown content updated.gsub!(url_str, normalized) modified = true puts " -> #{Kettle::Dev.display_path(file)}: normalized #{url_str} -> #{normalized}" end if modified && updated != original begin File.write(file, updated) changed << file rescue => e warn("[kettle-pre-release] Could not write #{Kettle::Dev.display_path(file)}: #{e.class}: #{e.}") end end end puts "[kettle-pre-release] Normalization candidates: #{total_candidates}. Files changed: #{changed.uniq.size}." nil end |
#run ⇒ void
This method returns an undefined value.
Execute configured checks starting from @check_num.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 277 def run checks = [] checks << method(:check_github_actions_sha_pins!) checks << method(:check_markdown_uri_normalization!) checks << method(:check_markdown_images_http!) start = @check_num raise ArgumentError, "check_num must be >= 1" if start < 1 begin_idx = start - 1 checks[begin_idx..-1].each_with_index do |check, i| idx = begin_idx + i + 1 puts "[kettle-pre-release] Running check ##{idx} of #{checks.size}" check.call end nil end |