|
21 | 21 | end |
22 | 22 | end |
23 | 23 |
|
| 24 | + it 'ignores Ruby setup output immediately after Ruby setup' do |
| 25 | + setup = steps.index { |step| step['id'] == 'setup_ruby' } |
| 26 | + ignore = steps.find { |step| step['id'] == 'ignore_ruby_setup_output' } |
| 27 | + expect(steps.index(ignore)).to eq(setup + 1) |
| 28 | + expect(ignore).to include('shell' => 'bash') |
| 29 | + expect(ignore).not_to have_key('if') |
| 30 | + end |
| 31 | + |
| 32 | + it 'leaves only the project files for the clean-checkout check after Ruby setup', :aggregate_failures do |
| 33 | + expect(setup_output_status(files: %w[Gemfile])).to eq([]) |
| 34 | + expect(setup_output_status(files: %w[Gemfile Gemfile.lock])).to eq([' M Gemfile.lock']) |
| 35 | + expect(setup_output_status(files: %w[Gemfile], untracked: %w[notes.txt])).to eq(['?? notes.txt']) |
| 36 | + expect(setup_output_status(files: %w[Gemfile gemfiles/release.gemfile], untracked: %w[Gemfile.lock], env: { 'BUNDLE_GEMFILE' => 'gemfiles/release.gemfile' })).to eq(['?? Gemfile.lock']) |
| 37 | + expect(setup_output_status(files: %w[gemfiles/release.gemfile], env: ->(root) { { 'BUNDLE_GEMFILE' => File.join(root, 'gemfiles/release.gemfile') } })).to eq([]) |
| 38 | + expect(setup_output_status(files: %w[gems.rb], lockfile: 'gems.locked')).to eq([]) |
| 39 | + expect(setup_output_status(files: %w[Gemfile], untracked: %w[Gemfile.lock], lockfile: 'locks/[ci]*.lock', env: { 'BUNDLE_LOCKFILE' => 'locks/[ci]*.lock' })).to eq(['?? Gemfile.lock']) |
| 40 | + end |
| 41 | + |
24 | 42 | it 'checks release prerequisites after capture, before validation, edits, or publication' do |
25 | 43 | preflight = steps.find { |step| step['id'] == 'check_release_prerequisites' } |
26 | 44 | expect(preflight.fetch('run')).to eq('bundle exec rake release:workflow:preflight') |
|
108 | 126 | end |
109 | 127 | end |
110 | 128 |
|
| 129 | + # Commits the project files to a fresh repository, adds the untracked ones, |
| 130 | + # runs the ignore step, simulates what `ruby/setup-ruby` writes, and returns |
| 131 | + # what `git status` reports. |
| 132 | + def setup_output_status(files:, untracked: [], env: {}, lockfile: nil) |
| 133 | + Dir.mktmpdir do |root| |
| 134 | + root = File.realpath(root) |
| 135 | + create_repository(root, files, untracked) |
| 136 | + values = ENV.to_h.slice('PATH', 'HOME', 'TMPDIR').merge(env.respond_to?(:call) ? env.call(root) : env) |
| 137 | + run_ignore_step(root, values) |
| 138 | + write_files(root, setup_output(root, values, lockfile)) |
| 139 | + git(root, 'status', '--porcelain', '--untracked-files=all').lines.map(&:chomp) |
| 140 | + end |
| 141 | + end |
| 142 | + |
| 143 | + def create_repository(root, files, untracked) |
| 144 | + git(root, 'init', '-q') |
| 145 | + write_files(root, files + untracked) |
| 146 | + git(root, 'add', '--', *files) |
| 147 | + git(root, '-c', 'user.name=spec', '-c', 'user.email=spec@example.com', 'commit', '-q', '-m', 'initial') |
| 148 | + end |
| 149 | + |
| 150 | + def setup_output(root, values, lockfile) |
| 151 | + gemfile = values.fetch('BUNDLE_GEMFILE', 'Gemfile').delete_prefix("#{root}/") |
| 152 | + ['vendor/bundle/ruby/3.3.0/gems/rake/rake.rb', '.bundle/config', lockfile || "#{gemfile}.lock"] |
| 153 | + end |
| 154 | + |
| 155 | + def run_ignore_step(root, values) |
| 156 | + script = steps.find { |step| step['id'] == 'ignore_ruby_setup_output' }.fetch('run') |
| 157 | + _output, error, status = Open3.capture3(values, 'bash', '-euo', 'pipefail', '-c', script, chdir: root, unsetenv_others: true) |
| 158 | + raise error unless status.success? |
| 159 | + end |
| 160 | + |
| 161 | + def write_files(root, files) |
| 162 | + files.each do |file| |
| 163 | + FileUtils.mkdir_p(File.dirname(File.join(root, file))) |
| 164 | + File.write(File.join(root, file), "# #{file}\n", mode: 'a') |
| 165 | + end |
| 166 | + end |
| 167 | + |
| 168 | + def git(root, *) |
| 169 | + output, error, status = Open3.capture3('git', '-C', root, *) |
| 170 | + raise error unless status.success? |
| 171 | + |
| 172 | + output |
| 173 | + end |
| 174 | + |
111 | 175 | def run_step(id, directory:, command: '') |
112 | 176 | values = ENV.to_h.slice('PATH', 'HOME', 'TMPDIR').merge( |
113 | 177 | 'RUNNER_TEMP' => directory, 'RELEASE_COMMAND' => command, |
@@ -143,7 +207,9 @@ def run_step(id, directory:, command: '') |
143 | 207 | preflight = workflow.dig('jobs', 'preflight') |
144 | 208 | expect(preflight).to include('if' => '${{ inputs.dry-run }}', 'environment' => 'release') |
145 | 209 | expect(preflight.dig('env', 'RUBYGEMS_OWNER_ID')).to eq('${{ inputs.rubygems-owner }}') |
146 | | - expect(preflight.fetch('steps').map { |step| step['run'] }.compact).to eq(['bundle exec rake release:workflow:capture', 'bundle exec rake release:workflow:preflight']) |
| 210 | + expect(preflight.fetch('steps').map { |step| step['id'] }).to eq(%w[checkout setup_ruby ignore_ruby_setup_output capture_release_context check_release_prerequisites]) |
| 211 | + expect(preflight.fetch('steps').find { |step| step['id'] == 'ignore_ruby_setup_output' }).to eq(steps.find { |step| step['id'] == 'ignore_ruby_setup_output' }) |
| 212 | + expect(preflight.fetch('steps').map { |step| step['run'] }.compact.drop(1)).to eq(['bundle exec rake release:workflow:capture', 'bundle exec rake release:workflow:preflight']) |
147 | 213 | expect(preflight.fetch('env')).to eq(workflow.dig('jobs', 'release', 'env')) |
148 | 214 | expect(preflight.fetch('steps').last).to eq(steps.find { |step| step['id'] == 'check_release_prerequisites' }) |
149 | 215 | end |
|
0 commit comments