fastlane-plugin-wpmreleasetoolkit 15.2.0 → 15.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f58be700d1b16e0f0fcf2e02e094f2b955c3867631b86e2e618d77058ee07497
4
- data.tar.gz: 4624f0dadd623572eb7fe502aeaeceb32bae95b9f5c2e3b5e6868782aa3174d2
3
+ metadata.gz: dd6cd903b356f44324f711012ffa75b7814adb1e31e1a4631e4e616bf77518d2
4
+ data.tar.gz: 95a989ce4d3e8a88855eb30d52f2c320573957d1321c5c15edd0d0f8b1695368
5
5
  SHA512:
6
- metadata.gz: 2096d4592bcd99537893357f1b052e659bf40a24bd907b24ea6ce9c0dd15329de58d4943d2324a4a48fd1290e0b067067a4d04330b818076a6babe740c2865c7
7
- data.tar.gz: 8d05e52b500bb9a097a5f339bb00930ef38ef2fe3712af5ba7b8244bb3442c09e64e8efbe8684b46997021c092985444b8733b35e0314755746ab8f377389849
6
+ metadata.gz: bdc7407060feede6dd035952dee8f90edfd28a435727a5656f9dbd8e70e968caecbfdbad1ec60c8777543568ed4ef6d1efdc2b9dc7ca3e50f3cd570535afd6b7
7
+ data.tar.gz: 5c9eeaa224d8af92149421f6591bfc8cc8fa983fabeb26ad300e358fac418e4e536d5a7864dce84f5cc9d9cd46531b5a155845fd206bcb629252616803c6299b
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fastlane/action'
4
+ require_relative 'get_prs_between_tags'
5
+ require_relative '../../helper/release_notes_helper'
6
+
7
+ module Fastlane
8
+ module Actions
9
+ class GenerateReleaseNotesFileAction < Action
10
+ def self.run(params)
11
+ UI.user_error!('An explicit previous_tag is required to generate release notes') if params[:previous_tag].to_s.empty?
12
+ version = params[:version]
13
+ UI.user_error!('Expected a numeric release version') unless version.match?(/\A\d+(?:\.\d+){0,2}\z/)
14
+
15
+ path = params[:release_notes_file_path]
16
+ contents = File.read(path)
17
+ format = params[:format]
18
+ options = params.values.except(*custom_options.map(&:key))
19
+ markdown = other_action.get_prs_between_tags(**options, fail_on_error: true)
20
+ section = Helper::ReleaseNotesHelper.format_section(version: version, markdown: markdown, format: format)
21
+ updated = Helper::ReleaseNotesHelper.update_section(contents: contents, version: version, section: section, format: format)
22
+
23
+ if params[:dry_run]
24
+ UI.message(section)
25
+ else
26
+ File.write(path, updated)
27
+ end
28
+ section
29
+ end
30
+
31
+ def self.description
32
+ 'Write generated GitHub notes to a release notes or Markdown changelog version section'
33
+ end
34
+
35
+ def self.details
36
+ <<~DETAILS
37
+ Inserts or replaces one version section using get_prs_between_tags, preserving other versions and header comments.
38
+ Defaults to the underlined version headings used in RELEASE-NOTES.txt.
39
+ Use format: :changelog and release_notes_file_path: 'CHANGELOG.md' for numeric ## version headings.
40
+ Changelog output nests generated headings beneath the version and preserves Trunk/Unreleased sections.
41
+ The existing file must contain at least one version section in the selected format.
42
+ Keeps authors, contributors, and links. Does not promote Unreleased entries or edit other versions.
43
+ Use configuration_file_path to exclude or group PRs by GitHub labels; no title markers are needed.
44
+ For a separate report, such as release testing, call get_prs_between_tags with its own configuration_file_path.
45
+ Requires an explicit previous_tag and a published target_commitish if tag_name does not exist.
46
+ Use dry_run to preview without writing. Does not commit changes.
47
+ DETAILS
48
+ end
49
+
50
+ def self.available_options
51
+ GetPrsBetweenTagsAction.available_options.reject { |option| option.key == :fail_on_error } + custom_options
52
+ end
53
+
54
+ def self.custom_options
55
+ [
56
+ FastlaneCore::ConfigItem.new(key: :version, description: 'Numeric version heading in the output file', type: String),
57
+ FastlaneCore::ConfigItem.new(key: :release_notes_file_path, description: 'Existing release notes file', type: String, default_value: 'RELEASE-NOTES.txt'),
58
+ FastlaneCore::ConfigItem.new(key: :format,
59
+ description: 'Version section format: :release_notes or :changelog',
60
+ type: Symbol,
61
+ default_value: :release_notes,
62
+ verify_block: proc do |value|
63
+ UI.user_error!('format must be :release_notes or :changelog') unless %i[release_notes changelog].include?(value)
64
+ end),
65
+ FastlaneCore::ConfigItem.new(key: :dry_run, description: 'Preview the section without writing the file', type: Boolean, default_value: false),
66
+ ]
67
+ end
68
+
69
+ private_class_method :custom_options
70
+
71
+ def self.return_value
72
+ 'The generated version section'
73
+ end
74
+
75
+ def self.authors
76
+ ['Automattic']
77
+ end
78
+
79
+ def self.is_supported?(platform)
80
+ true
81
+ end
82
+ end
83
+ end
84
+ end
@@ -15,22 +15,34 @@ module Fastlane
15
15
 
