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
60 changes: 59 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Release Please

# Opens and updates the release PR. Merging it tags the commit and creates
# a draft GitHub release; release.yml publishes from that tag.
# a draft GitHub release; release.yml publishes from that tag. A minor release
# PR then gets a signed App commit with its prepared installation guides.
on:
push:
branches: [main]
Expand All @@ -13,6 +14,10 @@ concurrency:
group: release-please-main
cancel-in-progress: false

env:
MISE_ENV: ci
MISE_LOCKED: "1"

jobs:
release-please:
if: github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -43,3 +48,56 @@ jobs:
token: ${{ steps.app-token.outputs.token }}
config-file: .github/release-please-config.json
manifest-file: .github/.release-please-manifest.json
# Looked up independently: Release Please reports no PR when its body is
# unchanged, and the owner-qualified head filter excludes forks. The SHA
# comes from the branch ref that createCommitOnBranch compares against;
# a PR's head.sha can lag a push that just rebuilt the branch.
- id: release-pr
name: Find the release PR
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RELEASE_BRANCH: release-please--branches--main--components--connectrpc
run: |
number="$(gh api "repos/$GITHUB_REPOSITORY/pulls?state=open&base=main&head=$GITHUB_REPOSITORY_OWNER:$RELEASE_BRANCH" --jq '.[0].number // empty')"
sha=""
if [ -n "$number" ]; then
sha="$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/$RELEASE_BRANCH" --jq '.object.sha')"
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
# Tooling comes from main. The release PR head is only read as data, so
# release-branch code never runs with the App token.
- name: Check out main tooling
if: steps.release-pr.outputs.sha != ''
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false
- name: Check out the release PR head as data
if: steps.release-pr.outputs.sha != ''
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.release-pr.outputs.sha }}
path: release-pr
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false
- if: steps.release-pr.outputs.sha != ''
uses: ruby/setup-ruby@7f797815d8adceb1c412e7abefdd1ab4abc47a5f # v1.335.0
with:
ruby-version: "3.4.12"
bundler: "4.0.23"
- if: steps.release-pr.outputs.sha != ''
uses: jdx/mise-action@82a612c5ab8bcda7cc5db6b7e81a8e7584c3dc6e # v5.2.3
with:
version: "2026.10.19"
add_shims_to_path: false
env: false
export_path: false
install: false
cache: false
- name: Prepare and commit installation guides
if: steps.release-pr.outputs.sha != ''
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
RELEASE_HEAD: ${{ steps.release-pr.outputs.sha }}
RELEASE_ROOT: release-pr
run: mise run release:prepare:pr
69 changes: 50 additions & 19 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ It remains experimental and does not adopt the stronger
The pipeline has three stages:

1. Every push to main runs Release Please, which opens or updates one release
PR for the whole train.
PR for the whole train. For a minor release, the same run then commits the
prepared installation guides to that PR.
2. Merging that PR makes Release Please push a `vX.Y.Z` tag and create a draft
GitHub release with the changelog.
3. The tag starts the [release workflow](../.github/workflows/release.yml). It
Expand Down Expand Up @@ -65,6 +66,26 @@ draft release until it is published, and without the tag Release Please cannot
find the previous release.
This workflow has no publishing job or OIDC permission.

After Release Please, the same job prepares the open release PR:

1. It looks up the open PR from the
`release-please--branches--main--components--connectrpc` branch of this
repository into main. Release Please reports no PR when the body is
unchanged, so the lookup does not depend on its output. Forks are excluded.
2. It checks out main for tooling, then the PR head SHA into `release-pr` as
data. Nothing from the release branch runs: `mise run release:prepare:pr`
reads only the release tree's core version file and installation guides as
text, and applies the same transformation as `release:prepare`.
3. If any guide changes, it commits exactly those guides to the release branch
through the GraphQL `createCommitOnBranch` mutation with the App token, so
GitHub signs the commit as the App. `expectedHeadOid` is the checked-out
SHA, so a branch that moved since the lookup fails the run instead of being
overwritten.

