kettle-dev 3.1.33 → 3.1.35

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.
@@ -50,6 +50,7 @@ module Kettle
50
50
  # @param restart_hint [String] guidance command shown on failure
51
51
  # @return [Boolean] whether all configured CI providers passed
52
52
  def monitor_all!(restart_hint: "bundle exec kettle-release --start-step 10", workflows: nil, keepalive: nil, event_recorder: nil, **options)
53
+ clear_warnings!
53
54
  # Rate limiting is recoverable: when the GitHub monitor parks for the
54
55
  # quota reset it returns :rate_limited and we re-enter it. GitLab has
55
56
  # no equivalent, so only the GitHub result drives the retry.
@@ -66,6 +67,28 @@ module Kettle
66
67
  results.all? { |result| result != false }
67
68
  end
68
69
 
70
+ WARNINGS_THREAD_KEY = :kettle_dev_ci_monitor_warnings
71
+
72
+ def clear_warnings!
73
+ Thread.current[WARNINGS_THREAD_KEY] = []
74
+ end
75
+ module_function :clear_warnings!
76
+
77
+ def record_warning(kind:, message:)
78
+ warnings = (Thread.current[WARNINGS_THREAD_KEY] ||= [])
79
+ entry = {kind: kind.to_s, message: message.to_s}
80
+ warnings << entry unless warnings.include?(entry)
81
+ entry
82
+ end
83
+ module_function :record_warning
84
+
85
+ def take_warnings
86
+ warnings = Array(Thread.current[WARNINGS_THREAD_KEY]).dup
87
+ Thread.current[WARNINGS_THREAD_KEY] = []
88
+ warnings
89
+ end
90
+ module_function :take_warnings
91
+
69
92
  def continue_ci_failures?
70
93
  !!(Kettle::Dev::ENV_TRUE_RE =~ ENV.fetch("K_RELEASE_CI_CONTINUE", "false"))
71
94
  end
@@ -304,6 +327,19 @@ module Kettle
304
327
  head_sha = Kettle::Dev::CIHelpers.current_head_sha
305
328
  abort("Could not determine local HEAD SHA for GitHub Actions checks.") unless head_sha && !head_sha.empty?
306
329
 
330
+ owner, repo = preflight_github_ci!(
331
+ root: root,
332
+ workflows: workflows,
333
+ gh_remote: gh_remote,
334
+ url: url,
335
+ owner: owner,
336
+ repo: repo,
337
+ branch: branch,
338
+ head_sha: head_sha,
339
+ restart_hint: restart_hint,
340
+ event_recorder: event_recorder
341
+ )
342
+
307
343
  passed = {}
308
344
  failed = {}
309
345
  started = {}
@@ -549,9 +585,142 @@ module Kettle
549
585
  )
550
586
  sleep(wait)
551
587
  :rate_limited
588
+ rescue Kettle::Dev::CIConfigurationError => error
589
+ pbar&.finish unless pbar&.finished?
590
+ emit_ci_monitor_event(
591
+ event_recorder,
592
+ action: "github_preflight",
593
+ status: "failed",
594
+ provider: "github",
595
+ head_sha: head_sha,
596
+ reason: error.message
597
+ )
598
+ abort(error.message)
552
599
  end
553
600
  module_function :monitor_github_internal!
554
601
 
