Skip to content

Commit 57890ab

Browse files
dblockclaude
andcommitted
Select the release Gemfile
Projects that keep `ruby-gem-release` and Commonmarker out of their main bundle could not use the reusable workflow: overriding the commands was not enough, because capture, resolution, checkpoint, preflight, and failure-phase steps run `bundle exec rake release:workflow:*` in the default bundle that `ruby/setup-ruby` installs. Add a `gemfile` input that sets `BUNDLE_GEMFILE` for both jobs before Ruby setup, and an equivalent composite-action input exported before setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr
1 parent 587d27e commit 57890ab

8 files changed

Lines changed: 82 additions & 22 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ on:
99
gemspec:
1010
description: Optional gemspec path; defaults to the only root gemspec.
1111
type: string
12+
gemfile:
13+
description: Gemfile for Bundler, relative to the repository root; its lockfile must be committed or ignored.
14+
type: string
15+
default: Gemfile
1216
rubygems-owner:
1317
description: Optional RubyGems account ID for first publication with a pending trusted publisher.
1418
type: string
@@ -81,6 +85,7 @@ jobs:
8185
env:
8286
INPUT_VERSION: ${{ inputs.version }}
8387
INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }}
88+
BUNDLE_GEMFILE: ${{ inputs.gemfile }}
8489
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
8590
GIT_USER_NAME: ${{ inputs.git-user-name }}
8691
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
@@ -114,6 +119,7 @@ jobs:
114119
env:
115120
INPUT_VERSION: ${{ inputs.version }}
116121
INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }}
122+
BUNDLE_GEMFILE: ${{ inputs.gemfile }}
117123
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
118124
GIT_USER_NAME: ${{ inputs.git-user-name }}
119125
GIT_USER_EMAIL: ${{ inputs.git-user-email }}

‎.spellcheck.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ GPG
1818
HTTPS
1919
idempotence
2020
Intridea
21+
lockfile
2122
JSON
2223
JRuby
2324
LCOV

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## 0.8.1 (Next)
3+
## 0.9.0 (Next)
44