16
16
  UI.message("Verifying #{path}")
17
17
 
18
- case File.extname(path).downcase
19
- when '.app'
20
- verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization])
21
- when '.dmg'
18
+ extension = File.extname(path).downcase
19
+ if mach_o?(path)
20
+ verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization])
21
+ elsif extension == '.app'
22
+ verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization])
23
+ elsif extension == '.dmg'
24
+ UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if params[:verify_hardened_runtime]
22
25
  verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization])
23
26
  else
24
- UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles and `.dmg` disk images")
27
+ UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and Mach-O binaries")
25
28
  end
26
29
  end
27
30
 
28
31
  UI.success("Verified #{paths.length} artifact(s)")
29
32
  end
30
33
 
31
- def self.verify_app_bundle(path:, expected_authority:, verify_notarization:)
34
+ # Thin 32- and 64-bit, then universal, in both byte orders.
35
+ MACH_O_MAGIC_NUMBERS = %w[feedface feedfacf cefaedfe cffaedfe cafebabe cafebabf bebafeca bfbafeca].freeze
36
+
37
+ # Recognizes a bare binary by its content, because its name can look like it has an extension, e.g. `tool-v1.2.3`.
38
+ #
39
+ def self.mach_o?(path)
40
+ File.file?(path) && MACH_O_MAGIC_NUMBERS.include?(File.binread(path, 4).to_s.unpack1('H*'))
41
+ end
42
+
43
+ def self.verify_app_bundle(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:)
32
44
  UI.user_error!("#{path} is not signed at all") unless signed?(path, deep: true)
33
- verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil?
45
+ verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime)
34
46
 
35
47
  return unless verify_notarization
36
48
 
@@ -49,7 +61,7 @@ module Fastlane
49
61
  UI.message("Checking whether #{path} is signed. Disk images usually aren't, so a `codesign` failure due to the image being unsigned is expected and tolerated (other signature failures will still fail).")
50
62
 
51
63
  if signed?(path)
52
- verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil?
64
+ verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: false)
53
65
  verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization
54
66
  else
55
67
  UI.important("#{path} is not signed — skipping its signature checks. We expect that the app it contains is the one carrying the signature.")
@@ -58,6 +70,14 @@ module Fastlane
58
70
  verify!("#{path} has no notarization ticket stapled to it", 'xcrun', 'stapler', 'validate', path) if verify_notarization
59
71
  end
60
72
 
73
+ def self.verify_binary(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:)
74
+ UI.user_error!("#{path} is not signed at all") unless signed?(path)
75
+ verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime)
76
+
77
+ # `--type execute` rejects any bare binary, notarized or not, as `does not seem to be an app`.
78
+ verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization
79
+ end
80
+
61
81
  # Distinguishes an artifact that carries no signature at all from one whose signature is
62
82
  # broken: the former is expected for a disk image, the latter always a failure.
63
83
  #
@@ -80,11 +100,33 @@ module Fastlane
80
100
  sh(*command, error_callback: ->(_) { UI.user_error!(error_message) })
81
101
  end
82
102
 
83
- def self.verify_authority!(path:, expected_authority:)
103
+ def self.verify_signature_details!(path:, expected_authority:, verify_hardened_runtime:)
104
+ return if expected_authority.nil? && !verify_hardened_runtime
105
+
106
+ signature_details(path).each do |details|
107
+ UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.lines(chomp: true).include?("Authority=#{expected_authority}")
108
+ UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !code_directory_flags(details).include?('runtime')
109
+ end
110
+ end
111
+
112
+ # Each architecture of universal code carries its own signature, but `codesign --display`
113
+ # only shows the one matching this Mac's, so the others are displayed one at a time.
114
+ #
115
+ # @return [Array<String>] The `codesign --display` output for each architecture.
116
+ #
117
+ def self.signature_details(path)
84
118
  details = sh('codesign', '--display', '--verbose=2', path)