602
+ # Run fast preflight checks before entering the 300s workflow-start poll
603
+ # loop so expected irrecoverable states (broken workflow YAML, unpushed
604
+ # commits, nonexistent 404 repo, redirected remote, branch trigger
605
+ # mismatch, disabled Actions or workflows) are handled immediately.
606
+ # Returns the canonical [owner, repo] pair (following permanent redirects).
607
+ def preflight_github_ci!(root:, workflows:, gh_remote:, url:, owner:, repo:, branch:, head_sha:, restart_hint:, event_recorder: nil, **options)
608
+ workflow_docs = Kettle::Dev::CIHelpers.validate_workflow_yaml!(root: root, workflows: workflows)
609
+ remote_commit_confirmed = check_github_commit_pushed!(gh_remote: gh_remote, branch: branch, head_sha: head_sha)
610
+
611
+ repo_info = Kettle::Dev::CIHelpers.github_repo_info(owner: owner, repo: repo)
612
+ if repo_info && repo_info["redirected"]
613
+ canonical_full_name = repo_info["full_name"].to_s
614
+ new_owner, new_repo = canonical_full_name.split("/", 2)
615
+ if new_owner && new_repo && !new_owner.empty? && !new_repo.empty? &&
616
+ canonical_full_name.casecmp("#{owner}/#{repo}") != 0
617
+ canonical_url = Kettle::Dev::CIHelpers.rewrite_github_remote_url(url, new_owner, new_repo)
618
+ fix_cmd = "git remote set-url #{gh_remote} #{canonical_url}"
619
+ msg = "Remote '#{gh_remote}' points to #{owner}/#{repo}, which permanently redirected to #{new_owner}/#{new_repo}. " \
620
+ "Update it with: #{fix_cmd}"
621
+ warn("WARNING: #{msg}")
622
+ record_warning(kind: "ci_remote_redirect", message: msg)
623
+ emit_ci_monitor_event(
624
+ event_recorder,
625
+ action: "github_remote_redirect",
626
+ status: "warning",
627
+ provider: "github",
628
+ remote: gh_remote,
629
+ from: "#{owner}/#{repo}",
630
+ to: "#{new_owner}/#{new_repo}",
631
+ recommended_command: fix_cmd,
632
+ reason: msg
633
+ )
634
+ owner = new_owner
635
+ repo = new_repo
636
+ end
637
+ end
638
+
639
+ default_branch = repo_info && repo_info["default_branch"]
640
+ Kettle::Dev::CIHelpers.validate_workflow_triggers!(
641
+ documents: workflow_docs,
642
+ branch: branch,
643
+ default_branch: default_branch
644
+ )
645
+
646
+ if repo_info
647
+ unless remote_commit_confirmed
648
+ commit_exists = Kettle::Dev::CIHelpers.github_commit_exists?(owner: owner, repo: repo, head_sha: head_sha)
649
+ if commit_exists == false
650
+ raise(
651
+ Kettle::Dev::CIConfigurationError,
652
+ "Commit #{head_sha[0, 12]} does not exist on GitHub (#{owner}/#{repo}). " \
653
+ "Push branch '#{branch}' to '#{gh_remote}' (or resume from step 9: bundle exec kettle-release --start-step 9) before monitoring CI."
654
+ )
655
+ end
656
+ end
657
+
658
+ perms = Kettle::Dev::CIHelpers.github_actions_permissions(owner: owner, repo: repo)
659
+ if perms.is_a?(Hash) && perms["enabled"] == false
660
+ raise(
661
+ Kettle::Dev::CIConfigurationError,
662
+ "GitHub Actions is disabled for #{owner}/#{repo}. " \
663
+ "Enable Actions in repository settings, then restart from CI validation with: #{restart_hint}"
664
+ )
665
+ end
666
+
667
+ remote_workflows = Kettle::Dev::CIHelpers.github_actions_workflows(owner: owner, repo: repo)
668
+ if remote_workflows.is_a?(Array)
669
+ by_path = {}
670
+ remote_workflows.each { |entry| by_path[entry["path"].to_s] = entry if entry.is_a?(Hash) }
671
+ disabled = workflows.each_with_object([]) do |wf, list|
672
+ entry = by_path[".github/workflows/#{wf}"]
673
+ next unless entry
674
+
675
+ state = entry["state"].to_s
676
+ list << "#{wf} (#{state})" if !state.empty? && state != "active"
677
+ end
678
+ unless disabled.empty?
679
+ raise(
680
+ Kettle::Dev::CIConfigurationError,
681
+ "GitHub Actions workflow(s) are disabled for #{owner}/#{repo}: #{disabled.join(", ")}. " \
682
+ "Re-enable them in GitHub Actions, then restart from CI validation with: #{restart_hint}"
683
+ )
684
+ end
685
+ end
686
+ end
687
+
688
+ [owner, repo]
689
+ end
690
+ module_function :preflight_github_ci!
691
+
692
+ # Check via git ls-remote + rev-list whether local HEAD has unpushed commits
693
+ # relative to gh_remote/branch. Returns true when remote_sha == head_sha,
694
+ # false when unknown, and raises CIConfigurationError when definitively ahead.
695
+ def check_github_commit_pushed!(gh_remote:, branch:, head_sha:)
696
+ adapter = Kettle::Dev::GitAdapter.new
697
+ out, ok = adapter.capture(["ls-remote", gh_remote, "refs/heads/#{branch}"])
698
+ return false unless ok
699
+
700
+ remote_sha = out.to_s.strip.split(/\s+/).first
701
+ return false unless remote_sha&.match?(/\A[0-9a-f]{40}\z/i)
702
+ return true if remote_sha == head_sha
703
+
704
+ ahead_out, ahead_ok = adapter.capture(["rev-list", "--count", "#{remote_sha}..#{head_sha}"])
705
+ ahead_count = ahead_out.to_s.strip.to_i
706
+ if ahead_ok && ahead_count.positive?
707
+ raise(
708
+ Kettle::Dev::CIConfigurationError,
709
+ "Local HEAD #{head_sha[0, 12]} is #{ahead_count} commit(s) ahead of #{gh_remote}/#{branch} " \
710
+ "(#{remote_sha[0, 12]}) and has not been pushed. " \
711
+ "Push your commits or resume from step 9 (bundle exec kettle-release --start-step 9) before monitoring CI."
712
+ )
713
+ end
714
+
715
+ false
716
+ rescue Kettle::Dev::CIConfigurationError
717
+ raise
718
+ rescue => error
719
+ Kettle::Dev.debug_error(error, __method__)
720
+ false
721
+ end
722
+ module_function :check_github_commit_pushed!
723
+
555
724
  def monotonic_time
