Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
description: Optional release version overriding the checked-in version.
type: string
required: false
dry-run:
description: Check release prerequisites without editing files, pushing, or publishing.
type: boolean
default: false

permissions:
contents: write
Expand All @@ -20,3 +24,4 @@ jobs:
version: ${{ inputs.version }}
timezone: America/New_York
rubygems-owner: ${{ vars.RUBYGEMS_OWNER_ID }}
dry-run: ${{ inputs.dry-run }}
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,40 @@ on:
description: Command to run after a release job failure.
type: string
default: bundle exec rake release:failure
dry-run:
description: Check release prerequisites, such as RubyGems Trusted Publishing, without editing files, pushing, or publishing.
type: boolean
default: false

concurrency:
group: ruby-gem-release-${{ github.repository }}
cancel-in-progress: false

jobs:
preflight:
if: ${{ inputs.dry-run }}
runs-on: ubuntu-latest
environment: release
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }}
steps:
- uses: actions/checkout@v7
id: checkout
with:
persist-credentials: false
- uses: ruby/setup-ruby@v1
id: setup_ruby
with:
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: true
- name: Check Release Prerequisites
id: check_release_prerequisites
env:
RELEASE_STEP_ID: check_release_prerequisites
run: bundle exec rake release:workflow:preflight
release:
if: ${{ !inputs.dry-run }}
runs-on: ubuntu-latest
environment: release
env:
Expand Down Expand Up @@ -105,6 +132,11 @@ jobs:
env:
RELEASE_STEP_ID: capture_release_context
run: bundle exec rake release:workflow:capture
- name: Check Release Prerequisites
id: check_release_prerequisites
env:
RELEASE_STEP_ID: check_release_prerequisites
run: bundle exec rake release:workflow:preflight
- name: Validate Release
id: validate_release
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
- [#82](https://github.com/dblock/ruby-gem-release/pull/82): Create the default package and Git temporary directories only when release data is first used, so loading a workflow leaves none behind - [@dblock](https://github.com/dblock).
- [#83](https://github.com/dblock/ruby-gem-release/pull/83): Name Intridea subsections with `sections:`, dropping sections without notes from a release and starting every Next section with all of them - [@dblock](https://github.com/dblock).
- [#85](https://github.com/dblock/ruby-gem-release/pull/85): Verify RubyGems Trusted Publishing before every release with a `release:workflow:preflight` task, add a `dry-run` workflow input that runs only that check, and name the token claims in rejected exchanges - [@dblock](https://github.com/dblock).
- Your contribution here.

## 0.7.0 (2026/11/20)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ gh api --method PUT repos/{owner}/{repo}/environments/release

For a new gem, open the [pending trusted publishers page](https://rubygems.org/profile/oidc/pending_trusted_publishers). For an existing gem, open your existing gem's **Trusted publishers** page (e.g. `https://rubygems.org/gems/example/trusted_publishers`). Create a [trusted publisher](https://guides.rubygems.org/trusted-publishing/#using-reusable-workflows). Set the repository fields to your gem's repository, the workflow filename to `release.yml`, and the environment to `release`. Set the separate workflow repository fields to `dblock` and `ruby-gem-release`; these identify the reusable workflow RubyGems verifies in the OIDC token.

To verify this setup without releasing, dispatch a [dry run](docs/actions/release.md#dry-run).

Collaborators with write access can dispatch releases after this setup, without repository admin access or their own RubyGems credentials. Creating the environment alone does not restrict publication. Configure [required maintainer approval and deployment branches](RELEASING.md#maintainer-approved-publication) to control who approves publication.

### 4. Make a Release
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bundle exec rake build

The manual **Release** caller is [`.github/workflows/publish.yml`](.github/workflows/publish.yml). Merges and schedules do not publish. It uses Ruby 4.0, the root Rakefile, and `America/New_York` for release dates and Git timestamp offsets.

Verify the existing RubyGems trusted publisher before dispatch. The caller passes the non-secret `RUBYGEMS_OWNER_ID` repository variable when set; this identifies an account, not an API key. Pending publishers need it for first publication.
Verify the existing RubyGems trusted publisher before dispatch with a [dry run](docs/actions/release.md#dry-run), which exchanges credentials without releasing: `gh workflow run publish.yml --ref master -f dry-run=true`. The caller passes the non-secret `RUBYGEMS_OWNER_ID` repository variable when set; this identifies an account, not an API key. Pending publishers need it for first publication.

Only after explicit authorization, successful validation, and confirmed setup:

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ runs:
env:
RELEASE_STEP_ID: capture_release_context
run: bundle exec rake release:workflow:capture
- name: Check Release Prerequisites
id: check_release_prerequisites
shell: bash
env:
RELEASE_STEP_ID: check_release_prerequisites
run: bundle exec rake release:workflow:preflight
- name: Validate Release
id: validate_release
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions docs/actions/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Register a RubyGems trusted publisher for the calling repository, its own workfl

For maintainer-only publication, protect the caller job's `release` environment using [Maintainer-Approved Publication](../../RELEASING.md#maintainer-approved-publication). Other repository writers can dispatch, but publication waits for a designated maintainer to approve. Environments do not restrict who can dispatch, and an environment without protection rules does not restrict release access.

The action checks [release prerequisites](release.md#release-prerequisites), including the trusted publisher, after context capture and before validation, edits, or publication. To check without releasing, run `bundle exec rake release:workflow:preflight` in a job of the same workflow file, in the `release` environment, with `id-token: write`. RubyGems matches the workflow file and environment, so a check from another workflow or environment does not prove the release job's configuration. The composite action has no dry-run input.

For first publication, register a pending trusted publisher and supply its numeric account ID through `rubygems-owner`. Later publications can omit that input. The default `release:publish` task authenticates through the configured destination before invoking its publication callback; no separate YAML authentication step is needed. The RubyGems destination uses the [Ruby credentials helper](../workflow/ruby_gems_credentials.md) without a stored API key. It exports environment variables and does not create or modify `~/.gem/credentials`. Command overrides that bypass the task must own authentication as well as publication.

## Release and Recovery
Expand Down
66 changes: 48 additions & 18 deletions docs/actions/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,57 @@ For a step-based interface with caller-owned job settings, see the [Composite Ac

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. |
| 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). |

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

### Release Prerequisites

Every release runs `bundle exec rake release:workflow:preflight` after context capture, before validation, edits, or publication, so missing permissions fail before anything is pushed or published. The preflight requests the job's OIDC token and exchanges it at RubyGems exactly as publication does, passing `rubygems-owner` when set. Success proves that the caller granted `id-token: write` and that a trusted publisher matches the repository, workflow, and environment in the token. The job reports those claims and the credential's scopes; on failure, the error names the claims RubyGems rejected. The exchanged credential is masked, expires after 15 minutes, and is never exported or used; publication performs its own exchange. RubyGems does not report which gems a publisher is attached to, so the preflight cannot confirm that the publisher belongs to this gem, or that RubyGems would accept the package.

### Dry Run

Set `dry-run: true` to run only the release prerequisites. A separate `preflight` job runs instead of the `release` job, in the same `release` environment, so required reviewers still approve it. It checks out the caller without persisted credentials, installs the bundle, and runs the same [prerequisite checks](#release-prerequisites). It never edits files, commits, tags, pushes, builds, or publishes.

To dispatch dry runs, add a boolean input to the caller and pass it through:

```yaml
on:
workflow_dispatch:
inputs:
dry-run:
description: Check release prerequisites without releasing.
type: boolean
default: false

jobs:
release:
uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.7.0
with:
ruby-version: '3.3'
dry-run: ${{ inputs.dry-run }}
```

Then run `gh workflow run release.yml -f dry-run=true`.

### Release Validation

Validation runs after context capture, before preparation edits. Empty pending notes fail unless the selected release already has a changelog heading, allowing repetition. Malformed content also fails. With no changelog, validation passes. Custom changelog objects implement `pending?` and `released?(version)` or supply a `validate:` callback.
Expand Down
2 changes: 2 additions & 0 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ The [Detailed Usage example](usage.md#custom-callbacks) commits, builds, tags, p

## Workflow Credentials

`release:workflow:preflight` checks release prerequisites without editing files, pushing, or publishing. With a RubyGems destination it verifies Trusted Publishing through [`Workflow::RubyGemsCredentials#check!`](workflow/ruby_gems_credentials.md#check) with optional `RUBYGEMS_OWNER_ID`; other destinations skip that check. Both Actions interfaces run it in every release after context capture, and the reusable workflow runs only it for [dry runs](actions/release.md#dry-run).

`release:workflow:credentials` directly invokes [`Workflow::RubyGemsCredentials`](workflow/ruby_gems_credentials.md) with optional `RUBYGEMS_OWNER_ID`. It remains available for custom RubyGems commands, but neither Actions interface calls a separate authentication task. Normal authentication belongs to `release:publish` through the configured destination.
Loading
Loading