85
- return if details.include?("Authority=#{expected_authority}")
119
+ architectures = details[/^Format=.*Mach-O universal \(([^)]+)\)/, 1]&.split
120
+ return [details] if architectures.nil?
121
+
122
+ architectures.map { |architecture| sh('codesign', '--display', '--verbose=2', '--arch', architecture, path) }
123
+ end
86
124
 
87
- UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}")
125
+ # The flags of the CodeDirectory line, e.g. `%w[adhoc runtime]` for `flags=0x10002(adhoc,runtime)`.
126
+ # The `Executable=` line can contain `flags=` too, as part of the path.
127
+ #
128
+ def self.code_directory_flags(details)
129
+ details[/^CodeDirectory\b.*?\bflags=0x\h+\(([^)]*)\)/, 1]&.split(',') || []
88
130
  end
89
131
 
90
132
  #####################################################
@@ -99,11 +141,16 @@ module Fastlane
99
141
  <<~DETAILS
100
142
  Verify that the given macOS artifacts are signed, and optionally notarized.
101
143
 
102
- The checks that apply are picked from the artifact's extension:
144
+ The checks that apply are picked from the kind of artifact:
103
145
 
104
146
  - `.app` — the signature is valid and satisfies its designated requirement, Gatekeeper accepts
105
147
  the bundle for execution, and a notarization ticket is stapled to it.
106
148
  - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image.
149
+ - a bare Mach-O binary, whatever its name — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission.
150
+
151
+ `verify_hardened_runtime` checks that app bundles and bare binaries are signed with the hardened runtime.
152
+ Notarization requires it, so `verify_notarization` already covers it implicitly. Use this option to catch a missing hardened runtime before submitting for notarization.
153
+ It doesn't apply to disk images.
107
154
  DETAILS
108
155
  end
109
156
 
@@ -111,7 +158,7 @@ module Fastlane
111
158
  [
112
159
  FastlaneCore::ConfigItem.new(
113
160
  key: :artifact_path,
114
- description: 'The path, or list of paths, to the `.app` bundle(s) or `.dmg` disk image(s) to verify',
161
+ description: 'The path, or list of paths, to the `.app` bundle(s), `.dmg` disk image(s) or bare binaries to verify',
115
162
  type: Array,
116
163
  verify_block: proc do |value|
117
164
  UI.user_error!('`artifact_path` must be a String or an Array of Strings') unless value.all?(String)
@@ -125,9 +172,15 @@ module Fastlane
125
172
  optional: true,
126
173
  default_value: nil
127
174
  ),
175
+ FastlaneCore::ConfigItem.new(
176
+ key: :verify_hardened_runtime,
177
+ description: 'Whether to also assert that app bundles and bare binaries are signed with the hardened runtime. Disk images are skipped',
178
+ type: Boolean,
179
+ default_value: false
180
+ ),
128
181
  FastlaneCore::ConfigItem.new(
129
182
  key: :verify_notarization,
130
- description: 'Whether to also assert that the artifact is accepted by Gatekeeper and has a notarization ticket stapled to it',
183
+ description: 'Whether to also assert that the artifact is accepted by Gatekeeper and, unless it is a bare binary, has a notarization ticket stapled to it',
131
184
  type: Boolean,
132
185
  default_value: true
133
186
  ),
@@ -311,7 +311,7 @@ module Fastlane
311
311
  tag_name: tag_name,
312
312
  target_commitish: target_commitish, # Only used if no git tag named `tag_name` exists yet
313
313
  previous_tag_name: previous_tag,
314
- config_file_path: config_file_path
314
+ configuration_file_path: config_file_path
315
315
  )
316
316
  res.body
317
317
  end
@@ -3,6 +3,101 @@
3
3
  module Fastlane
4
4
  module Helper
5
5
  module ReleaseNotesHelper