556
725
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
557
726
  end
@@ -730,7 +899,7 @@ module Kettle
730
899
  ">"
731
900
  when "ok", "skipped", "continued"
732
901
  "."
733
- when "failed"
902
+ when "failed", "warning"
734
903
  "!"
735
904
  else
736
905
  "?"
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Kettle
6
+ module Dev
7
+ # Computes and updates the README KLOC badge from CHANGELOG coverage
8
+ # summaries or SimpleCov JSON coverage reports.
9
+ #
10
+ # Shared by standalone releases (kettle-release) and monorepo family
11
+ # releases (kettle-family). Guards against zero-line counts so a broken
12
+ # coverage run (0/0 lines) never overwrites a real KLOC badge with 0.000.
13
+ module KlocBadge
14
+ BADGE_PATTERN = /(\[🧮kloc-img\]:\s*https?:\/\/img\.shields\.io\/badge\/KLOC-)(\d+(?:\.\d+)?)(-[^\s]*)/
15
+ CHANGELOG_COVERAGE_PATTERN = /-\s*COVERAGE:\s*.+--\s*\d+\/(\d+)\s+lines/i
16
+
17
+ module_function
18
+
19
+ # Format a positive line count as a 3-decimal KLOC string (e.g. "2.175").
20
+ # Returns nil when line_count is nil or <= 0.
21
+ #
22
+ # @param line_count [Integer, nil]
23
+ # @return [String, nil]
24
+ def format_kloc(line_count)
25
+ count = line_count.to_i
26
+ return nil unless count > 0
27
+
28
+ format("%.3f", count.to_f / 1000.0)
29
+ end
30
+
31
+ # Extract a formatted KLOC string from a CHANGELOG version section's
32
+ # COVERAGE line. Returns nil when absent or when the denominator is 0.
33
+ #
34
+ # @param section [String, nil]
35
+ # @return [String, nil]
36
+ def kloc_from_changelog_section(section)
37
+ return nil if section.to_s.empty?
38
+
39
+ match = section.to_s.match(CHANGELOG_COVERAGE_PATTERN)
40
+ return nil unless match
41
+
42
+ format_kloc(match[1].to_i)
43
+ end
44
+
45
+ # Parse a SimpleCov coverage.json file once and return its coverage file
46
+ # map alongside the inferred project root directory, or nil on error.
47
+ #
48
+ # @param coverage_path [String, nil]
49
+ # @return [Array(Hash, String), nil]
50
+ def parse_coverage_json(coverage_path)
51
+ return nil if coverage_path.to_s.empty? || !File.file?(coverage_path)
52
+
53
+ data = JSON.parse(File.read(coverage_path))
54
+ return nil unless data.is_a?(Hash)
55
+
56
+ files = data["coverage"]
57
+ return nil unless files.is_a?(Hash)
58
+
59
+ coverage_root = File.dirname(File.dirname(File.expand_path(coverage_path)))
60
+ [files, coverage_root]
61
+ rescue JSON::ParserError, SystemCallError
62
+ nil
63
+ end
64
+
65
+ # Count total relevant (trackable) lines from an already-parsed coverage
66
+ # file map, optionally restricted to files within scope_root.
67
+ #
68
+ # @param files [Hash]
69
+ # @param scope_root [String, nil]
70
+ # @param coverage_root [String, nil]
71
+ # @return [Integer]
72
+ def lines_from_coverage_data(files, scope_root: nil, coverage_root: nil, **_options)
73
+ scoped_root = scope_root.to_s.empty? ? nil : Paths.canonical(scope_root)
74
+
75
+ total_lines = 0
76
+ files.each do |file_path, entry|
77
+ next unless entry.is_a?(Hash)
78
+ if scoped_root
79
+ next unless Paths.within?(file_path.to_s, scoped_root, base: coverage_root)
80
+ end
81
+
82
+ lines = entry["lines"]
83
+ next unless lines.is_a?(Array)
84
+
85
+ total_lines += lines.count { |value| value.is_a?(Integer) }
86
+ end
87
+ total_lines
88
+ end
89
+
90
+ # Count total relevant (trackable) lines in a SimpleCov coverage.json
91
+ # file, optionally restricted to files within scope_root.
92
+ # Returns nil when coverage_path does not exist or cannot be parsed.
93
+ #
94
+ # @param coverage_path [String, nil]
95
+ # @param scope_root [String, nil]
96
+ # @return [Integer, nil]
97
+ def lines_from_coverage_json(coverage_path, scope_root: nil, **options)
98
+ parsed = parse_coverage_json(coverage_path)
99
+ return nil unless parsed
100
+
101
+ files, coverage_root = parsed
102
+ lines_from_coverage_data(files, scope_root: scope_root, coverage_root: coverage_root, **options)
103
+ end
104
+
105
+ # Compute a formatted KLOC string from a SimpleCov coverage.json file,
106
+ # optionally scoped to files under scope_root. Returns nil when missing,
107
+ # invalid, or 0 lines.
108
+ #
109
+ # @param coverage_path [String, nil]
110
+ # @param scope_root [String, nil]
111
+ # @return [String, nil]
112
+ def kloc_from_coverage_json(coverage_path, scope_root: nil, **options)
113
+ lines = lines_from_coverage_json(coverage_path, scope_root: scope_root, **options)
114
+ return nil unless lines
115
+
116
+ format_kloc(lines)
117
+ end
118
+
119
+ # Rewrite the [🧮kloc-img] badge number in a single file.
120
+ # Returns true when the file was modified, false otherwise.
121
+ #
122
+ # @param path [String, nil]
123
+ # @param kloc_str [String, nil]
124
+ # @return [Boolean]
125
+ def update_file(path, kloc_str)
126
+ return false if path.to_s.empty? || kloc_str.to_s.empty? || !File.file?(path)
127
+
128
+ content = File.read(path)
129
+ new_content = content.gsub(BADGE_PATTERN, "\\1#{kloc_str}\\3")
130
+ return false if new_content == content
131
+
132
+ File.write(path, new_content)
133
+ true
134
+ end
135
+
136
+ # Update README.md (and README.md.example when present) under project_root.
137
+ # Returns the list of modified file paths.
138
+ #
139
+ # @param project_root [String]
140
+ # @param kloc_str [String, nil]
141
+ # @return [Array<String>]
142
+ def update_project_readmes(project_root, kloc_str, **_options)
143
+ return [] if project_root.to_s.empty? || kloc_str.to_s.empty?
144
+
145
+ updated = []
146
+ [
147
+ File.join(project_root, "README.md"),
148
+ File.join(project_root, "README.md.example")
149
+ ].each do |path|
150
+ updated << path if update_file(path, kloc_str)
151
+ end
152
+ updated
153
+ end
154
+
155
+ # Compute member-scoped KLOC from coverage_path and update README files
156
+ # under project_root. Returns the list of modified file paths.
157
+ #
158
+ # @param project_root [String]
159
+ # @param coverage_path [String]
160
+ # @param scope_root [String, nil]
161
+ # @return [Array<String>]
162
+ def update_from_coverage_json(project_root:, coverage_path:, scope_root: project_root, **options)
163
+ kloc_str = kloc_from_coverage_json(coverage_path, scope_root: scope_root, **options)
164
+ return [] unless kloc_str
165
+
166
+ update_project_readmes(project_root, kloc_str, **options)
167
+ end
168
+
169
+ # Parse coverage_path once and update README KLOC badges for each
170
+ # member root in member_roots. Returns the list of modified file paths.
171
+ #
172
+ # @param member_roots [Array<String>]
173
+ # @param coverage_path [String]
174
+ # @return [Array<String>]
175
+ def update_members_from_coverage_json(member_roots:, coverage_path:, **options)
176
+ parsed = parse_coverage_json(coverage_path)
177
+ return [] unless parsed
178
+
179
+ files, coverage_root = parsed
180
+ updated = []
181
+ Array(member_roots).each do |member_root|
182
+ lines = lines_from_coverage_data(files, scope_root: member_root, coverage_root: coverage_root, **options)
183
+ kloc_str = format_kloc(lines)
184
+ next unless kloc_str
185
+
186
+ updated.concat(update_project_readmes(member_root, kloc_str, **options))
187
+ end
188
+ updated
189
+ end
190
+ end
191
+ end
192
+ end
@@ -615,6 +615,15 @@ module Kettle
615
615
  # Fallback if detection fails for any reason
