Repository navigation
Add opt-in RubyGems trusted publishing to cd.yml - #36
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
workflow_callinputs:trusted-publishing(defaultfalse),ruby-version(default3),attestations(defaulttrue).deployjob runs exactly as before unless a caller setstrusted-publishing: true. All 14 callers track@main, so this can merge before any gem has a trusted publisher.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. Ifmainhas moved on, it leaves the release to the later run.release: runs in therubygems.orgenvironment and usesrubygems/release-gem, which tagsv<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.Why the release job has no
permissionsblockGitHub checks every called job's permissions against the caller's grant when the run starts, including jobs that would be skipped. Declaring
id-token: writeon 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 ifid-token: writewasn't granted.Why decide by RubyGems instead of the tag
The API-key path skips any version whose tag exists.
rake releasepushes the tag beforegem push, so a failed push leaves that version permanently unreleasable. The new path checks RubyGems.release-gemfetches tags first, and Bundler doesn't re-create an existing tag, so a re-run publishes it.To opt a gem in
gusto-open-sourceowner adds a GitHub Actions trusted publisher athttps://rubygems.org/gems/<gem>/trusted_publishers. Repository ownerrubyatscale, repository name<repo>, workflow filenamecd.yml, environmentrubygems.org, workflow repository ownerrubyatscale, workflow repository nameshared-config. RubyGems matches reusable workflows onjob_workflow_ref..github/workflows/cd.yml, addid-token: writeto the calling job's permissions andwith: trusted-publishing: true.Testing
actionlintandzizmor(default) are clean oncd.yml.zizmor --pedanticadds no new findings beyond the existing ones on thedeployandnotify_on_failurejobs.checkscript locally againstquery_packwerk,code_teams,packs-railsanddanger-migrations(private). All four reported "already on RubyGems". With an unpublished version it reported release needed, with a movedmainit skipped, and with two gemspecs it errored.Not changed
The API-key
deployjob, including its existingworkflow_runguard (CI success only). It checks out the default branch, not the triggering commit. It goes away once every caller has switched.