Patch releases and runs without an open release PR change nothing. A failed
preparation is retried by the next push to main, or by manually dispatching the
workflow from main. The App-token push starts the PR's normal CI.

The job runs in the `release-please` environment, whose deployment branch
policy allows only `main`. The existing release GitHub App needs these
references, as in the pinned
Expand All @@ -77,10 +98,11 @@ references, as in the pinned
| App installation | Installation access to `jimeh/connectrpc-ruby`, with contents, issues and pull requests write permissions. |

The workflow requests an installation token scoped to the current repository
and those three permissions. Its `GITHUB_TOKEN` has no permissions. App-created
PRs can trigger normal downstream CI. Missing references fail the run with an
actionable error; there is no fallback token. Do not print, copy into the
checkout, or ask for private-key values in chat.
and those three permissions. Contents write also covers the guide preparation
commit, so it needs no new permission. Its `GITHUB_TOKEN` has no permissions.
App-created PRs can trigger normal downstream CI. Missing references fail the
run with an actionable error; there is no fallback token. Do not print, copy
into the checkout, or ask for private-key values in chat.

Both reference names were listed in the `release-please` environment on
2026-11-14. App installation and token permissions are verified only by the
Expand All @@ -100,21 +122,23 @@ For each release PR:
2. A patch release needs no preparation: the bot's version files, manifest and
changelog are the whole change, and `release:check` accepts them. A minor
(breaking) release changes the internal `~> M.m.0` requirement that the
installation guides quote, so `release:check` fails until you check out the
release branch, run `mise run release:prepare`, review the guide diff and
commit it with the existing signing configuration. Preparation does not
resolve dependencies or download anything.
installation guides quote. The workflow commits that guide update
automatically; review its diff. If the workflow cannot, dispatch it again or
use the local fallback: check out the release branch, run
`mise run release:prepare`, review the guide diff and commit it with the
existing signing configuration. Preparation does not resolve dependencies or
download anything.
3. Run `mise run release:check`, focused tests and the candidate procedure below.
Capture the exact head and CI/review evidence after the final bot update.
4. Merge the PR once the release decision is made. The release workflow then
waits for any `release` environment approval.

**Re-run preparation after every bot regeneration of a minor release.** Release
Please rebuilds its branch from main when its generated body changes. It can
discard signed preparation commits and hand edits in the release PR. Finish the
bot update, then prepare and validate its final head; a quiet main during that
window helps. Do not present earlier CI/review evidence as covering a later
regenerated head.
**Validate the final head after every bot regeneration of a minor release.**
Release Please rebuilds its branch from main when its generated body changes,
which drops the preparation commit; the same workflow run then commits it
again. Hand edits in the release PR are still discarded. Wait for the run to
finish, then validate the final head; a quiet main during that window helps. Do
not present earlier CI/review evidence as covering a later regenerated head.

## Validate a local candidate

Expand All @@ -123,7 +147,8 @@ Use `mise tasks` for the task index:
| Task | Evidence and writes |
| --- | --- |
| `release:check` | Offline version, configuration, guard and installation-guide checks. No writes or setup dependencies. |
| `release:prepare` | Deterministic installation-guide requirement updates, needed only for a minor release. No registry resolution. |
| `release:prepare` | Deterministic installation-guide requirement updates, needed only for a minor release. No registry resolution. Local fallback for the workflow. |
| `release:prepare:pr` | CI only. Refuses to run outside `release-please.yml` on main. Commits the prepared guides of the checked-out release PR as the App. |
| `release:build` | Eleven canonical archives, two-build hash comparison and `candidate.json`. No installation or publication. |
| `release:candidate` | Existing installed-package/generation/RBS checks followed by the canonical archive build. Uses normal scoped setup prerequisites. |
| `release:tools` | Installs the frozen Sigstore signing bundle (`release/Gemfile`) into `vendor/sigstore`. |
Expand All @@ -133,7 +158,7 @@ Run the focused release specs and workflow checks first:

```sh
mise run release:check
mise run test -- spec/release_train_spec.rb spec/release_publisher_spec.rb spec/package_build_spec.rb spec/ci_runtime_spec.rb
mise run test -- spec/release_train_spec.rb spec/release_preparation_spec.rb spec/release_publisher_spec.rb spec/package_build_spec.rb spec/ci_runtime_spec.rb
mise run lint:workflows
```

Expand Down Expand Up @@ -301,8 +326,11 @@ published, the retained bytes are the only valid candidate. An interrupted uploa
safe to delete. When repair requires a new version, release a new whole-train
version and document the partial train and migration implications.

Release Please creates its commits and tags through the GitHub API as the App,
not with a local GPG key. Normal source commits stay signed.
Release Please creates its commits and tags, and the workflow creates the
guide preparation commit, through the GitHub API as the App, not with a local
GPG key. GitHub signs App commits made without a custom author or committer.
Normal source commits, including a local `release:prepare` fallback, stay
signed.

## Primary references

Expand All @@ -315,3 +343,6 @@ not with a local GPG key. Normal source commits stay signed.
- [RubyGems owner assertion for new gems](https://github.com/rubygems/rubygems.org/blob/master/app/models/pusher.rb) (`notify_missing_pending_owner`).
- [Sigstore Ruby CLI](https://github.com/sigstore/sigstore-ruby/tree/v0.2.3).
- [GitHub immutable releases](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/immutable-releases).
- [GraphQL `createCommitOnBranch`](https://docs.github.com/en/graphql/reference/mutations#createcommitonbranch).
- [Signature verification for bots](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification#signature-verification-for-bots).
- [Triggering a workflow from a workflow](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow).
4 changes: 4 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,10 @@ run = "mise exec -- ruby scripts/release.rb check"
description = "Refresh installation guide requirements after a minor (breaking) release version update"
run = "mise exec -- ruby scripts/release.rb prepare"

[tasks."release:prepare:pr"]
description = "CI only (release-please.yml on main): commit prepared installation guides to the release PR branch as the release App"
run = "mise exec -- ruby scripts/release.rb prepare-pr"

[tasks."release:build"]
description = "Build and compare eleven canonical candidate archives from a clean Ruby 3.4.12 checkout"
run = "mise exec -- ruby scripts/release.rb build"
Expand Down
14 changes: 13 additions & 1 deletion scripts/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
when ["prepare"]
train.prepare!
puts "Prepared installation guides for #{train.version}; review and sign the diff"
when ["prepare-pr"]
require_relative "release_preparation"
# The App-token commit only runs from the Release Please workflow on main.
workflow = "#{ENV.fetch('GITHUB_REPOSITORY', '')}/.github/workflows/release-please.yml@refs/heads/main"
unless ENV["GITHUB_ACTIONS"] == "true" && ENV["GITHUB_WORKFLOW_REF"] == workflow
abort "release:prepare:pr only runs in .github/workflows/release-please.yml on main"
end

ReleasePreparation.new(
train: ReleaseTrain.new(ENV.fetch("RELEASE_ROOT")), repository: ENV.fetch("GITHUB_REPOSITORY"),
head: ENV.fetch("RELEASE_HEAD"), github: ReleasePreparation::GitHub.new
).commit!
when ["build"]
require_relative "release_candidate"
puts "Candidate archives: #{ReleaseCandidate.new(train).build_from_git!}"
Expand Down Expand Up @@ -38,5 +50,5 @@
).publish!
end
else
abort "Usage: ruby scripts/release.rb check|prepare|build|tools|publish"
abort "Usage: ruby scripts/release.rb check|prepare|prepare-pr|build|tools|publish"
end
104 changes: 104 additions & 0 deletions scripts/release_preparation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# frozen_string_literal: true

require "json"
require "open3"
require_relative "release_train"

# Commits prepared installation guides to the open release PR as the release
# App. The release checkout is data: its version file and guides are read as
# text and nothing from it runs while the App token is in the environment.
class ReleasePreparation
BRANCH = "release-please--branches--main--components--connectrpc"

def initialize(train:, repository:, head:, github:, log: $stdout)
@train = train
@repository = repository
@head = head
@github = github
@log = log
end

def commit!
verify_head!
changes = changed_guides
if changes.empty?
@log.puts "Installation guides already quote #{@train.requirement}; nothing to commit"
return
end

oid = @github.create_commit(commit_input(changes))
@log.puts "Committed #{changes.size} prepared installation guides for #{@train.version} to #{BRANCH}: #{oid}"
oid
end

private

def verify_head!
revision, error, status = Open3.capture3("git", "rev-parse", "HEAD", chdir: @train.root)
raise "Cannot read the release checkout HEAD: #{error}" unless status.success?
return if revision.strip == @head

raise "Release checkout is at #{revision.strip}, expected #{@head}"
end

def changed_guides
root = File.realpath(@train.root)
ReleaseTrain::GUIDES.sort.each_with_object({}) do |file, changes|
current = guide(root, file)
next unless current

prepared = @train.prepared_guide(current)
changes[file] = prepared unless prepared == current
end
end

# Main may list a guide that an older release branch lacks.
def guide(root, file)
path = File.join(root, file)
unless File.exist?(path)
@log.puts "Skipping #{file}: not in the release tree"
return
end
# A symlink could make the commit carry runner files instead of guide text.
unless File.file?(path) && File.realpath(path) == path
raise "Refusing #{file}: not a regular file inside the release tree"
end

File.read(path)
end

def commit_input(changes)
{
branch: { repositoryNameWithOwner: @repository, branchName: BRANCH },
expectedHeadOid: @head,
message: { headline: "chore: prepare installation guides for #{@train.version}" },
# pack("m0") is strict Base64; the base64 gem is no longer a default gem on Ruby 3.4.
fileChanges: { additions: changes.map { |path, text| { path: path, contents: [text].pack("m0") } } }
}
end

# GraphQL createCommitOnBranch through the preinstalled gh CLI. An App
# installation token makes GitHub sign the commit, and a stale
# expectedHeadOid fails the mutation instead of overwriting the branch.
class GitHub
MUTATION = <<~GRAPHQL
mutation($input: CreateCommitOnBranchInput!) {
createCommitOnBranch(input: $input) { commit { oid url } }
}
GRAPHQL

def create_commit(input)
body = JSON.generate(query: MUTATION, variables: { input: input })
output, error, status = Open3.capture3("gh", "api", "graphql", "--input", "-", stdin_data: body)
raise "gh api graphql failed: #{error}#{output}" unless status.success?

response = JSON.parse(output)
raise "createCommitOnBranch failed: #{JSON.generate(response['errors'])}" if response["errors"]

oid = response.dig("data", "createCommitOnBranch", "commit", "oid")
raise "createCommitOnBranch returned no commit: #{output}" unless oid

oid
end
end
end
10 changes: 7 additions & 3 deletions scripts/release_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ def check_versions! # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplex
# Installation guides name the internal `~> M.m.0` requirement, which changes
# only on a minor (breaking) release. Versions and changelog need nothing else.
def prepared_files
GUIDES.to_h do |file|
[file, read(file).gsub(/(connectrpc(?:-[a-z]+)*["`, ]+)~> 0\.\d+\.\d+/, "\\1#{requirement}")]
end
GUIDES.to_h { |file| [file, prepared_guide(read(file))] }
end

# Pure text transformation, so callers can prepare guides read from a tree
# they must not execute.
def prepared_guide(content)
content.gsub(/(connectrpc(?:-[a-z]+)*["`, ]+)~> 0\.\d+\.\d+/, "\\1#{requirement}")
end

def check_configuration! # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
Expand Down
Loading