616
616
  human_output.puts "\n🚀 Release v#{version || "unknown"} Complete 🚀"
617
617
  end
618
+ print_release_warnings_summary!
619
+ end
620
+
621
+ def print_release_warnings_summary!
622
+ warnings = @diagnostics.select { |diag| diag[:severity].to_s == "warning" }
623
+ return if warnings.empty?
624
+
625
+ human_output.puts "\nWarnings:"
626
+ warnings.each { |diag| human_output.puts " - #{diag[:message]}" }
618
627
  end
619
628
 
620
629
  def normalize_appraisal_task(value)
@@ -1358,44 +1367,47 @@ module Kettle
1358
1367
  ENV.fetch("K_CHANGELOG_COVERAGE_HARD", "true").downcase != "false"
1359
1368
  end
1360
1369
 
1361
- # Update the README KLOC badge number based on the denominator in the current version's COVERAGE line in CHANGELOG.md.
1362
- # - Parses the current version section of CHANGELOG.md
1363
- # - Finds a line matching: "- COVERAGE: ... -- <tested>/<total> lines ..."
1364
- # - Computes KLOC = total / 1000.0
1365
- # - Formats with three decimals (e.g., 0.076, 2.175, 10.123)
1366
- # - Rewrites the [🧮kloc-img] badge line in README.md (and README.md.example when present)
1367
- # replacing only the numeric portion after "KLOC-" while preserving other URL params.
1370
+ # Update the README KLOC badge number based on the current version's
1371
+ # COVERAGE line in a project-local CHANGELOG.md, or a member-scoped
1372
+ # SimpleCov coverage.json when sharing a monorepo root CHANGELOG.md.
1373
+ # Never overwrites the badge when the line count is 0.
1368
1374
  def update_readme_kloc_badge!
