Skip to content

Commit 8e5d35d

Browse files
dblockclaude
andcommitted
Publish from a job that runs no project code
Add an opt-in isolated reusable workflow. A read-only build job runs the project's capture, validation, preparation, tests, and checkpoint, then `release:workflow:seal` commits the next development iteration locally and preserves a Git bundle and `publication.json` handoff with the gem. An 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 before the gem, so a branch that rejects the release token fails before publication. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr
1 parent 41f8630 commit 8e5d35d

23 files changed

Lines changed: 814 additions & 7 deletions

‎.github/actionlint.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# GitHub documents job.workflow_repository and job.workflow_sha, which the isolated
2+
# publish job uses to check out its own library source; actionlint 1.7.12 does not
3+
# know them yet (https://github.com/rhysd/actionlint/pull/707).
4+
paths:
5+
.github/workflows/isolated-release.yml:
6+
ignore:
7+
- 'property "workflow_(repository|sha)" is not defined in object type'
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Isolated Release Gem
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: Optional release version overriding the checked-in version in the standard workflow.
8+
type: string
9+
gemspec:
10+
description: Optional gemspec path; defaults to the only root gemspec.
11+
type: string
12+
rubygems-owner:
13+
description: Optional RubyGems account ID for first publication with a pending trusted publisher.
14+
type: string
15+
git-user-name:
16+
description: Author name for release and next development iteration commits.
17+
type: string
18+
default: github-actions[bot]
19+
git-user-email:
20+
description: Author email for release and next development iteration commits.
21+
type: string
22+
default: github-actions[bot]@users.noreply.github.com
23+
ruby-version:
24+
description: Ruby version used to validate, build, and publish.
25+
type: string
26+
required: true
27+
timezone:
28+
description: Timezone for release dates and Git timestamps.
29+
type: string
30+
default: UTC
31+
validate:
32+
description: Unprivileged command validating release preconditions; must exit nonzero on failure.
33+
type: string
34+
default: bundle exec rake release:validate
35+
prepare:
36+
description: Unprivileged command to prepare release files; INPUT_VERSION is the selected release version.
37+
type: string
38+
default: bundle exec rake release:prepare
39+
test:
40+
description: Unprivileged command to test the prepared release.
41+
type: string
42+
default: bundle exec rake
43+
44+
concurrency:
45+
group: ruby-gem-release-${{ github.repository }}
46+
cancel-in-progress: false
47+
48+
jobs:
49+
build:
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
outputs:
54+
artifact: ${{ steps.name_release_artifact.outputs.artifact }}
55+
env:
56+
INPUT_VERSION: ${{ inputs.version }}
57+
INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }}
58+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
59+
GIT_USER_NAME: ${{ inputs.git-user-name }}
60+
GIT_USER_EMAIL: ${{ inputs.git-user-email }}
61+
TZ: ${{ inputs.timezone }}
62+
steps:
63+
- uses: actions/checkout@v7
64+
id: checkout
65+
with:
66+
fetch-depth: 0
67+
persist-credentials: false
68+
- uses: ruby/setup-ruby@v1
69+
id: setup_ruby
70+
with:
71+
ruby-version: ${{ inputs.ruby-version }}
72+
bundler-cache: true
73+
- name: Capture Release Context
74+
id: capture_release_context
75+
env:
76+
RELEASE_STEP_ID: capture_release_context
77+
run: bundle exec rake release:workflow:capture
78+
- name: Validate Release
79+
id: validate_release
80+
env:
81+
RELEASE_COMMAND: ${{ inputs.validate }}
82+
RELEASE_STEP_ID: validate_release
83+
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
84+
run: bash -euo pipefail -c "$RELEASE_COMMAND"
85+
- name: Prepare Release
86+
id: prepare_release
87+
env:
88+
RELEASE_COMMAND: ${{ inputs.prepare }}
89+
RELEASE_STEP_ID: prepare_release
90+
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
91+
run: bash -euo pipefail -c "$RELEASE_COMMAND"
92+
- name: Resolve Prepared Version
93+
id: resolve_prepared_version
94+
env:
95+
RELEASE_STEP_ID: resolve_prepared_version
96+
run: bundle exec rake release:workflow:resolve
97+
- name: Test Release
98+
id: test_release
99+
env:
100+
RELEASE_COMMAND: ${{ inputs.test }}
101+
RELEASE_STEP_ID: test_release
102+
RELEASE_STEPS_JSON: ${{ toJSON(steps) }}
103+
run: bash -euo pipefail -c "$RELEASE_COMMAND"
104+
- name: Checkpoint Release
105+
id: checkpoint_release
106+
env:
107+
RELEASE_STEP_ID: checkpoint_release
108+
run: bundle exec rake release:workflow:checkpoint
109+
- name: Seal Release
110+
id: seal_release
111+
env:
112+
RELEASE_STEP_ID: seal_release
113+
run: bundle exec rake release:workflow:seal
114+
- name: Name Release Artifact
115+
id: name_release_artifact
116+
run: echo "artifact=release-gem-$RELEASE_VERSION-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
117+
- name: Preserve Release Artifacts
118+
id: preserve_release_artifacts
119+
uses: actions/upload-artifact@v7
120+
with:
121+
name: ${{ steps.name_release_artifact.outputs.artifact }}
122+
path: |
123+
${{ runner.temp }}/release.gem
124+
${{ runner.temp }}/release.json
125+
${{ runner.temp }}/release.bundle
126+
${{ runner.temp }}/publication.json
127+
if-no-files-found: error
128+
retention-days: 30
129+
publish:
130+
needs: build
131+
runs-on: ubuntu-latest
132+
environment: release
133+
permissions:
134+
contents: write
135+
id-token: write
136+
env:
137+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
138+
RELEASE_AUTH_MODE: rubygems
139+
RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }}
140+
GH_TOKEN: ${{ github.token }}
141+
steps:
142+
- uses: actions/checkout@v7
143+
id: checkout
144+
with:
145+
path: source
146+
fetch-depth: 0
147+
- uses: actions/checkout@v7
148+
id: checkout_library
149+
with:
150+
repository: ${{ job.workflow_repository }}
151+
ref: ${{ job.workflow_sha }}
152+
path: library
153+
persist-credentials: false
154+
- uses: ruby/setup-ruby@v1
155+
id: setup_ruby
156+
with:
157+
ruby-version: ${{ inputs.ruby-version }}
158+
bundler: none
159+
- uses: actions/download-artifact@v8
160+
id: download_release_artifacts
161+
with:
162+
name: ${{ needs.build.outputs.artifact }}
163+
path: ${{ runner.temp }}
164+
- name: Publish Release
165+
id: publish_release
166+
working-directory: source
167+
run: ruby --disable-gems -rrubygems -I ../library/lib -rruby-gem-release/workflow/isolated_publication -e 'RubyGemRelease::Workflow::IsolatedPublication.new.publish!'

