From 91b4985f6ee555ac01150dcac6f2f2492f7803c3 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Fri, 20 Nov 2026 18:28:02 -0500 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr --- .github/workflows/release.yml | 6 ++++ .spellcheck.txt | 1 + CHANGELOG.md | 3 +- action.yml | 12 ++++++++ docs/actions/action.md | 2 +- docs/actions/release.md | 53 ++++++++++++++++++++------------ lib/ruby-gem-release/version.rb | 2 +- spec/workflow_interfaces_spec.rb | 25 +++++++++++++++ 8 files changed, 82 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c27079..5f63f2a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,6 +9,10 @@ on: gemspec: description: Optional gemspec path; defaults to the only root gemspec. type: string + gemfile: + description: Gemfile for Bundler, relative to the repository root; its lockfile must be committed or ignored. + type: string + default: Gemfile rubygems-owner: description: Optional RubyGems account ID for first publication with a pending trusted publisher. type: string @@ -81,6 +85,7 @@ jobs: env: INPUT_VERSION: ${{ inputs.version }} INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }} + BUNDLE_GEMFILE: ${{ inputs.gemfile }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} GIT_USER_NAME: ${{ inputs.git-user-name }} GIT_USER_EMAIL: ${{ inputs.git-user-email }} @@ -114,6 +119,7 @@ jobs: env: INPUT_VERSION: ${{ inputs.version }} INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }} + BUNDLE_GEMFILE: ${{ inputs.gemfile }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} GIT_USER_NAME: ${{ inputs.git-user-name }} GIT_USER_EMAIL: ${{ inputs.git-user-email }} diff --git a/.spellcheck.txt b/.spellcheck.txt index 68a43ff..3540592 100644 --- a/.spellcheck.txt +++ b/.spellcheck.txt @@ -18,6 +18,7 @@ GPG HTTPS idempotence Intridea +lockfile JSON JRuby LCOV diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c645c..5780d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog -## 0.8.1 (Next) +## 0.9.0 (Next) +- [#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). - Your contribution here. ## 0.8.0 (2026/11/20) diff --git a/action.yml b/action.yml index f73f854..4cf6cec 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,9 @@ inputs: gemspec: description: Optional gemspec path; defaults to the only root gemspec. default: '' + gemfile: + 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. + default: '' rubygems-owner: description: Optional RubyGems account ID for first publication with a pending trusted publisher. default: '' @@ -62,6 +65,15 @@ runs: id: checkout with: fetch-depth: 0 + - name: Select Gemfile + id: select_gemfile + if: ${{ inputs.gemfile != '' }} + shell: bash + env: + RELEASE_GEMFILE: ${{ inputs.gemfile }} + run: | + [[ "$RELEASE_GEMFILE" != *$'\n'* && "$RELEASE_GEMFILE" != *$'\r'* ]] || { echo 'gemfile must be a single line' >&2; exit 1; } + echo "BUNDLE_GEMFILE=$RELEASE_GEMFILE" >> "$GITHUB_ENV" - uses: ruby/setup-ruby@be3c7df29b3349ec6bcfc6b4792f1cf9f5237d18 # v1.343.0 id: setup_ruby with: diff --git a/docs/actions/action.md b/docs/actions/action.md index f8023ca..bc4cb29 100644 --- a/docs/actions/action.md +++ b/docs/actions/action.md @@ -48,7 +48,7 @@ The action checks out the calling repository with full history and sets up Ruby ## Inputs and Environment -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. +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. 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. diff --git a/docs/actions/release.md b/docs/actions/release.md index a89e299..bec7076 100644 --- a/docs/actions/release.md +++ b/docs/actions/release.md @@ -10,25 +10,26 @@ Every action the workflow uses is pinned to a commit SHA. RubyGems Trusted Publi Set these under the calling job's `with:` mapping. Only `ruby-version` is required. -| Input | Type | Default | Behavior | -| --- | --- | --- | --- | -| `ruby-version` | String | Required | Ruby version used for validation and building. | -| `version` | String | Empty | Selected numeric `MAJOR.MINOR.PATCH` release version, without leading zeros. Overrides the checked-in version in standard preparation. | -| `gemspec` | String | Empty | Specification path, defaulting to the only root gemspec. Missing or ambiguous specifications fail. | -| `rubygems-owner` | String | Empty | Numeric RubyGems account ID required for a new gem's pending trusted publisher to create it. | -| `timezone` | String | `UTC` | Installed timezone identifier for the release calendar date and Git timestamp offsets. | -| `prepare-artifacts` | String | Empty | Trusted command preparing explicitly selected input archives after setup, before capture. | -| `artifacts` | String | Empty | Additional newline-separated artifact paths preserved before publication, alongside default paths. | -| `validate` | String | `bundle exec rake release:validate` | Check release preconditions before edits; exit nonzero on failure. | -| `prepare` | String | `bundle exec rake release:prepare` | Prepare release files before version resolution and testing. | -| `test` | String | `bundle exec rake` | Test prepared release files before publication. | -| `publish` | String | `bundle exec rake release:publish` | Commit, build, tag, publish to RubyGems, push atomically, and create a GitHub Release through the configured callback. | -| `bump` | String | `bundle exec rake release:bump` | Prepare, commit, and push the next development iteration through the configured callback. | -| `success` | String | `bundle exec rake release:success` | Run after publication and the next development iteration succeed. | -| `failure` | String | `bundle exec rake release:failure` | Run after a release job failure, after Ruby setup. | -| `git-user-name` | String | `github-actions[bot]` | Checkout-local author name for release and next development iteration commits. | -| `git-user-email` | String | `github-actions[bot]@users.noreply.github.com` | Checkout-local author email for release and next development iteration commits. | -| `dry-run` | Boolean | `false` | Check release prerequisites, such as RubyGems Trusted Publishing, without editing files, pushing, or publishing. See [Dry Run](#dry-run). | +| Input | Type | Default | Behavior | +| --- | --- | --- | --- | +| `ruby-version` | String | Required | Ruby version used for validation and building. | +| `version` | String | Empty | Selected numeric `MAJOR.MINOR.PATCH` release version, without leading zeros. Overrides the checked-in version in standard preparation. | +| `gemspec` | String | Empty | Specification path, defaulting to the only root gemspec. Missing or ambiguous specifications fail. | +| `gemfile` | String | `Gemfile` | Gemfile Bundler installs and every release step runs in, set as `BUNDLE_GEMFILE` before Ruby setup. See [Release Gemfile](#release-gemfile). | +| `rubygems-owner` | String | Empty | Numeric RubyGems account ID required for a new gem's pending trusted publisher to create it. | +| `timezone` | String | `UTC` | Installed timezone identifier for the release calendar date and Git timestamp offsets. | +| `prepare-artifacts` | String | Empty | Trusted command preparing explicitly selected input archives after setup, before capture. | +| `artifacts` | String | Empty | Additional newline-separated artifact paths preserved before publication, alongside default paths. | +| `validate` | String | `bundle exec rake release:validate` | Check release preconditions before edits; exit nonzero on failure. | +| `prepare` | String | `bundle exec rake release:prepare` | Prepare release files before version resolution and testing. | +| `test` | String | `bundle exec rake` | Test prepared release files before publication. | +| `publish` | String | `bundle exec rake release:publish` | Commit, build, tag, publish to RubyGems, push atomically, and create a GitHub Release through the configured callback. | +| `bump` | String | `bundle exec rake release:bump` | Prepare, commit, and push the next development iteration through the configured callback. | +| `success` | String | `bundle exec rake release:success` | Run after publication and the next development iteration succeed. | +| `failure` | String | `bundle exec rake release:failure` | Run after a release job failure, after Ruby setup. | +| `git-user-name` | String | `github-actions[bot]` | Checkout-local author name for release and next development iteration commits. | +| `git-user-email` | String | `github-actions[bot]@users.noreply.github.com` | Checkout-local author email for release and next development iteration commits. | +| `dry-run` | Boolean | `false` | Check release prerequisites, such as RubyGems Trusted Publishing, without editing files, pushing, or publishing. See [Dry Run](#dry-run). | Identity values must be nonempty and contain no line breaks. They change commit attribution, not authentication or push permissions. @@ -79,6 +80,20 @@ Expose a string `version` input in the caller's `workflow_dispatch` form and for 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. +### Release Gemfile + +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:`: + +```ruby +# gemfiles/release.gemfile +eval_gemfile '../Gemfile' + +gem 'commonmarker', '~> 2.10', require: false +gem 'ruby-gem-release', '0.9.0', require: false +``` + +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. + ### Timezone Set `timezone: America/New_York` under `with:` to use Eastern Time, including daylight saving changes. UTC remains the default. diff --git a/lib/ruby-gem-release/version.rb b/lib/ruby-gem-release/version.rb index de83fde..981cb3a 100644 --- a/lib/ruby-gem-release/version.rb +++ b/lib/ruby-gem-release/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RubyGemRelease - VERSION = '0.8.1' + VERSION = '0.9.0' end diff --git a/spec/workflow_interfaces_spec.rb b/spec/workflow_interfaces_spec.rb index 86f7816..ad5c57b 100644 --- a/spec/workflow_interfaces_spec.rb +++ b/spec/workflow_interfaces_spec.rb @@ -130,6 +130,13 @@ def run_step(id, directory:, command: '') expect(workflow.dig('jobs', 'release', 'env', 'TZ')).to eq('${{ inputs.timezone }}') end + it 'installs and runs every job in the selected Gemfile', :aggregate_failures do + expect(workflow.fetch(true).dig('workflow_call', 'inputs', 'gemfile')).to include('type' => 'string', 'default' => 'Gemfile') + %w[preflight release].each do |job| + expect(workflow.dig('jobs', job, 'env', 'BUNDLE_GEMFILE')).to eq('${{ inputs.gemfile }}') + end + end + it 'runs only the prerequisite checks in the release environment for a dry run', :aggregate_failures do expect(workflow.dig(true, 'workflow_call', 'inputs', 'dry-run')).to include('type' => 'boolean', 'default' => false) expect(workflow.dig('jobs', 'release', 'if')).to eq('${{ !inputs.dry-run }}') @@ -157,6 +164,24 @@ def run_step(id, directory:, command: '') it 'passes the configured timezone to input configuration' do expect(steps.find { |step| step['id'] == 'configure_release_inputs' }.dig('env', 'TZ')).to eq('${{ inputs.timezone }}') end + + it 'exports a selected Gemfile before Ruby setup and rejects multiline values', :aggregate_failures do + selection = steps.find { |step| step['id'] == 'select_gemfile' } + expect(selection.fetch('if')).to eq("${{ inputs.gemfile != '' }}") + expect(steps.index(selection)).to be < steps.index { |step| step['id'] == 'setup_ruby' } + Dir.mktmpdir do |directory| + environment = File.join(directory, 'environment') + File.write(environment, '') + values = ENV.to_h.slice('PATH').merge('GITHUB_ENV' => environment, 'RELEASE_GEMFILE' => 'gemfiles/release.gemfile') + _output, error, status = Open3.capture3(values, 'bash', '-euo', 'pipefail', '-c', selection.fetch('run'), unsetenv_others: true) + expect(status.success?).to be(true), error + expect(File.read(environment)).to eq("BUNDLE_GEMFILE=gemfiles/release.gemfile\n") + _output, error, status = Open3.capture3(values.merge('RELEASE_GEMFILE' => "Gemfile\nINJECTED=1"), 'bash', '-euo', 'pipefail', '-c', selection.fetch('run'), unsetenv_others: true) + expect(status.success?).to be(false) + expect(error).to include('single line') + expect(File.read(environment)).to eq("BUNDLE_GEMFILE=gemfiles/release.gemfile\n") + end + end end it 'pins every external action and reusable workflow to a commit with its version as a comment', :aggregate_failures do