1369
- version = detect_version
1370
- # Extract only the current version's section
1371
- section, _compare_ref, _tag_ref = extract_changelog_for_version(version)
1372
- return unless section
1375
+ kloc_str = resolved_readme_kloc
1376
+ return unless kloc_str
1377
+
1378
+ KlocBadge.update_project_readmes(@root, kloc_str)
1379
+ end
1373
1380
 
1374
- # Example match: "- COVERAGE: 97.70% -- 2125/2175 lines in 20 files"
1375
- m = section.lines.find { |l| /-\s*COVERAGE:\s*.+--\s*\d+\/(\d+)\s+lines/i.match?(l) }
1376
- return unless m
1381
+ def resolved_readme_kloc
1382
+ changelog_path = resolved_changelog_path
1383
+ if Paths.within?(changelog_path, @root)
1384
+ version = detect_version
1385
+ section, _compare_ref, _tag_ref = extract_changelog_for_version(version)
1386
+ kloc_str = KlocBadge.kloc_from_changelog_section(section)
1387
+ return kloc_str if kloc_str
1388
+ end
1377
1389
 
1378
- denom = m.match(/-\s*COVERAGE:\s*.+--\s*\d+\/(\d+)\s+lines/i)[1].to_i
1379
- kloc = denom.to_f / 1000.0
1380
- kloc_str = format("%.3f", kloc)
1390
+ coverage_json_kloc_candidates(changelog_path).each do |coverage_path|
1391
+ kloc_str = KlocBadge.kloc_from_coverage_json(coverage_path, scope_root: @root)
1392
+ return kloc_str if kloc_str
1393
+ end
1394
+ nil
1395
+ end
1381
1396
 