‎.spellcheck.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gemspecs
1414
Gemfile
1515
GitLab
1616
GPG
17+
handoff
1718
HTTPS
1819
idempotence
1920
Intridea
@@ -48,6 +49,7 @@ rulesets
4849
RSpec
4950
RuboCop
5051
RubyGems
52+
SHA
5153
strftime
5254
subclasses
5355
subprocess

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Keep orchestration permutations and YAML assertions in focused source specs (`bu
1212

1313
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.
1414

15-
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.
15+
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.
1616

1717
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.
1818

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- [#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).
66
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
7+
- [#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).
78
- Your contribution here.
89

910
## 0.7.0 (2026/11/20)

‎DESIGN.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ The checkpoint task commits prepared edits, builds reproducibly, tags locally, a
2828

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

31+
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).
32+
3133
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.
3234

3335
## Preparation and Artifact Guards

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Replace only what you need. The [standard workflow](docs/workflow/ruby_gem.md) p
103103
- **Packages and registries:** Override [package construction](docs/package/ruby_gem.md) or supply a [registry destination](docs/destination.md) independently of hosted releases.
104104
- **Release hosting:** Replace or disable [GitHub Release creation](docs/workflow/ruby_gem.md#hosting) without changing package publication or Git operations.
105105
- **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.
106+
- **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.
106107
- **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.
107108
- **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.
108109

‎docs/actions/isolated_release.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Isolated Release Workflow
2+
3+
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:
4+
5+
- **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.
6+
- **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.
7+
8+
## Usage
9+
10+
Add `.github/workflows/release.yml` using the [sample workflow](../../examples/.github/workflows/isolated-release.yml), pinning the reusable workflow by commit SHA:
11+
12+
```yaml
13+
name: Release
14+
15+
on:
16+
workflow_dispatch:
17+
inputs:
18+
version:
19+
description: Optional release version overriding the checked-in version.
20+
type: string
21+
required: false
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
release:
28+
uses: dblock/ruby-gem-release/.github/workflows/isolated-release.yml@v0.8.0
29+
permissions:
30+
contents: write
31+
id-token: write
32+
with:
33+
ruby-version: '3.3'
34+
version: ${{ inputs.version }}
35+
```
36+
37+
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.
38+
39+
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.
40+
41+
## Inputs
42+
43+
`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.
44+
45+
## Requirements
46+
47+
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`.
48+
49+
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.
50+
51+
## Publication Order
52+
53+
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:
54+
55+
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.
56+
2. Publishes the gem to RubyGems, authenticating through Trusted Publishing only if that exact gem is not already published.
57+
3. Pushes the release tag.
58+
4. Creates or updates the GitHub Release with the gem attached.
59+
5. Pushes the next development commit.
60+
61+
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`.
62+
63+
## Recovery
64+
65+
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.
66+
67+
## Security Notes
68+
69+
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.

‎docs/actions/release.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
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.
5+
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).
66

77
## Inputs
88

0 commit comments

Comments
 (0)