fastlane-plugin-wpmreleasetoolkit 15.2.0 → 15.3.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: 821f365e32e08a05230fbc5ae16760f128ff39eca6b8b8c99459751bc6299120
4
+ data.tar.gz: f67252ac27be73b6d8d0f54c8679d11d5c71a1f52042caa8ab97362451ff8abe
5
5
  SHA512:
6
- metadata.gz: 2096d4592bcd99537893357f1b052e659bf40a24bd907b24ea6ce9c0dd15329de58d4943d2324a4a48fd1290e0b067067a4d04330b818076a6babe740c2865c7
7
- data.tar.gz: 8d05e52b500bb9a097a5f339bb00930ef38ef2fe3712af5ba7b8244bb3442c09e64e8efbe8684b46997021c092985444b8733b35e0314755746ab8f377389849
6
+ metadata.gz: 214447b137397d1b1ed813320370eb6a2e06c15d6a7a9d8d28d063d55b9c7dd39c751d6700d537d253e222808ac132c179eec87ee893db87c430323dabee8d9a
7
+ data.tar.gz: 9eb8cef1bb2a5cd5fc96df1aa7aa5500ebc2f9eb49beb6dd345da1011741b1d823c2fc76fdc8faf14c66f94673c6b77bd526fcf2c8a470da590731756e70d6af
@@ -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
@@ -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.3.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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
@@ -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