5+
- [#89](https://github.com/dblock/ruby-gem-release/pull/89): Add a `gemfile` input to the reusable workflow and composite action that selects the Gemfile every release step installs and runs in, so release-only gems can stay out of a project's main bundle - [@dblock](https://github.com/dblock).
56
- Your contribution here.
67

78
## 0.8.0 (2026/11/20)

‎action.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
gemspec:
1313
description: Optional gemspec path; defaults to the only root gemspec.
1414
default: ''
15+
gemfile:
16+
description: Optional Gemfile for Bundler, relative to the repository root; its lockfile must be committed or ignored. Empty keeps the job's BUNDLE_GEMFILE or Gemfile.
17+
default: ''
1518
rubygems-owner:
1619
description: Optional RubyGems account ID for first publication with a pending trusted publisher.
1720
default: ''
@@ -62,6 +65,15 @@ runs:
6265
id: checkout
6366
with:
6467
fetch-depth: 0
68+
- name: Select Gemfile
69+
id: select_gemfile
70+
if: ${{ inputs.gemfile != '' }}
71+
shell: bash
72+
env:
73+
RELEASE_GEMFILE: ${{ inputs.gemfile }}
74+
run: |
75+
[[ "$RELEASE_GEMFILE" != *$'\n'* && "$RELEASE_GEMFILE" != *$'\r'* ]] || { echo 'gemfile must be a single line' >&2; exit 1; }
76+
echo "BUNDLE_GEMFILE=$RELEASE_GEMFILE" >> "$GITHUB_ENV"
6577
- uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0
6678
id: setup_ruby
6779
with:

‎docs/actions/action.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The action checks out the calling repository with full history and sets up Ruby
4848
4949
## Inputs and Environment
5050
51-
Inputs, command defaults, callback semantics, and exported environment variables match the [workflow reference](release.md#inputs). Set them under the action step's `with:` mapping rather than under a reusable-workflow job. All action inputs are strings. Dispatching the sample workflow requests publication; configured environment protection rules must pass before the job runs.
51+
Inputs, command defaults, callback semantics, and exported environment variables match the [workflow reference](release.md#inputs). Set them under the action step's `with:` mapping rather than under a reusable-workflow job. All action inputs are strings. `gemfile` defaults to empty, which keeps a `BUNDLE_GEMFILE` the calling job already sets; a nonempty value is exported for all later steps before Ruby setup. Dispatching the sample workflow requests publication; configured environment protection rules must pass before the job runs.
5252

5353
For [already-reviewed source and package collections](../workflow/reviewed_ruby_gem.md), configure `Workflow::ReviewedRubyGem` in the Rakefile. Optional `prepare-artifacts` prepares explicit input archives after Ruby setup, before loading release tasks for input configuration and capture; `artifacts` adds newline-separated paths to artifact preservation. Both default to empty. Caller-provided commands retain release privileges and must use reviewed inputs.
5454

‎docs/actions/release.md‎

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ Every action the workflow uses is pinned to a commit SHA. RubyGems Trusted Publi
1010

1111
Set these under the calling job's `with:` mapping. Only `ruby-version` is required.
1212

13-
| Input | Type | Default | Behavior |
14-
| --- | --- | --- | --- |
15-
| `ruby-version` | String | Required | Ruby version used for validation and building. |
16-
| `version` | String | Empty | Selected numeric `MAJOR.MINOR.PATCH` release version, without leading zeros. Overrides the checked-in version in standard preparation. |
17-
| `gemspec` | String | Empty | Specification path, defaulting to the only root gemspec. Missing or ambiguous specifications fail. |
18-
| `rubygems-owner` | String | Empty | Numeric RubyGems account ID required for a new gem's pending trusted publisher to create it. |
19-
| `timezone` | String | `UTC` | Installed timezone identifier for the release calendar date and Git timestamp offsets. |
20-
| `prepare-artifacts` | String | Empty | Trusted command preparing explicitly selected input archives after setup, before capture. |
21-
| `artifacts` | String | Empty | Additional newline-separated artifact paths preserved before publication, alongside default paths. |
22-
| `validate` | String | `bundle exec rake release:validate` | Check release preconditions before edits; exit nonzero on failure. |
23-
| `prepare` | String | `bundle exec rake release:prepare` | Prepare release files before version resolution and testing. |
24-
| `test` | String | `bundle exec rake` | Test prepared release files before publication. |
25-
| `publish` | String | `bundle exec rake release:publish` | Commit, build, tag, publish to RubyGems, push atomically, and create a GitHub Release through the configured callback. |
26-
| `bump` | String | `bundle exec rake release:bump` | Prepare, commit, and push the next development iteration through the configured callback. |
27-
| `success` | String | `bundle exec rake release:success` | Run after publication and the next development iteration succeed. |
28-
| `failure` | String | `bundle exec rake release:failure` | Run after a release job failure, after Ruby setup. |
29-
| `git-user-name` | String | `github-actions[bot]` | Checkout-local author name for release and next development iteration commits. |
30-
| `git-user-email` | String | `github-actions[bot]@users.noreply.github.com` | Checkout-local author email for release and next development iteration commits. |
31-
| `dry-run` | Boolean | `false` | Check release prerequisites, such as RubyGems Trusted Publishing, without editing files, pushing, or publishing. See [Dry Run](#dry-run). |
13+
| Input | Type | Default | Behavior |
14+
| --- | --- | --- | --- |
15+
| `ruby-version` | String | Required | Ruby version used for validation and building. |
16+
| `version` | String | Empty | Selected numeric `MAJOR.MINOR.PATCH` release version, without leading zeros. Overrides the checked-in version in standard preparation. |
17+
| `gemspec` | String | Empty | Specification path, defaulting to the only root gemspec. Missing or ambiguous specifications fail. |
18+
| `gemfile` | String | `Gemfile` | Gemfile Bundler installs and every release step runs in, set as `BUNDLE_GEMFILE` before Ruby setup. See [Release Gemfile](#release-gemfile). |
19+
| `rubygems-owner` | String | Empty | Numeric RubyGems account ID required for a new gem's pending trusted publisher to create it. |
20+
| `timezone` | String | `UTC` | Installed timezone identifier for the release calendar date and Git timestamp offsets. |
21+
| `prepare-artifacts` | String | Empty | Trusted command preparing explicitly selected input archives after setup, before capture. |
22+
| `artifacts` | String | Empty | Additional newline-separated artifact paths preserved before publication, alongside default paths. |
23+
| `validate` | String | `bundle exec rake release:validate` | Check release preconditions before edits; exit nonzero on failure. |
24+
| `prepare` | String | `bundle exec rake release:prepare` | Prepare release files before version resolution and testing. |
25+
| `test` | String | `bundle exec rake` | Test prepared release files before publication. |
26+
| `publish` | String | `bundle exec rake release:publish` | Commit, build, tag, publish to RubyGems, push atomically, and create a GitHub Release through the configured callback. |
27+
| `bump` | String | `bundle exec rake release:bump` | Prepare, commit, and push the next development iteration through the configured callback. |
28+
| `success` | String | `bundle exec rake release:success` | Run after publication and the next development iteration succeed. |
29+
| `failure` | String | `bundle exec rake release:failure` | Run after a release job failure, after Ruby setup. |
30+
| `git-user-name` | String | `github-actions[bot]` | Checkout-local author name for release and next development iteration commits. |
31+
| `git-user-email` | String | `github-actions[bot]@users.noreply.github.com` | Checkout-local author email for release and next development iteration commits. |
32+
| `dry-run` | Boolean | `false` | Check release prerequisites, such as RubyGems Trusted Publishing, without editing files, pushing, or publishing. See [Dry Run](#dry-run). |
3233

3334
Identity values must be nonempty and contain no line breaks. They change commit attribution, not authentication or push permissions.
3435

@@ -79,6 +80,20 @@ Expose a string `version` input in the caller's `workflow_dispatch` form and for
7980

8081
Custom preparation commands and callbacks must honor the selection; resolution rejects a mismatched prepared gemspec before publication. Custom version objects must implement `read`, `set!`, and `increment!`. See [UPGRADING.md](../../UPGRADING.md) for migrations.
8182

83+
### Release Gemfile
84+
85+
To keep `ruby-gem-release` and its optional dependencies out of every contributor's and CI variant's bundle, put them in a separate Gemfile that evaluates the main one, and pass it as `gemfile:`:
86+
87+
```ruby
88+
# gemfiles/release.gemfile
89+
eval_gemfile '../Gemfile'
90+
91+
gem 'commonmarker', '~> 2.10', require: false
92+
gem 'ruby-gem-release', '0.9.0', require: false
93+
```
94+
95+
The workflow sets `BUNDLE_GEMFILE` for the whole job before `ruby/setup-ruby` installs the bundle, so the built-in `bundle exec rake release:workflow:*` steps and the default commands, including the `test` command's full suite, run in that bundle. Commit or ignore the lockfile Bundler writes next to the selected Gemfile: capture rejects an untracked lockfile as an unclean checkout. Guard the release task setup in your Rakefile with `rescue LoadError` so the main bundle can still load it without the gem.
96+
8297
### Timezone
8398

8499
Set `timezone: America/New_York` under `with:` to use Eastern Time, including daylight saving changes. UTC remains the default.

‎lib/ruby-gem-release/version.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RubyGemRelease
4-
VERSION = '0.8.1'
4+
VERSION = '0.9.0'
55
end

‎spec/workflow_interfaces_spec.rb‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ def run_step(id, directory:, command: '')
130130
expect(workflow.dig('jobs', 'release', 'env', 'TZ')).to eq('${{ inputs.timezone }}')
131131
end
132132

133+
it 'installs and runs every job in the selected Gemfile', :aggregate_failures do
134+
expect(workflow.fetch(true).dig('workflow_call', 'inputs', 'gemfile')).to include('type' => 'string', 'default' => 'Gemfile')
135+
%w[preflight release].each do |job|
136+
expect(workflow.dig('jobs', job, 'env', 'BUNDLE_GEMFILE')).to eq('${{ inputs.gemfile }}')
137+
end
138+
end
139+
133140
it 'runs only the prerequisite checks in the release environment for a dry run', :aggregate_failures do
134141
expect(workflow.dig(true, 'workflow_call', 'inputs', 'dry-run')).to include('type' => 'boolean', 'default' => false)
135142
expect(workflow.dig('jobs', 'release', 'if')).to eq('${{ !inputs.dry-run }}')
@@ -157,6 +164,24 @@ def run_step(id, directory:, command: '')
157164
it 'passes the configured timezone to input configuration' do
158165
expect(steps.find { |step| step['id'] == 'configure_release_inputs' }.dig('env', 'TZ')).to eq('${{ inputs.timezone }}')
159166
end
167+
168+
it 'exports a selected Gemfile before Ruby setup and rejects multiline values', :aggregate_failures do
169+
selection = steps.find { |step| step['id'] == 'select_gemfile' }
170+
expect(selection.fetch('if')).to eq("${{ inputs.gemfile != '' }}")
171+
expect(steps.index(selection)).to be < steps.index { |step| step['id'] == 'setup_ruby' }
172+
Dir.mktmpdir do |directory|
173+
environment = File.join(directory, 'environment')
174+
File.write(environment, '')
175+
values = ENV.to_h.slice('PATH').merge('GITHUB_ENV' => environment, 'RELEASE_GEMFILE' => 'gemfiles/release.gemfile')
176+
_output, error, status = Open3.capture3(values, 'bash', '-euo', 'pipefail', '-c', selection.fetch('run'), unsetenv_others: true)
177+
expect(status.success?).to be(true), error
178+
expect(File.read(environment)).to eq("BUNDLE_GEMFILE=gemfiles/release.gemfile\n")
179+
_output, error, status = Open3.capture3(values.merge('RELEASE_GEMFILE' => "Gemfile\nINJECTED=1"), 'bash', '-euo', 'pipefail', '-c', selection.fetch('run'), unsetenv_others: true)
180+
expect(status.success?).to be(false)
181+
expect(error).to include('single line')
182+
expect(File.read(environment)).to eq("BUNDLE_GEMFILE=gemfiles/release.gemfile\n")
183+
end
184+
end
160185
end
161186

162187
it 'pins every external action and reusable workflow to a commit with its version as a comment', :aggregate_failures do

0 commit comments

Comments
 (0)