6
+ VERSION_HEADING = /^\d+(?:\.\d+){0,2}\r?\n[-=]+(?:\r?\n|\z)/
7
+
8
+ # Render a version section, nesting generated Markdown headings in changelog output.
9
+ def self.format_section(version:, markdown:, format: :release_notes)
10
+ return "#{version}\n-----\n#{markdown.rstrip}\n\n" unless format == :changelog
11
+
12
+ headings = markdown_headings(markdown)
13
+ shift = [3 - (headings.map(&:last).min || 3), 0].max
14
+ markdown = markdown.dup
15
+ headings.reverse_each do |offset, level|
16
+ markdown.insert(markdown.index('#', offset), '#' * [shift, 6 - level].min)
17
+ end
18
+ "## #{version}\n\n#{markdown.rstrip}\n\n"
19
+ end
20
+
21
+ # Insert or replace one version, preserving other sections and line endings.
22
+ # @param [String] contents Existing release notes or changelog contents.
23
+ # @param [String] version The section to replace or insert.
24
+ # @param [String] section The generated version section.
25
+ # @param [Symbol] format Version heading format: :release_notes or :changelog.
26
+ # @return [String] Updated file contents.
27
+ def self.update_section(contents:, version:, section:, format: :release_notes)
28
+ if format == :changelog
29
+ offsets = markdown_headings(contents).select { |_, level| level <= 2 }.map(&:first)
30
+ sections = [0, *offsets, contents.length].uniq.each_cons(2).map { |start, finish| contents[start...finish] }
31
+ versions = sections.map { |part| part.lines.first[/\A {0,3}##[ \t]+(\d+(?:\.\d+){0,2})[ \t]*\r?\n?\z/, 1] }
32
+ else
33
+ sections = contents.split(/(?=#{VERSION_HEADING})/)
34
+ versions = sections.map { |part| part.lines.first.chomp if part.match?(VERSION_HEADING) }
35
+ end
36
+ first_version = versions.index { |value| value }
37
+ UI.user_error!('No version headings found in the release notes file') unless first_version
38
+ UI.user_error!("Duplicate release notes sections for #{version}") if versions.count(version) > 1
39
+
40
+ newline = contents.include?("\r\n") ? "\r\n" : "\n"
41
+ section = section.gsub(/\r?\n/, newline)
42
+ index = versions.index(version)
43
+ if index
44
+ sections[index] = section
45
+ else
46
+ sections.insert(first_version, section)
47
+ end
48
+ sections.join
49
+ end
50
+
51
+ # Return line offsets and levels of ATX headings, ignoring code fences and HTML comments.
52
+ def self.markdown_headings(contents)
53
+ headings = []
54
+ fence = nil
55
+ html_comment = false
56
+ offset = 0
57
+ contents.each_line do |line|
58
+ if fence
59
+ fence = nil if line.match?(/\A {0,3}#{Regexp.escape(fence[0])}{#{fence.length},}[ \t]*\r?\n?\z/)
60
+ elsif !html_comment && (match = line.match(/\A {0,3}(`{3,}(?!.*`)|~{3,})/))
61
+ fence = match[1]
62
+ else
63
+ if !html_comment && (match = line.match(/\A {0,3}(\#{1,6})(?:[ \t]+|\r?\n?\z)/))
64
+ headings << [offset, match[1].length]
65
+ end
66
+ html_comment = html_comment_open?(line, open: html_comment) unless !html_comment && line.match?(/\A(?: {4}| {0,3}\t)/)
67
+ end
68
+ offset += line.length
69
+ end
70
+ UI.user_error!('Unterminated code fence in Markdown release notes') if fence
71
+ UI.user_error!('Unterminated HTML comment in Markdown release notes') if html_comment
72
+ headings
73
+ end
74
+ private_class_method :markdown_headings
75
+
76
+ # Track comment delimiters in order, skipping matched inline code spans.
77
+ def self.html_comment_open?(line, open:)
78
+ cursor = 0
79
+ loop do
80
+ if open
81
+ closing = line.index('-->', cursor)
82
+ return true unless closing
83
+
84
+ cursor = closing + 3
85
+ open = false
86
+ else
87
+ marker = line.match(/<!--|`+/, cursor)
88
+ return false unless marker
89
+
90
+ cursor = marker.end(0)
91
+ if marker[0] == '<!--'
92
+ open = true
93
+ elsif (closing = line.match(/(?<!`)#{Regexp.escape(marker[0])}(?!`)/, cursor))
94
+ cursor = closing.end(0)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ private_class_method :html_comment_open?
100
+
6
101
  # Update the release notes file (typycally RELEASE-NOTES.txt) to add a new entry.
7
102
  #
8
103
  # @param [String] path The path to the release notes text file.
@@ -3,6 +3,6 @@
3
3
  module Fastlane
4
4
  module Wpmreleasetoolkit
5
5
  NAME = 'fastlane-plugin-wpmreleasetoolkit'
6
- VERSION = '15.2.0'
6
+ VERSION = '15.4.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-wpmreleasetoolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.2.0
4
+ version: 15.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
@@ -130,7 +130,7 @@ dependencies:
130
130
  version: '1.19'
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.19.4
133
+ version: 1.19.5
134
134
  type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  version: '1.19'
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 1.19.4
143
+ version: 1.19.5
144
144
  - !ruby/object:Gem::Dependency
145
145
  name: octokit
146
146
  requirement: !ruby/object:Gem::Requirement
@@ -300,6 +300,7 @@ files:
300
300
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_or_create_pull_request_action.rb
301
301
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb
302
302
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/firebase_login.rb
303
+ - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/generate_release_notes_file.rb
303
304
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb
304
305
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb
305
306
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb