Skip to content

Add opt-in RubyGems trusted publishing to cd.yml - #36

Merged
dduugg merged 1 commit into
mainfrom
trusted-publishing
Nov 24, 2026
Merged

dduugg merged 1 commit into
mainfrom
trusted-publishing

Conversation

@dduugg

@dduugg dduugg commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Adds RubyGems trusted publishing (OIDC) to the shared CD workflow as an opt-in, so gems can stop publishing with the long-lived org-wide RUBYGEMS_API_KEY. Part of the Modularity board item "Consistent, convenient trusted publishing and auto tagging of releases".

What changes

  • New workflow_call inputs: trusted-publishing (default false), ruby-version (default 3), attestations (default true).
  • Default behavior is unchanged. The existing API-key deploy job runs exactly as before unless a caller sets trusted-publishing: true. All 14 callers track @main, so this can merge before any gem has a trusted publisher.
  • With trusted-publishing: true, three new jobs run instead:
    • check (contents: read): reads the gemspec at the commit CI tested, and asks RubyGems whether that version exists and GitHub whether its release exists. It only proceeds for a push to this repo's default branch that is still the branch head. If main has moved on, it leaves the release to the later run.
    • release: runs in the rubygems.org environment and uses rubygems/release-gem, which tags v<version>, pushes the tag, publishes over OIDC, and attaches Sigstore attestations.
    • github_release (contents: write): a separate job, so a re-run can still create the release after the gem has shipped.
  • README documents the caller change and the trusted publisher values to register on rubygems.org.

Why the release job has no permissions block

GitHub checks every called job's permissions against the caller's grant when the run starts, including jobs that would be skipped. Declaring id-token: write on the job would therefore fail CD in every repo that hasn't opted in. The job inherits the caller's permissions instead. Its first step fails with a clear message if id-token: write wasn't granted.

Why decide by RubyGems instead of the tag

The API-key path skips any version whose tag exists. rake release pushes the tag before gem push, so a failed push leaves that version permanently unreleasable. The new path checks RubyGems. release-gem fetches tags first, and Bundler doesn't re-create an existing tag, so a re-run publishes it.

To opt a gem in

  1. A gusto-open-source owner adds a GitHub Actions trusted publisher at https://rubygems.org/gems/<gem>/trusted_publishers. Repository owner rubyatscale, repository name <repo>, workflow filename cd.yml, environment rubygems.org, workflow repository owner rubyatscale, workflow repository name shared-config. RubyGems matches reusable workflows on job_workflow_ref.
  2. In the gem's .github/workflows/cd.yml, add id-token: write to the calling job's permissions and with: trusted-publishing: true.

Testing

  • actionlint and zizmor (default) are clean on cd.yml. zizmor --pedantic adds no new findings beyond the existing ones on the deploy and notify_on_failure jobs.
  • Ran the check script locally against query_packwerk, code_teams, packs-rails and danger-migrations (private). All four reported "already on RubyGems". With an unpublished version it reported release needed, with a moved main it skipped, and with two gemspecs it errored.
  • Not yet run end to end. That needs a registered trusted publisher. The first gem to opt in is the real test, ideally with a patch release.

Not changed

The API-key deploy job, including its existing workflow_run guard (CI success only). It checks out the default branch, not the triggering commit. It goes away once every caller has switched.

Callers that set trusted-publishing: true (and grant id-token: write)
publish with rubygems/release-gem over OIDC instead of the org-wide
RUBYGEMS_API_KEY. The API-key deploy job is unchanged and stays the
default, so no caller changes behavior until it opts in, which it can do
once its gem has a trusted publisher registered on rubygems.org.

The new path decides whether to release by asking RubyGems rather than
by the git tag, so a tag pushed before a failed gem push no longer blocks
that version, and re-running a failed run picks up where it stopped. It
only releases a push to the repo's default branch that is still the
branch head, and creates the GitHub release in its own job so it can be
retried after the gem ships.

The release job inherits the caller's permissions rather than requesting
id-token: write, because GitHub rejects a run when any called job asks
for more than the caller grants, skipped jobs included.
@github-project-automation github-project-automation Bot moved this to Triage in Modularity Nov 17, 2026
@dduugg
dduugg marked this pull request as ready for review November 17, 2026 20:20
@dduugg
dduugg requested a review from a team as a code owner November 17, 2026 20:20
@dduugg
dduugg merged commit b7dc9d9 into main Nov 24, 2026
4 checks passed
@dduugg
dduugg deleted the trusted-publishing branch November 24, 2026 00:43
@github-project-automation github-project-automation Bot moved this from Triage to Done in Modularity Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant