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
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.
184 185 186 187 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 184 def initialize(check_num: 1) @check_num = (check_num || 1).to_i @check_num = 1 if @check_num < 1 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.
211 212 213 214 215 216 217 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 211 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"]).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)
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 271 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)." failures = [] urls.each do |url| print(" -> #{url} … ") ok = HTTP.head_ok?(url) if ok puts "OK" 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.
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 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 222 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.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/kettle/dev/pre_release_cli.rb', line 191 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 |