1382
- update_badge_number_in_file(File.join(@root, "README.md"), kloc_str)
1383
- example_path = File.join(@root, "README.md.example")
1384
- update_badge_number_in_file(example_path, kloc_str) if File.file?(example_path)
1397
+ def coverage_json_kloc_candidates(changelog_path)
1398
+ candidates = [File.join(@root, "coverage", "coverage.json")]
1399
+ coverage_root = ENV["K_CHANGELOG_COVERAGE_ROOT"].to_s.strip
1400
+ candidates << File.join(File.expand_path(coverage_root, @root), "coverage", "coverage.json") unless coverage_root.empty?
1401
+ unless Paths.within?(changelog_path, @root)
1402
+ candidates << File.join(File.dirname(changelog_path), "coverage", "coverage.json")
1403
+ end
1404
+ candidates.uniq
1385
1405
  end
1386
1406
 
1387
1407
  # Helper to update the [🧮kloc-img] badge in the given file path.
1388
1408
  # Replaces only the numeric portion after "KLOC-" keeping other URL parts intact.
1389
1409
  def update_badge_number_in_file(path, kloc_str)
1390
- return unless File.file?(path)
1391
-
1392
- content = File.read(path)
1393
- # Match the specific reference line, capture groups around the number
1394
- # Example: [🧮kloc-img]: https://img.shields.io/badge/KLOC-2.175-FFDD67.svg?style=...
1395
- new_content = content.gsub(/(\[🧮kloc-img\]:\s*https?:\/\/img\.shields\.io\/badge\/KLOC-)(\d+(?:\.\d+)?)(-[^\s]*)/, "\\1#{kloc_str}\\3")
1396
- if new_content != content
1397
- File.write(path, new_content)
1398
- end
1410
+ KlocBadge.update_file(path, kloc_str)
1399
1411
  end
1400
1412
 
1401
1413
  # Update Rakefile.example banner to include current gem version and current date.
@@ -1598,6 +1610,12 @@ module Kettle
1598
1610
  rescue => error
1599
1611
  emit_ci_monitor_event(action: "finish", status: "failed", workflows: @ci_workflows, restart_hint: restart_hint, reason: "#{error.class}: #{error.message}")
1600
1612
  raise
1613
+ ensure
1614
+ if Kettle::Dev::CIMonitor.respond_to?(:take_warnings)
1615
+ Kettle::Dev::CIMonitor.take_warnings.each do |warning|
1616
+ record_diagnostic(warning[:kind], warning[:message], severity: "warning", blocking: false)
1617
+ end
1618
+ end
1601
1619
  end
1602
1620
  end
1603
1621
 
@@ -2588,35 +2606,64 @@ module Kettle
2588
2606
  success = @git.push("all", branch)
2589
2607
  unless success
2590
2608
  warn("Normal push to 'all' failed; retrying with force push...")
2591
- @git.push("all", branch, force: true)
2609
+ success = @git.push("all", branch, force: true)
2592
2610
  end
