ruby-gem-release 0.5.1 → 0.6.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: 6147db94530ebf0d53d63e1988df089cf1d9442721f3d5a45384731e308d5c91
4
- data.tar.gz: c5ebef85abb8868a7cfa8f0316a5be602b359443140f399e981b2060f4b59404
3
+ metadata.gz: 6ef326bc606b9d966fa15697bd078438b4d4afa90f85126ceccae0fba679dab1
4
+ data.tar.gz: a4272a4fadf4ab595677181e1cbd779f3b7a359da9b9ea73ed8e1b695fe16a0a
5
5
  SHA512:
6
- metadata.gz: 11ef16efd08c2a7c87c3c3f758b391b20c258bc3bc4b14e1a7a77299a27a971a8746c636aea9035e0d3fe87c87594c9c06829c64d80ff4ab877b28e09e2f1cb5
7
- data.tar.gz: c17e11145abae06232754512046f5212c35309da77feef552e11d730e3cc4fb5bc70133c5f44b4df6334f5d586f8f1d8f54d13f3e9962d6243a29e28238304f6
6
+ metadata.gz: 7801b51e766bf896fd4112fbfb6ab983746d97bb528831f5665f945f6273d11834980f024fdc72c05adaf16d9fa1f2f2158f88e027f13c9d0ab764e5bf58ca97
7
+ data.tar.gz: c6268c91f1fb9eeaddea3a19dbae5afea1ac2f98f316eec29d0f94ac375e66cc1b70ebbce1f73c42d6c7ea56bfe9d5003bdbce1ae77acba8ed42f7e87cf8457f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 (2026/11/11)
4
+
5
+ - [#50](https://github.com/dblock/ruby-gem-release/pull/50): Add optional release spec helpers, local publication adapters, and a complete example for testing project-specific release customizations in isolated repositories - [@dblock](https://github.com/dblock).
6
+ - [#51](https://github.com/dblock/ruby-gem-release/pull/51): Carry changelog subsections into the next release and remove multiple contribution placeholders - [@dblock](https://github.com/dblock).
7
+ - [#52](https://github.com/dblock/ruby-gem-release/pull/52): Support configured contribution placeholders and complete category templates in Keep a Changelog releases - [@dblock](https://github.com/dblock).
8
+ - [#53](https://github.com/dblock/ruby-gem-release/pull/53): Add Markdown section replacement and text substitution for project-specific release documentation - [@dblock](https://github.com/dblock).
9
+ - [#54](https://github.com/dblock/ruby-gem-release/pull/54): Add whole-project or selected fixture file copying to the optional release spec helper - [@dblock](https://github.com/dblock).
10
+ - [#55](https://github.com/dblock/ruby-gem-release/pull/55): Run full and integration specs concurrently while retaining isolated release processes and combined coverage - [@dblock](https://github.com/dblock).
11
+ - [#56](https://github.com/dblock/ruby-gem-release/pull/56): Configure isolated release fixtures from project workflow builders with local test adapters - [@dblock](https://github.com/dblock).
12
+ - [#57](https://github.com/dblock/ruby-gem-release/pull/57): Support relative globs and mixed file selectors when copying release spec fixtures - [@dblock](https://github.com/dblock).
13
+
3
14
  ## 0.5.1 (2026/11/10)
4
15
 
5
16
  - [#49](https://github.com/dblock/ruby-gem-release/pull/49): Add ordered lifecycle hooks to standard and semantic workflows, trusted preparation hooks, structured hook failure details, a consumer customization example, and real-Git coverage - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -53,7 +53,7 @@ permissions:
53
53
 
54
54
  jobs:
55
55
  release:
56
- uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.5.0
56
+ uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.5.1
57
57
  with:
58
58
  ruby-version: '3.3'
59
59
  version: ${{ inputs.version }}
@@ -104,6 +104,7 @@ Replace only what you need. The [standard workflow](docs/workflow/ruby_gem.md) p
104
104
  - **Release hosting:** Replace or disable [GitHub Release creation](docs/workflow/ruby_gem.md#hosting) without changing package publication or Git operations.
105
105
  - **Execution platforms:** Supply an [execution provider](docs/execution_provider.md) for environment transport, metadata, temporary storage, and authentication services. GitHub Actions is the only built-in external platform; another platform needs its own adapter and pipeline.
106
106
  - **Actions integration:** Override commands, inputs, and timezone through the [Actions Reference](docs/actions/release.md), or use the [Composite Action](docs/actions/action.md) inside a caller-owned job.
107
+ - **Testing customizations:** Use optional [RSpec helpers and local publication adapters](docs/testing.md) to verify project-specific release behavior and catch regressions in release-managed files.
107
108
 
108
109
  Execution platform, registry, and hosting are independent choices.
109
110
 
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
- require 'commonmarker'
4
+ require_relative '../markdown/source'
5
5
 
6
6
  module RubyGemRelease
7
7
  module Changelog
8
8
  class Base
9
+ include Markdown::Source
10
+
9
11
  def initialize(path: 'CHANGELOG.md')
10
12
  @path = path
11
13
  end
@@ -44,38 +46,6 @@ module RubyGemRelease
44
46
  content[line_end(content, position, separator)...section_end]
45
47
  end
46
48
 
47
- def heading(content, pattern)
48
- matches = heading_positions(content, pattern)
49
- raise ArgumentError, "expected exactly one matching heading in #{@path}" unless matches.one?
50
-
51
- matches.first
52
- end
53
-
54
- def heading_positions(content, pattern, max_level: 6)
55
- lines = content.lines
56
- offsets = line_offsets(lines)
57
- matches = []
58
- document(content).each do |node|
59
- next unless node.type == :heading && node.header_level <= max_level
60
-
61
- index = node.source_position[:start_line] - 1
62
- matches << offsets[index] if pattern.match?(lines[index].chomp)
63
- end
64
- matches
65
- end
66
-
67
- def heading_prefix(content, position)
68
- content[position, 6][/\A#+/]
69
- end
70
-
71
- def section_end_position(content, position, level)
72
- heading_positions(content, /\A\#{1,6} /, max_level: level).find { |offset| offset > position } || content.length
73
- end
74
-
75
- def line_end(content, position, separator)
76
- content.index(separator, position) || raise(ArgumentError, "heading must end with a newline in #{@path}")
77
- end
78
-
79
49
  def check_release_notes(content, position, separator, version)
80
50
  section_end = section_end_position(content, position, heading_prefix(content, position).length)
81
51
  check_notes(content[line_end(content, position, separator)...section_end], version)
@@ -103,19 +73,6 @@ module RubyGemRelease
103
73
  end
104
74
  end
105
75
 
106
- def document(content)
107
- Commonmarker.parse(content, options: { extension: { shortcodes: false } })
108
- end
109
-
110
- def line_offsets(lines)
111
- offset = 0
112
- lines.map do |line|
113
- position = offset
114
- offset += line.length
115
- position
116
- end
117
- end
118
-
119
76
  def excluded_lines(content)
120
77
  excluded = Set.new
121
78
  document(content).walk do |node|
@@ -127,12 +84,6 @@ module RubyGemRelease
127
84
  excluded
128
85
  end
129
86
 
130
- def newline(content)
131
- raise ArgumentError, "mixed or unsupported line endings in #{@path}" if (content.match?(/(?<!\r)\n/) && content.include?("\r\n")) || content.match?(/\r(?!\n)/)
132
-
133
- content.include?("\r\n") ? "\r\n" : "\n"
134
- end
135
-
136
87
  def validate_version(version)
137
88
  raise ArgumentError, "invalid version: #{version.inspect}" unless version.is_a?(String) && /\A(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\z/.match?(version)
138
89
  end
@@ -43,8 +43,12 @@ module RubyGemRelease
43
43
  return if heading_positions(content, /\A\#{1,6} #{Regexp.escape(version)} \(Next\)\z/).one?
44
44
 
45
45
  check_absent(content, UNRELEASED, 'unreleased heading already exists')
46
+ write_next_section(content, position, prefix, version, separator)
47
+ end
46
48
 
47
- File.write(@path, content.insert(position, ["#{prefix} #{version} (Next)", '', @placeholder, '', ''].join(separator)))
49
+ def write_next_section(content, position, prefix, version, separator)
50
+ subsections = subsection_headings(content, position, prefix.length)
51
+ File.write(@path, content.insert(position, build_next_section(prefix, version, subsections, separator)))
48
52
  end
49
53
 
50
54
  def check_release_absent(content, version)
@@ -62,13 +66,38 @@ module RubyGemRelease
62
66
  def remove_placeholder(section, separator)
63
67
  positions = []
64
68
  editable_lines(section) { |line, offset| positions << offset if line.chomp == @placeholder }
65
- raise ArgumentError, "expected exactly one placeholder in #{@path}" unless positions.one?
69
+ raise ArgumentError, "expected at least one placeholder in #{@path}" if positions.empty?
66
70
 
67
- position = positions.first
68
- section.slice!(position, placeholder_length(section, position, separator))
71
+ positions.reverse_each { |position| section.slice!(position, placeholder_length(section, position, separator)) }
69
72
  section
70
73
  end
71
74
 
75
+ def subsection_headings(content, position, level)
76
+ section_end = section_end_position(content, position, level)
77
+ lines = content.lines
78
+ offsets = line_offsets(lines)
79
+ subsection_heading_lines(content, level).filter_map do |index|
80
+ lines[index].chomp if (position...section_end).cover?(offsets[index])
81
+ end
82
+ end
83
+
84
+ def subsection_heading_lines(content, level)
85
+ document(content).each.filter_map do |node|
86
+ node.source_position[:start_line] - 1 if node.type == :heading && node.header_level == level + 1
87
+ end
88
+ end
89
+
90
+ def build_next_section(prefix, version, subsections, separator)
91
+ lines = ["#{prefix} #{version} (Next)"]
92
+ if subsections.empty?
93
+ lines.push('', @placeholder, '', '')
94
+ else
95
+ subsections.each { |subsection| lines.push('', subsection, '', @placeholder) }
96
+ lines.push('', '')
97
+ end
98
+ lines.join(separator)
99
+ end
100
+
72
101
  def placeholder_length(section, position, separator)
73
102
  line_end = section.index("\n", position)
74
103
  length = (line_end ? line_end + 1 : section.length) - position
@@ -5,8 +5,24 @@ module RubyGemRelease
5
5
  class KeepAChangelog < Base
6
6
  UNRELEASED = /\A\#{1,6} \[Unreleased\]\z/
7
7
 
8
+ def initialize(path: 'CHANGELOG.md', placeholder: nil, sections: [])
9
+ validate_template(placeholder, sections)
10
+ super(path: path)
11
+ @placeholder = placeholder
12
+ @sections = sections.dup
13
+ end
14
+
8
15
  private
9
16
 
17
+ def validate_template(placeholder, sections)
18
+ raise ArgumentError, 'placeholder must be a single nonempty line' unless placeholder.nil? || single_line?(placeholder)
19
+ raise ArgumentError, 'sections must be an array of unique nonempty names' unless sections.is_a?(Array) && sections.all? { |name| single_line?(name) } && sections.uniq == sections
20
+ end
21
+
22
+ def single_line?(value)
23
+ value.is_a?(String) && !value.strip.empty? && !value.match?(/[\r\n]/)
24
+ end
25
+
10
26
  def release_pattern(version)
11
27
  /\A\#{1,6} \[#{Regexp.escape(version)}\] - \d{4}-\d{2}-\d{2}\z/
12
28
  end
@@ -14,7 +30,7 @@ module RubyGemRelease
14
30
  def unreleased_notes(content, separator)
15
31
  reference = unreleased_reference(content)
16
32
  comparison(reference[2]) if reference
17
- super
33
+ clean_notes(super, separator, heading_prefix(content, heading(content, UNRELEASED)).length)
18
34
  end
19
35
 
20
36
  def update_release(version:, date:)
@@ -23,6 +39,7 @@ module RubyGemRelease
23
39
  separator = newline(content)
24
40
  position = heading(content, UNRELEASED)
25
41
  check_absent(content, /\A\#{1,6} \[#{Regexp.escape(version)}\] - \d{4}-\d{2}-\d{2}\z/, 'release heading already exists')
42
+ clean_release_section(content, position, separator)
26
43
  content[position...line_end(content, position, separator)] = "#{heading_prefix(content, position)} [#{version}] - #{date.strftime('%Y-%m-%d')}"
27
44
  release_references(content, version, separator)
28
45
  check_release_notes(content, position, separator, version)
@@ -41,7 +58,51 @@ module RubyGemRelease
41
58
 
42
59
  check_absent(content, UNRELEASED, 'duplicate unreleased headings')
43
60
 
44
- File.write(@path, content.insert(position, ["#{prefix} [Unreleased]", '', ''].join(separator)))
61
+ File.write(@path, content.insert(position, next_section(prefix, separator)))
62
+ end
63
+
64
+ def clean_release_section(content, position, separator)
65
+ level = heading_prefix(content, position).length
66
+ start = line_end(content, position, separator)
67
+ finish = section_end_position(content, position, level)
68
+ content[start...finish] = clean_notes(content[start...finish], separator, level)
69
+ end
70
+
71
+ def clean_notes(section, separator, level)
72
+ return section unless @placeholder || @sections.any?
73
+
74
+ positions = []
75
+ editable_lines(section) { |line, offset| positions << offset if @placeholder && line.chomp == @placeholder }
76
+ positions.reverse_each { |offset| remove_line(section, offset, separator) }
77
+ remove_empty_categories(section, separator, level)
78
+ section
79
+ end
80
+
81
+ def remove_empty_categories(section, separator, level)
82
+ heading_positions(section, /\A\#{#{level + 1}} /).reverse_each do |offset|
83
+ finish = section_end_position(section, offset, level + 1)
84
+ start = section.index(separator, offset) || section.length
85
+ remove_line(section, offset, separator) unless notes?(document(section[start...finish]))
86
+ end
87
+ end
88
+
89
+ def remove_line(section, offset, separator)
90
+ finish = section.index(separator, offset)
91
+ length = (finish ? finish + separator.length : section.length) - offset
92
+ length += separator.length if section[0...offset].end_with?(separator * 2) && section[offset + length, separator.length] == separator
93
+ section.slice!(offset, length)
94
+ end
95
+
96
+ def next_section(prefix, separator)
97
+ raise ArgumentError, 'category headings cannot be deeper than level six' if prefix.length == 6 && @sections.any?
98
+
99
+ lines = ["#{prefix} [Unreleased]", '']
100
+ if @sections.empty?
101
+ lines.push(@placeholder, '') if @placeholder
102
+ else
103
+ @sections.each { |name| lines.push("#{prefix}# #{name}", '').concat(@placeholder ? [@placeholder, ''] : []) }
104
+ end
105
+ lines.push('').join(separator)
45
106
  end
46
107
 
47
108
  def references(content, label)
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'source'
4
+
5
+ module RubyGemRelease
6
+ module Markdown
7
+ class Section
8
+ include Source
9
+
10
+ def initialize(path:, heading:)
11
+ raise ArgumentError, 'heading must be a complete Markdown heading line' unless heading.is_a?(String) && /\A\#{1,6}[ \t]+\S[^\r\n]*\z/.match?(heading)
12
+
13
+ @path = path
14
+ @pattern = /\A#{Regexp.escape(heading)}\z/
15
+ end
16
+
17
+ def validate!
18
+ read_section
19
+ self
20
+ end
21
+
22
+ def replace!(body)
23
+ raise ArgumentError, 'section body must be a String' unless body.is_a?(String)
24
+
25
+ content, start, finish, separator = read_section
26
+ replacement = replacement_body(body, content, finish, separator)
27
+ File.write(@path, content[0...start] + replacement + content[finish..])
28
+ end
29
+
30
+ def gsub!(pattern, replacement)
31
+ content, start, finish, separator = read_section
32
+ body = content[start...finish]
33
+ return unless body.gsub!(pattern, replacement)
34
+
35
+ body = substitution_body(body, separator, following: finish < content.length)
36
+ File.write(@path, content[0...start] + body + content[finish..])
37
+ end
38
+
39
+ private
40
+
41
+ def read_section
42
+ content = File.read(@path)
43
+ separator = newline(content)
44
+ position = heading(content, @pattern)
45
+ finish = section_end_position(content, position, heading_prefix(content, position).length)
46
+ start = content.index(separator, position) || content.length
47
+ [content, start, finish, separator]
48
+ end
49
+
50
+ def replacement_body(body, content, finish, separator)
51
+ newline(body)
52
+ text = body.gsub(/\r?\n/, separator).sub(/\A(?:\r?\n)+/, '').sub(/(?:\r?\n)+\z/, '')
53
+ return separator * 2 if text.empty?
54
+
55
+ "#{separator}#{separator}#{text}#{trailing_newlines(content, finish, separator)}"
56
+ end
57
+
58
+ def substitution_body(body, separator, following:)
59
+ text = body.gsub(/\r?\n/, separator)
60
+ newline(text)
61
+ text.prepend(separator) unless text.empty? || text.start_with?(separator)
62
+ text.concat(separator) if following && !text.end_with?(separator)
63
+ text
64
+ end
65
+
66
+ def trailing_newlines(content, finish, separator)
67
+ return separator * 2 if finish < content.length
68
+
69
+ content.end_with?(separator) ? separator : ''
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'commonmarker'
4
+
5
+ module RubyGemRelease
6
+ module Markdown
7
+ module Source
8
+ private
9
+
10
+ def heading(content, pattern)
11
+ matches = heading_positions(content, pattern)
12
+ raise ArgumentError, "expected exactly one matching heading in #{@path}" unless matches.one?
13
+
14
+ matches.first
15
+ end
16
+
17
+ def heading_positions(content, pattern, max_level: 6)
18
+ lines = content.lines
19
+ offsets = line_offsets(lines)
20
+ matches = []
21
+ document(content).each do |node|
22
+ next unless node.type == :heading && node.header_level <= max_level
23
+
24
+ index = node.source_position[:start_line] - 1
25
+ matches << offsets[index] if pattern.match?(lines[index].chomp)
26
+ end
27
+ matches
28
+ end
29
+
30
+ def heading_prefix(content, position)
31
+ content[position, 6][/\A#+/]
32
+ end
33
+
34
+ def section_end_position(content, position, level)
35
+ heading_positions(content, /\A/, max_level: level).find { |offset| offset > position } || content.length
36
+ end
37
+
38
+ def line_end(content, position, separator)
39
+ content.index(separator, position) || raise(ArgumentError, "heading must end with a newline in #{@path}")
40
+ end
41
+
42
+ def document(content)
43
+ Commonmarker.parse(content, options: { extension: { shortcodes: false } })
44
+ end
45
+
46
+ def line_offsets(lines)
47
+ offset = 0
48
+ lines.map do |line|
49
+ position = offset
50
+ offset += line.length
51
+ position
52
+ end
53
+ end
54
+
55
+ def newline(content)
56
+ raise ArgumentError, "mixed or unsupported line endings in #{@path}" if (content.match?(/(?<!\r)\n/) && content.include?("\r\n")) || content.match?(/\r(?!\n)/)
57
+
58
+ content.include?("\r\n") ? "\r\n" : "\n"
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'find'
5
+ require 'json'
6
+ require 'open3'
7
+ require 'pathname'
8
+
9
+ module RubyGemRelease
10
+ module RSpec
11
+ class Project
12
+ attr_reader :directory, :checkout, :remote, :environment
13
+
14
+ def initialize(directory:)
15
+ @directory = File.expand_path(directory)
16
+ @checkout = File.join(@directory, 'checkout')
17
+ @remote = File.join(@directory, 'remote.git')
18
+ @environment = build_environment
19
+ FileUtils.mkdir_p([@checkout, @environment.fetch('RELEASE_DATA_DIR')])
20
+ initialize_git
21
+ end
22
+
23
+ def write(path, content)
24
+ destination = File.expand_path(path, @checkout)
25
+ raise ArgumentError, 'fixture files must be inside the checkout' unless destination.start_with?("#{@checkout}/")
26
+
27
+ FileUtils.mkdir_p(File.dirname(destination))
28
+ File.write(destination, content)
29
+ end
30
+
31
+ def copy_files(path:, files: nil)
32
+ source_root, destination_root = [path, @checkout].map { |directory| File.realpath(directory) }
33
+ copies = selected_files(source_root, files).map do |file|
34
+ source = copy_path(source_root, file)
35
+ raise ArgumentError, "fixture source must be a regular file: #{file}" unless File.file?(source)
36
+
37
+ [source, copy_path(destination_root, file)]
38
+ end
39
+ copies.each do |source, destination|
40
+ FileUtils.mkdir_p(File.dirname(destination))
41
+ FileUtils.copy_file(source, destination, true)
42
+ end
43
+ end
44
+
45
+ def configure_workflow(require:, builder:)
46
+ raise ArgumentError, 'workflow builder must be a constant path and method' unless builder.is_a?(String) && /\A(?:::)?[A-Z]\w*(?:::[A-Z]\w*)*\.[a-z_]\w*[!?]?\z/.match?(builder)
47
+
48
+ source = workflow_source(require)
49
+ write('Rakefile', <<~RUBY)
50
+ require 'ruby-gem-release/rspec'
51
+ require_relative #{source.dump}
52
+
53
+ #{builder}(
54
+ provider: RubyGemRelease::RSpec::Provider.new,
55
+ destination: RubyGemRelease::RSpec::Destination.new,
56
+ hosting: RubyGemRelease::RSpec::Hosting.new
57
+ ).install_tasks
58
+ RUBY
59
+ end
60
+
61
+ def commit!(message = 'Prepare release fixture')
62
+ git('add', '.')
63
+ git('commit', '--quiet', '-m', message)
64
+ git('push', '--quiet', '-u', 'origin', 'master')
65
+ end
66
+
67
+ def git(*)
68
+ output, error, status = Open3.capture3(@environment, 'git', *, chdir: @checkout, unsetenv_others: true)
69
+ raise "#{output}\n#{error}" unless status.success?
70
+
71
+ output.strip
72
+ end
73
+
74
+ def remote_file(ref, path)
75
+ git('--git-dir', @remote, 'show', "#{ref}:#{path}")
76
+ end
77
+
78
+ def run_task(name, chdir: @checkout)
79
+ output, error, status = Open3.capture3(@environment, Gem.ruby, '-S', 'bundle', 'exec', 'rake', name, chdir: chdir, unsetenv_others: true)
80
+ import_environment
81
+ return output if status.success?
82
+
83
+ @environment['RELEASE_TEST_FAILURES'] = JSON.generate([name])
84
+ raise "#{output}\n#{error}"
85
+ end
86
+
87
+ def release!(version: '', test_task: nil)
88
+ @environment['INPUT_VERSION'] = version
89
+ %w[release:workflow:capture release:validate release:prepare release:workflow:resolve].each { |name| run_task(name) }
90
+ run_task(test_task) if test_task
91
+ %w[release:workflow:checkpoint release:publish release:bump release:success].each { |name| run_task(name) }
92
+ end
93
+
94
+ private
95
+
96
+ def workflow_source(path)
97
+ raise ArgumentError, 'workflow source must be a nonempty string' unless path.is_a?(String) && !path.empty?
98
+
99
+ source = "#{path.delete_suffix('.rb')}.rb"
100
+ root = File.realpath(@checkout)
101
+ copy_path(root, source)
102
+ copy_path(root, 'Rakefile')
103
+ source
104
+ end
105
+
106
+ def selected_files(root, files)
107
+ return source_files(root) if files.nil?
108
+
109
+ available = nil
110
+ Array(files).flat_map do |file|
111
+ source = copy_path(root, file)
112
+ pattern = source.delete_prefix("#{root}/")
113
+ next pattern if File.exist?(source) || !pattern.match?(/[*?{\[]/)
114
+
115
+ available ||= source_files(root)
116
+ glob_files(pattern, available)
117
+ end.uniq
118
+ end
119
+
120
+ def glob_files(pattern, available)
121
+ matches = available.select { |file| File.fnmatch?(pattern, file, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB) }
122
+ raise ArgumentError, "fixture source must match at least one regular file: #{pattern}" if matches.empty?
123
+
124
+ matches
125
+ end
126
+
127
+ def source_files(root)
128
+ Find.find(root).filter_map do |source|
129
+ next if source == root
130
+
131
+ Find.prune if File.basename(source) == '.git'
132
+
133
+ source.delete_prefix("#{root}/") unless File.directory?(source) && !File.symlink?(source)
134
+ end
135
+ end
136
+
137
+ def copy_path(root, path)
138
+ path = File.path(path)
139
+ candidate = File.expand_path(path, root)
140
+ raise ArgumentError, 'fixture paths must be relative files inside their root' if Pathname.new(path).absolute? || !candidate.start_with?("#{root}/")
141
+
142
+ ancestor = candidate
143
+ ancestor = File.dirname(ancestor) until File.exist?(ancestor) || File.symlink?(ancestor)
144
+ resolved = File.realpath(ancestor)
145
+ raise ArgumentError, 'fixture paths must stay inside their root' unless resolved == root || resolved.start_with?("#{root}/")
146
+
147
+ check_git_metadata(root, candidate, resolved)
148
+
149
+ candidate
150
+ end
151
+
152
+ def check_git_metadata(root, *paths)
153
+ return unless paths.any? { |path| path.delete_prefix("#{root}/").split('/').include?('.git') }
154
+
155
+ raise ArgumentError, 'fixture files must not replace Git metadata'
156
+ end
157
+
158
+ def initialize_git
159
+ git('init', '--bare', '--quiet', '-b', 'master', @remote)
160
+ git('init', '--quiet', '-b', 'master')
161
+ git('config', 'user.name', 'Release Fixture')
162
+ git('config', 'user.email', 'release-fixture@example.com')
163
+ git('remote', 'add', 'origin', @remote)
164
+ end
165
+
166
+ def build_environment
167
+ ENV.to_h.slice('PATH', 'HOME', 'TMPDIR', 'LANG').merge(
168
+ ruby_environment,
169
+ 'GIT_CONFIG_NOSYSTEM' => '1', 'GIT_CONFIG_GLOBAL' => File::NULL,
170
+ 'RELEASE_DATA_DIR' => File.join(@directory, 'artifacts'),
171
+ 'RELEASE_TEST_ENVIRONMENT' => File.join(@directory, 'environment.json'),
172
+ 'SOURCE_REF' => 'refs/heads/master', 'DEFAULT_BRANCH' => 'master', 'TZ' => 'UTC'
173
+ )
174
+ end
175
+
176
+ def ruby_environment
177
+ {
178
+ 'BUNDLE_GEMFILE' => File.expand_path(ENV.fetch('RELEASE_CONSUMER_GEMFILE', ENV.fetch('BUNDLE_GEMFILE', 'Gemfile'))),
179
+ 'RUBYLIB' => ENV.fetch('RELEASE_CONSUMER_LIB', File.expand_path('../..', __dir__)),
180
+ 'GEM_HOME' => ENV.fetch('RELEASE_CONSUMER_GEM_HOME', Gem.dir),
181
+ 'GEM_PATH' => ENV.fetch('RELEASE_CONSUMER_GEM_PATH', Gem.path.join(File::PATH_SEPARATOR))
182
+ }
183
+ end
184
+
185
+ def import_environment
186
+ path = @environment.fetch('RELEASE_TEST_ENVIRONMENT')
187
+ @environment.merge!(JSON.parse(File.read(path))) if File.file?(path)
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative '../execution_provider'
5
+
6
+ module RubyGemRelease
7
+ module RSpec
8
+ class Provider < ExecutionProvider
9
+ def export(values)
10
+ super
11
+ path = fetch('RELEASE_TEST_ENVIRONMENT')
12
+ previous = File.file?(path) ? JSON.parse(File.read(path)) : {}
13
+ File.write(path, JSON.generate(previous.merge(values)))
14
+ end
15
+
16
+ def failed_steps
17
+ JSON.parse(fetch('RELEASE_TEST_FAILURES', '[]'))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+ require 'fileutils'
5
+ require_relative '../destination'
6
+
7
+ module RubyGemRelease
8
+ module RSpec
9
+ module Publication
10
+ def publish!(release, package:)
11
+ return if published?(release, package: package)
12
+ raise @failure if @failure
13
+
14
+ FileUtils.mkdir_p(@directory)
15
+ FileUtils.cp(package.artifact(release), publication_path(release))
16
+ end
17
+
18
+ def published?(release, package:)
19
+ path = publication_path(release)
20
+ return false unless File.file?(path)
21
+ raise 'Published checksum differs' unless Digest::SHA256.file(path).hexdigest == Digest::SHA256.file(package.artifact(release)).hexdigest
22
+
23
+ true
24
+ end
25
+
26
+ private
27
+
28
+ def publication_path(release)
29
+ File.join(@directory, "#{release.version}.gem")
30
+ end
31
+ end
32
+
33
+ class Destination < RubyGemRelease::Destination
34
+ include Publication
35
+
36
+ def initialize(directory: ENV.fetch('RELEASE_DATA_DIR'), failure: nil)
37
+ super()
38
+ @directory = File.join(directory, 'registry')
39
+ @failure = failure
40
+ end
41
+ end
42
+
43
+ class Hosting
44
+ include Publication
45
+
46
+ def initialize(directory: ENV.fetch('RELEASE_DATA_DIR'), failure: nil)
47
+ @directory = File.join(directory, 'hosting')
48
+ @failure = failure
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+ require_relative 'rspec/project'
5
+ require_relative 'rspec/provider'
6
+ require_relative 'rspec/publication'
7
+
8
+ module RubyGemRelease
9
+ module RSpec
10
+ def with_release_project
11
+ Dir.mktmpdir('ruby-gem-release-') do |directory|
12
+ yield Project.new(directory: directory)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyGemRelease
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gem-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
@@ -65,9 +65,15 @@ files:
65
65
  - lib/ruby-gem-release/github_api.rb
66
66
  - lib/ruby-gem-release/hosting/github_release.rb
67
67
  - lib/ruby-gem-release/hosting/github_release/existing.rb
68
+ - lib/ruby-gem-release/markdown/section.rb
69
+ - lib/ruby-gem-release/markdown/source.rb
68
70
  - lib/ruby-gem-release/package/ruby_gem.rb
69
71
  - lib/ruby-gem-release/release.rb
70
72
  - lib/ruby-gem-release/release_failure.rb
73
+ - lib/ruby-gem-release/rspec.rb
74
+ - lib/ruby-gem-release/rspec/project.rb
75
+ - lib/ruby-gem-release/rspec/provider.rb
76
+ - lib/ruby-gem-release/rspec/publication.rb
71
77
  - lib/ruby-gem-release/semantic_release.rb
72
78
  - lib/ruby-gem-release/semantic_release/conventional_commits.rb
73
79
  - lib/ruby-gem-release/semantic_release/decision.rb