Skip to content
Closed
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
7 changes: 7 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# GitHub documents job.workflow_repository and job.workflow_sha, which the isolated
# publish job uses to check out its own library source; actionlint 1.7.12 does not
# know them yet (https://github.com/rhysd/actionlint/pull/707).
paths:
.github/workflows/isolated-release.yml:
ignore:
- 'property "workflow_(repository|sha)" is not defined in object type'
167 changes: 167 additions & 0 deletions .github/workflows/isolated-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: Isolated Release Gem

on:
workflow_call:
inputs:
version:
description: Optional release version overriding the checked-in version in the standard workflow.
type: string
gemspec:
description: Optional gemspec path; defaults to the only root gemspec.
type: string
rubygems-owner:
description: Optional RubyGems account ID for first publication with a pending trusted publisher.
type: string
git-user-name:
description: Author name for release and next development iteration commits.
type: string
default: github-actions[bot]
git-user-email:
description: Author email for release and next development iteration commits.
type: string
default: github-actions[bot]@users.noreply.github.com
ruby-version:
description: Ruby version used to validate, build, and publish.
type: string
required: true
timezone:
description: Timezone for release dates and Git timestamps.
type: string
default: UTC
validate:
description: Unprivileged command validating release preconditions; must exit nonzero on failure.
type: string
default: bundle exec rake release:validate
prepare:
description: Unprivileged command to prepare release files; INPUT_VERSION is the selected release version.
type: string
default: bundle exec rake release:prepare
test:
description: Unprivileged command to test the prepared release.
type: string
default: bundle exec rake

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

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
artifact: ${{ steps.name_release_artifact.outputs.artifact }}
env:
INPUT_VERSION: ${{ inputs.version }}
INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GIT_USER_NAME: ${{ inputs.git-user-name }}
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
TZ: ${{ inputs.timezone }}
steps:
- uses: actions/checkout@v7
id: checkout
with:
fetch-depth: 0
persist-credentials: false
- uses: ruby/setup-ruby@v1
id: setup_ruby
with:
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: true
- name: Capture Release Context
id: capture_release_context
env:
RELEASE_STEP_ID: capture_release_context
run: bundle exec rake release:workflow:capture
- name: Validate Release
id: validate_release
env:
RELEASE_COMMAND: ${{ inputs.validate }}
RELEASE_STEP_ID: validate_release
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
run: bash -euo pipefail -c "$RELEASE_COMMAND"
- name: Prepare Release
id: prepare_release
env:
RELEASE_COMMAND: ${{ inputs.prepare }}
RELEASE_STEP_ID: prepare_release
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
run: bash -euo pipefail -c "$RELEASE_COMMAND"
- name: Resolve Prepared Version
id: resolve_prepared_version
env:
RELEASE_STEP_ID: resolve_prepared_version
run: bundle exec rake release:workflow:resolve
- name: Test Release
id: test_release
env:
RELEASE_COMMAND: ${{ inputs.test }}
RELEASE_STEP_ID: test_release
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
run: bash -euo pipefail -c "$RELEASE_COMMAND"
- name: Checkpoint Release
id: checkpoint_release
env:
RELEASE_STEP_ID: checkpoint_release
run: bundle exec rake release:workflow:checkpoint
- name: Seal Release
id: seal_release
env:
RELEASE_STEP_ID: seal_release
run: bundle exec rake release:workflow:seal
- name: Name Release Artifact
id: name_release_artifact
run: echo "artifact=release-gem-$RELEASE_VERSION-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
- name: Preserve Release Artifacts
id: preserve_release_artifacts
uses: actions/upload-artifact@v7
with:
name: ${{ steps.name_release_artifact.outputs.artifact }}
path: |
${{ runner.temp }}/release.gem
${{ runner.temp }}/release.json
${{ runner.temp }}/release.bundle
${{ runner.temp }}/publication.json
if-no-files-found: error
retention-days: 30
publish:
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
RELEASE_AUTH_MODE: rubygems
RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }}
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v7
id: checkout
with:
path: source
fetch-depth: 0
- uses: actions/checkout@v7
id: checkout_library
with:
repository: ${{ job.workflow_repository }}
ref: ${{ job.workflow_sha }}
path: library
persist-credentials: false
- uses: ruby/setup-ruby@v1
id: setup_ruby
with:
ruby-version: ${{ inputs.ruby-version }}
bundler: none
- uses: actions/download-artifact@v8
id: download_release_artifacts
with:
name: ${{ needs.build.outputs.artifact }}
path: ${{ runner.temp }}
- name: Publish Release
id: publish_release
working-directory: source
run: ruby --disable-gems -rrubygems -I ../library/lib -rruby-gem-release/workflow/isolated_publication -e 'RubyGemRelease::Workflow::IsolatedPublication.new.publish!'
2 changes: 2 additions & 0 deletions .spellcheck.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gemspecs
Gemfile
GitLab
GPG
handoff
HTTPS
idempotence
Intridea
Expand Down Expand Up @@ -48,6 +49,7 @@ rulesets
RSpec
RuboCop
RubyGems
SHA
strftime
subclasses
subprocess
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Keep orchestration permutations and YAML assertions in focused source specs (`bu

Keep semantic releases opt-in. Calculate from reachable released tags, not development versions; persist one immutable decision across processes, preserve it when recording the next version, and never reanalyze during preparation or publication. Preserve manual workflow defaults and publication guards. Semantic consumer fixtures must verify success, publication failure, and empty-release rejection against the installed artifact without real publication.

The root `action.yml` exposes the same Ruby tasks as a composite action. Keep both interfaces consistent without making version-pinned workflows depend on moving action references. Action callers own job permissions, runner, environment, and concurrency. Preserve authentication selection and failure-aware artifact preservation; run installed-artifact consumer CI and `actionlint .github/workflows/*.yml examples/.github/workflows/*.yml` when changing YAML interfaces.
The root `action.yml` exposes the same Ruby tasks as a composite action. Keep both interfaces consistent without making version-pinned workflows depend on moving action references. Action callers own job permissions, runner, environment, and concurrency. Preserve authentication selection and failure-aware artifact preservation; run installed-artifact consumer CI and `actionlint .github/workflows/*.yml examples/.github/workflows/*.yml` when changing YAML interfaces. The isolated workflow's publish job must never install or load the project's bundle, Rakefile, gemspec, or commands; `Workflow::IsolatedPublication` and everything it requires must load with plain `ruby -I lib` and only the standard library.

Run `bundle exec rake` locally for specs and RuboCop before every push, and `bundle exec rake build` for package construction when applicable. Danger checks the changelog in PR CI, not as a routine local command. Document user-visible changes in `CHANGELOG.md`, listing entries within each release chronologically and keeping `- Your contribution here.` as the last entry in the next-release section; keep Markdown paragraphs on one source line.

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#79](https://github.com/dblock/ruby-gem-release/pull/79): Select the next development version part with `next_version: :minor` or `:major` on `Workflow::RubyGem` and `Workflow::SemanticRubyGem` - [@dblock](https://github.com/dblock).
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
- [#81](https://github.com/dblock/ruby-gem-release/pull/81): Add an opt-in isolated reusable workflow that builds and tests without credentials and publishes from a separate environment-gated job that runs no project code, pushing the release commit before the gem - [@dblock](https://github.com/dblock).
- Your contribution here.

## 0.7.0 (2026/11/20)
Expand Down
2 changes: 2 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The checkpoint task commits prepared edits, builds reproducibly, tags locally, a

Every release action must be idempotent for the same checkout and inputs, without recovery flags, artifact discovery, restored context, or a completion journal. Tasks reconcile their own outputs; a fresh workflow uses its current checkout and inputs rather than discovering an older unfinished release. Registry publication and Git pushes cannot be atomic together, so both interfaces preserve artifacts before publication for manual inspection. See [rerunning releases](RELEASING.md#verify-and-recover).

The opt-in isolated workflow runs the same tasks through the checkpoint in a read-only build job, then seals the release: it commits the next development iteration locally and preserves a Git bundle and `publication.json` handoff with the gem. Its environment-gated publish job checks out the library at the reusable workflow's own commit and publishes with plain Ruby, never loading the project's bundle, Rakefile, or gemspec. It verifies the handoff against the dispatched commit, then pushes the release commit, publishes the gem, pushes the tag, creates the hosted release, and pushes the development commit, so a branch that rejects the release token fails before publication. Sealing rejects components and publication-stage hooks the publish job cannot reproduce. See the [isolated workflow reference](docs/actions/isolated_release.md).

Keep both YAML interfaces thin and consistent. The reusable workflow does not depend on a moving composite-action reference: a pinned release must remain independent of later action versions. Composite callers own permissions, runner, environment protection, and concurrency. Commands run with release privileges and must be trusted.

## Preparation and Artifact Guards
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Replace only what you need. The [standard workflow](docs/workflow/ruby_gem.md) p
- **Packages and registries:** Override [package construction](docs/package/ruby_gem.md) or supply a [registry destination](docs/destination.md) independently of hosted releases.
- **Release hosting:** Replace or disable [GitHub Release creation](docs/workflow/ruby_gem.md#hosting) without changing package publication or Git operations.
- **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.
- **Isolated publication:** Use the [isolated workflow](docs/actions/isolated_release.md) to build and test without credentials and publish from a separate environment-gated job that runs no project code.
- **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.
- **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.

Expand Down
69 changes: 69 additions & 0 deletions docs/actions/isolated_release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Isolated Release Workflow

Reference for [`.github/workflows/isolated-release.yml`](../../.github/workflows/isolated-release.yml), an opt-in reusable workflow that keeps publication credentials away from project code. The [standard workflow](release.md) runs everything in one job holding `id-token: write` and `contents: write`, so any gem in the project's development bundle, and any code its tests run, could request a publishing token. The isolated workflow splits the release into two jobs:

- **Build** runs with `contents: read`, outside the `release` environment. It installs the project bundle and runs capture, validation, preparation, resolution, tests, and the checkpoint exactly as the standard workflow does, then seals the release: it prepares and commits the next development iteration locally, running preparation hooks such as README updates, and preserves the gem, its manifest, a Git bundle with the release tag and both commits, and a `publication.json` handoff as the recovery artifact.
- **Publish** runs in the `release` environment with `id-token: write` and `contents: write`. It checks out the caller at the dispatched commit and this library at the reusable workflow's own commit (`job.workflow_sha`), installs no bundle, and publishes with plain Ruby. Project code, including its Gemfile, Rakefile, and gemspec, never runs while publication credentials are available.

## Usage

Add `.github/workflows/release.yml` using the [sample workflow](../../examples/.github/workflows/isolated-release.yml), pinning the reusable workflow by commit SHA:

```yaml
name: Release

on:
workflow_dispatch:
inputs:
version:
description: Optional release version overriding the checked-in version.
type: string
required: false

permissions:
contents: read

jobs:
release:
uses: dblock/ruby-gem-release/.github/workflows/isolated-release.yml@v0.8.0
permissions:
contents: write
id-token: write
with:
ruby-version: '3.3'
version: ${{ inputs.version }}
```

Configure the RubyGems trusted publisher as described in [Usage](../../README.md#3-enable-trusted-publishing), with workflow filename `isolated-release.yml`: RubyGems matches the filename of the reusable workflow, not the caller's. A trusted publisher for `isolated-release.yml` cannot be used by the single-job workflow. RubyGems accepts any ref of the workflow repository, so pin the `uses:` line to the full commit SHA of a release tag, with the tag in a trailing comment.

Keep `ruby-gem-release` in your development Gemfile at the same version as the pinned workflow. The build job runs the gem's Rake tasks from your bundle; the publish job runs the library from the workflow commit and rejects a handoff format it does not support.

## Inputs

`version`, `gemspec`, `rubygems-owner`, `git-user-name`, `git-user-email`, `ruby-version`, and `timezone` behave as in the [standard workflow](release.md#inputs). The `validate`, `prepare`, and `test` commands run only in the unprivileged build job. There are no `publish`, `bump`, `success`, `failure`, `prepare-artifacts`, or `artifacts` inputs: publication runs no project commands.

## Requirements

Sealing fails in the build job, before anything is published, unless the workflow uses the default package, RubyGems destination, Git source control, and either the default GitHub Release hosting for the calling repository or `hosting: nil`. Hooks for `authenticate`, `publish_registry`, `push_release`, `publish_hosted_release`, `push_next`, `success`, or `failure`, and `success:` or `failure:` callbacks, are rejected because the publish job cannot run them. Hooks for earlier stages, including `prepare_release`, `prepare_next`, and `commit_next`, run in the build job. [`Workflow::RubyGem`](../workflow/ruby_gem.md) and [`Workflow::SemanticRubyGem`](../workflow/semantic_ruby_gem.md) are supported; semantic releases carry their generated notes and seal no development iteration unless `bump: true`.

The [composite action](action.md) has no isolated mode, because a composite action runs inside one caller-owned job. The `job.workflow_*` contexts the publish job uses are unavailable on GitHub Enterprise Server.

## Publication Order

The publish job verifies the handoff before any push: the run must be on the default branch, the release commit must have the dispatched commit as its only parent, the tag must be a lightweight tag at the release commit, the development commit must have the release commit as its only parent, and the gem must match its manifest checksum and identity. It then:

1. Pushes the release commit to the default branch without the tag. A branch rule that rejects the release token fails here, before the gem is published.
2. Publishes the gem to RubyGems, authenticating through Trusted Publishing only if that exact gem is not already published.
3. Pushes the release tag.
4. Creates or updates the GitHub Release with the gem attached.
5. Pushes the next development commit.

Branch rules must still permit the Actions token to push commits and tags; see [branch permissions](../../RELEASING.md#one-time-setup). If the default branch moves after the build, publication stops with `Default branch advanced; start a new release`.

## Recovery

Every publication step reconciles existing state, so **Re-run failed jobs** on the same workflow run resumes from the first incomplete step, reusing the build job's artifact for its 30-day retention. If the release commit was pushed but the gem was not, the branch contains a release commit without a tag until the rerun completes. See [rerunning releases](../../RELEASING.md#verify-and-recover) before starting a new dispatch after a partial publication.

## Security Notes

Isolation protects the credential, not the build: a compromised dependency in the build job can still alter the gem or the sealed commits it hands off, and publication verifies their structure, not their contents. Required environment reviewers approve the publish job after the build job and its tests have finished, so reviewers can inspect the build log and preserved artifact before approving.
2 changes: 1 addition & 1 deletion docs/actions/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Reference for [`.github/workflows/release.yml`](../../.github/workflows/release.yml), invoked with `workflow_call`. See [Usage](../../README.md#usage) for a caller example and [Detailed Usage](../usage.md#configuration) for customization. See [RELEASING.md](../../RELEASING.md#one-time-setup) for branch permissions. Trusted Publishing is required setup in [Usage](../../README.md#3-enable-trusted-publishing).

For a step-based interface with caller-owned job settings, see the [Composite Action](action.md). Both interfaces invoke the same Ruby release tasks; the reusable workflow keeps its own runner, environment, permissions contract, and concurrency group.
For a step-based interface with caller-owned job settings, see the [Composite Action](action.md). Both interfaces invoke the same Ruby release tasks; the reusable workflow keeps its own runner, environment, permissions contract, and concurrency group. To publish from a separate job that runs no project code, see the [Isolated Release Workflow](isolated_release.md).

## Inputs

Expand Down
Loading
Loading