2611
+ return if success
2612
+
2613
+ remotes = individual_push_remotes
2614
+ if remotes.empty?
2615
+ abort("Failed to push #{branch} to remote 'all'. Fix remote connectivity/permissions and resume with: bundle exec kettle-release --start-step 9")
2616
+ end
2617
+
2618
+ warn("Push to aggregate remote 'all' failed; falling back to active individual remotes: #{remotes.join(", ")}")
2619
+ push_individual_remotes!(remotes, branch)
2593
2620
  return
2594
2621
  end
2595
2622
 
2596
- remotes = []
2597
- remotes << "origin" if has_remote?("origin") && !skipped_remote?("origin")
2598
- remotes |= github_remote_candidates
2599
- remotes |= gitlab_remote_candidates
2600
- remotes |= codeberg_remote_candidates
2601
- remotes.uniq!
2602
-
2623
+ remotes = individual_push_remotes
2603
2624
  if remotes.empty?
2604
2625
  puts "$ git push #{branch}"
2605
2626
  success = @git.push(nil, branch)
2606
2627
  unless success
2607
2628
  warn("Normal push failed; retrying with force push...")
2608
- @git.push(nil, branch, force: true)
2629
+ success = @git.push(nil, branch, force: true)
2609
2630
  end
2610
- return
2631
+ return if success
2632
+
2633
+ abort("Failed to push #{branch}. Fix remote connectivity/permissions and resume with: bundle exec kettle-release --start-step 9")
2611
2634
  end
2612
2635
 
2636
+ push_individual_remotes!(remotes, branch)
2637
+ end
2638
+
2639
+ def individual_push_remotes
2640
+ remotes = []
2641
+ remotes << "origin" if has_remote?("origin") && !skipped_remote?("origin")
2642
+ remotes |= github_remote_candidates
2643
+ remotes |= gitlab_remote_candidates
2644
+ remotes |= codeberg_remote_candidates
2645
+ remotes.delete("all")
2646
+ remotes.uniq
2647
+ end
2648
+
2649
+ def push_individual_remotes!(remotes, branch)
2613
2650
  remotes.each do |remote|
2614
2651
  puts "$ git push #{remote} #{branch}"
2615
2652
  success = @git.push(remote, branch)
2616
2653
  unless success
2617
2654
  warn("Push to #{remote} failed; retrying with force push...")
2618
- @git.push(remote, branch, force: true)
2655
+ success = @git.push(remote, branch, force: true)
2619
2656
  end
2657
+ next if success
2658
+
2659
+ if required_remote?(remote)
2660
+ abort("Failed to push #{branch} to required remote '#{remote}'. Fix remote connectivity/permissions and resume with: bundle exec kettle-release --start-step 9")
2661
+ end
2662
+
2663
+ @skip_remotes << remote unless @skip_remotes.include?(remote)
2664
+ message = "Failed to push #{branch} to optional remote '#{remote}'; skipping this remote for this release."
2665
+ warn(message)
2666
+ record_diagnostic("release_remote_skipped", message, severity: "warning", blocking: false)
2620
2667
  end
2621
2668
  end
2622
2669
 
@@ -2926,13 +2973,15 @@ module Kettle
2926
2973
 
2927
2974
  def push_tags!
2928
2975
  # After release, push tags to remotes according to policy:
2929
- # 1) If a remote named "all" exists, push tags only to it.
2976
+ # 1) If a remote named "all" exists and no remotes were skipped, push tags to it;
2977
+ # if that fails (e.g. an optional mirror pushurl timed out), fall back to active individual remotes.
2930
2978
  # 2) Otherwise, if other remotes exist, push tags to each of them.
2931
2979
  # 3) If no remotes are configured, push tags using default remote.
2932
2980
  if use_all_remote?
2933
2981
  ok = @git.push_tags("all")
2934
- warn("Push tags to 'all' reported failure.") unless ok
2935
- return
2982
+ return if ok
2983
+
2984
+ warn("Push tags to 'all' reported failure; falling back to active individual remotes...")
2936
2985
  end
2937
2986
 
2938
2987
  remotes = active_remotes
@@ -3027,7 +3076,7 @@ module Kettle
3027
3076
  end
3028
3077
 
3029
3078
  def active_remote_candidates(candidates)
3030
- candidates.reject { |remote| skipped_remote?(remote) }
3079
+ candidates.reject { |remote| remote == "all" || skipped_remote?(remote) }
3031
3080
  end
3032
3081
 
3033
3082
  def use_all_remote?
@@ -3171,6 +3220,7 @@ module Kettle
3171
3220
  abort(remote_fetch_failure_message(remote, detail))
3172
3221
  end
3173
3222
 
3223
+ @skip_remotes << remote unless @skip_remotes.include?(remote)
3174
3224
  message = optional_remote_fetch_failure_message(remote, detail)
3175
3225
  warn(message)
3176
3226
  emit_remote_parity_event(action: "skip", remote: remote, status: "skipped", attempts: attempts, required: false, reason: detail)
@@ -5,7 +5,7 @@ module Kettle
5
5
  # Version namespace for this gem.
6
6
  module Version
7
7
  # Current gem version.
8
- VERSION = "3.1.33"
8
+ VERSION = "3.1.35"
9
9
  end
10
10
  # Current gem version exposed at the traditional constant location.
11
11
  VERSION = Version::VERSION # Traditional Constant Location
data/lib/kettle/dev.rb CHANGED
@@ -44,6 +44,7 @@ module Kettle
44
44
  autoload :GhaShaPinsCLI, "kettle/dev/gha_sha_pins_cli"
45
45
  autoload :InputAdapter, "kettle/dev/input_adapter"
46
46
  autoload :InteractiveReleaseCommand, "kettle/dev/interactive_release_command"
47
+ autoload :KlocBadge, "kettle/dev/kloc_badge"
47
48
  autoload :LockfileReset, "kettle/dev/lockfile_reset"
48
49
  autoload :MarkdownReferenceValidator, "kettle/dev/markdown_reference_validator"
49
50
  autoload :ReadmeBackers, "kettle/dev/readme_backers"
data/sig/kettle/dev.rbs CHANGED
@@ -362,6 +362,22 @@ module Kettle
362
362
  def self.block_call_to?: (Prism::Node node, Symbol method_name) -> bool
363
363
  end
364
364
 
365
+ module KlocBadge
366
+ BADGE_PATTERN: Regexp
367
+ CHANGELOG_COVERAGE_PATTERN: Regexp
368
+
369
+ def self.format_kloc: (Integer? line_count) -> String?
370
+ def self.kloc_from_changelog_section: (String? section) -> String?
371
+ def self.parse_coverage_json: (String? coverage_path) -> [Hash[String, untyped], String]?
372
+ def self.lines_from_coverage_data: (Hash[String, untyped] files, ?scope_root: String?, ?coverage_root: String?, **untyped) -> Integer
373
+ def self.lines_from_coverage_json: (String? coverage_path, ?scope_root: String?, **untyped) -> Integer?
374
+ def self.kloc_from_coverage_json: (String? coverage_path, ?scope_root: String?, **untyped) -> String?
375
+ def self.update_file: (String? path, String? kloc_str) -> bool
376
+ def self.update_project_readmes: (String project_root, String? kloc_str, **untyped) -> Array[String]
377
+ def self.update_from_coverage_json: (project_root: String, coverage_path: String, ?scope_root: String?, **untyped) -> Array[String]
378
+ def self.update_members_from_coverage_json: (member_roots: Array[String], coverage_path: String, **untyped) -> Array[String]
379
+ end
380
+
365
381
  class ReadmeBackers
366
382
  def initialize: (
367
383
  handle: String?,
@@ -387,7 +403,9 @@ module Kettle
387
403
  private
388
404
 
389
405
  def update_readme_kloc_badge!: () -> void
390
- def update_badge_number_in_file: (String path, String kloc_str) -> void
406
+ def resolved_readme_kloc: () -> String?
407
+ def coverage_json_kloc_candidates: (String changelog_path) -> Array[String]
408
+ def update_badge_number_in_file: (String path, String kloc_str) -> bool
391
409
  def update_rakefile_example_header!: (String version) -> void
392
410
  def validate_copyright_years!: () -> void
393
411
  def extract_years_from_file: (String path) -> ::Set[Integer]
data.tar.gz.sig CHANGED
Binary file