From 325f6672c7b3bcfa25a1b965ca8b8b073dca774a Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:58:55 -0800 Subject: [PATCH 1/3] ci: publish the Maple crates to crates.io from a reviewed tag maple-sdk must stay publishable to crates.io, which refuses a crate with a Git dependency, so the two crates this fork changes have to be published under Maple's names. `maple-publish.yml` runs for a tag `maple-v`. Its script refuses unless the tagged commit is the head of a `maple/-publish` branch that is exactly one commit on top of `maple/`, and the two manifests carry the tagged version and pin every workspace sibling exactly. It then runs the workspace tests and a dry run without a credential. The upload is a second job behind the `maple-crates` environment. It repeats the check, uploads `maple-sigstore-rekor`, waits until the crates.io index serves it, and uploads `maple-sigstore-verify`. A crate the index already serves at that version is skipped, so a rerun finishes a half-done release and does nothing when both are there. A crate's first version uses a bootstrap token from the environment, because crates.io offers trusted publishing only for a crate that already exists; later versions use trusted publishing. Nothing names a release line, so the same files serve the next `maple/`. Co-Authored-By: Claude --- .github/maple/publish.py | 209 +++++++++++++++++++++ .github/maple/test_publish.py | 280 ++++++++++++++++++++++++++++ .github/workflows/maple-publish.yml | 100 ++++++++++ MAPLE.md | 61 +++++- 4 files changed, 647 insertions(+), 3 deletions(-) create mode 100644 .github/maple/publish.py create mode 100644 .github/maple/test_publish.py create mode 100644 .github/workflows/maple-publish.yml diff --git a/.github/maple/publish.py b/.github/maple/publish.py new file mode 100644 index 00000000..99fc5f3a --- /dev/null +++ b/.github/maple/publish.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python3 +"""Release the two crates this fork changes. MAPLE.md describes the process. + + plan Check that the tagged commit may be released and say which crates + crates.io does not have yet. Uses no credential. + publish Repeat that check, then upload the missing crates in dependency + order, waiting for the registry index between them. +""" + +import json +import os +import re +import subprocess +import sys +import time +import urllib.error +import urllib.request + +# Dependency order: maple-sigstore-verify pins maple-sigstore-rekor exactly, so +# it cannot be packaged until that version is in the index. Nothing else in the +# workspace is ever published from this fork. +CRATES = ("maple-sigstore-rekor", "maple-sigstore-verify") +TAG = re.compile(r"refs/tags/maple-v(((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))-maple\.[1-9]\d*)\Z") +INDEX = "https://index.crates.io" +USER_AGENT = "maple-sigstore-publish (https://github.com/MaplePrivacyLabs/sigstore-rust)" +POLL_SECONDS = 10 +# How long to wait for an uploaded version to be served. Cargo's own wait can +# end early, and an upload can succeed even when Cargo reports a failure. +SERVED_AFTER_SUCCESS = 15 * 60 +SERVED_AFTER_FAILURE = 3 * 60 + + +class Refused(Exception): + """The release must not go ahead. The message says why.""" + + +def require(condition, message): + if not condition: + raise Refused(message) + + +def output(*command): + return subprocess.run(command, check=True, stdout=subprocess.PIPE, text=True).stdout + + +# --- Which commit may be released ------------------------------------------- + + +def tagged_version(ref): + """The crate version and the upstream release a maple-v tag names.""" + match = TAG.fullmatch(ref) + require(match, "This run is not for a tag named maple-v-maple.") + return match.group(1), match.group(2) + + +def maple_heads(remote="origin"): + """Branch heads under maple/, read from the remote and not from this checkout.""" + heads = {} + for line in output("git", "ls-remote", "--heads", remote, "refs/heads/maple/*").splitlines(): + sha, ref = line.split() + heads[ref.removeprefix("refs/heads/")] = sha + return heads + + +def publish_branch(sha, heads, parents, upstream): + """The maple/-publish branch whose head is this commit. + + The commit must be that head, and its only parent must be the head of + maple/: the reviewed changes plus the one rename commit, nothing else. + """ + at_head = sorted(name for name, head in heads.items() if name.endswith("-publish") and head == sha) + require(len(at_head) == 1, "The tagged commit is not the head of exactly one maple/-publish branch") + branch = at_head[0] + base = branch.removesuffix("-publish") + release = base.removeprefix("maple/") + require(release in (upstream, upstream.rpartition(".")[0]), + f"{branch} is not the publish branch for upstream {upstream}") + require(base in heads, f"{base} does not exist") + require(parents == [heads[base]], f"{branch} must be exactly one commit on top of the head of {base}") + return branch, base + + +def check_manifests(metadata, version, upstream): + """The two crates carry the tagged version and pin their workspace siblings exactly.""" + packages = {package["name"]: package for package in metadata["packages"]} + for name in CRATES: + require(name in packages, f"{name} is not a package in this workspace") + package = packages[name] + require(package["version"] == version, f"{name} is at {package['version']}, but the tag says {version}") + require(package.get("publish") in (None, ["crates-io"]), f"{name} does not allow publishing to crates.io") + for dependency in package["dependencies"]: + # A path means a crate of this workspace. Dev-dependencies never reach a consumer. + if dependency.get("path") is None or dependency.get("kind") == "dev": + continue + expected = f"={version}" if dependency["name"] in CRATES else f"={upstream}" + require(dependency["req"] == expected, + f"{name} must depend on {dependency['name']} at exactly {expected[1:]}, not {dependency['req']}") + require(any(dependency["name"] == CRATES[0] and dependency.get("kind") is None + for dependency in packages[CRATES[1]]["dependencies"]), + f"{CRATES[1]} does not depend on {CRATES[0]}") + renamed = sorted(name for name, package in packages.items() + if name not in CRATES and ("maple" in name or "maple" in package["version"])) + require(not renamed, f"Only {' and '.join(CRATES)} may carry a Maple name or version, not {', '.join(renamed)}") + + +# --- What crates.io already has --------------------------------------------- + + +def index_versions(name): + """Every version the sparse index serves for a crate, or None if it has never been published.""" + request = urllib.request.Request(f"{INDEX}/{name[:2]}/{name[2:4]}/{name}", headers={"User-Agent": USER_AGENT}) + try: + with urllib.request.urlopen(request, timeout=30) as response: + lines = response.read().decode().splitlines() + except urllib.error.HTTPError as error: + if error.code == 404: + return None + raise + return {json.loads(line)["vers"] for line in lines if line.strip()} + + +def plan(environ, versions=index_versions): + """Check the release commit, then return its version, the crates still missing and how to authenticate.""" + version, upstream = tagged_version(environ.get("GITHUB_REF", "")) + sha = environ["GITHUB_SHA"] + parents = output("git", "rev-list", "--parents", "-n", "1", sha).split()[1:] + branch, base = publish_branch(sha, maple_heads(), parents, upstream) + check_manifests(json.loads(output("cargo", "metadata", "--no-deps", "--format-version", "1", "--locked")), + version, upstream) + print(f"{sha} is the head of {branch}, one commit on top of {base}.") + return (version, *registry_state(version, versions)) + + +def registry_state(version, versions): + """The crates not yet published at this version, and the credential the upload needs. + + crates.io accepts trusted publishing only for a crate that already exists, + so a crate's first version needs the bootstrap token. + """ + served = {name: versions(name) for name in CRATES} + missing = [name for name in CRATES if version not in (served[name] or ())] + for name in CRATES: + print(f"{name} {version}: {'to publish' if name in missing else 'already on crates.io'}") + if not missing: + return missing, "none" + return missing, "bootstrap" if any(served[name] is None for name in missing) else "trusted" + + +# --- Uploading ---------------------------------------------------------------- + + +def cargo_publish(name): + # --no-verify: the check job built, tested and dry-ran this commit without a + # credential. Building here would run dependency build scripts next to the token. + return subprocess.run(["cargo", "publish", "--locked", "--no-verify", "-p", name]).returncode + + +def wait_until_served(name, version, seconds, versions=index_versions, sleep=time.sleep): + """True once the index serves this version; False if it has not after the given time.""" + for attempt in range(seconds // POLL_SECONDS + 1): + if attempt: + sleep(POLL_SECONDS) + try: + if version in (versions(name) or ()): + return True + except OSError as error: + print(f"Reading the index for {name} failed ({error}); trying again.") + return False + + +def publish(version, environ, versions=index_versions, upload=cargo_publish, sleep=time.sleep): + """Upload each crate the index lacks, in order, and wait for it to be served before the next.""" + for name in CRATES: + if version in (versions(name) or ()): + print(f"{name} {version} is already on crates.io; skipping it.") + continue + require(environ.get("CARGO_REGISTRY_TOKEN"), + f"No crates.io credential for {name}. A crate's first version needs CRATES_BOOTSTRAP_TOKEN in the " + "maple-crates environment; later versions need its trusted publisher entry on crates.io.") + status = upload(name) + wait = SERVED_AFTER_SUCCESS if status == 0 else SERVED_AFTER_FAILURE + require(wait_until_served(name, version, wait, versions, sleep), + f"{name} {version} is not in the crates.io index (cargo publish exited with {status}). " + "Nothing after it was uploaded. Rerun this job once the cause is fixed.") + print(f"{name} {version} is published and served by the index.") + + +def github_output(environ, **values): + if environ.get("GITHUB_OUTPUT"): + with open(environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out: + out.writelines(f"{key}={value}\n" for key, value in values.items()) + + +def main(argv, environ): + require(len(argv) == 2 and argv[1] in ("plan", "publish"), "Usage: publish.py plan|publish") + version, missing, auth = plan(environ) + if argv[1] == "plan": + github_output(environ, version=version, missing=" ".join(missing), auth=auth) + elif missing: + publish(version, environ) + else: + print("Both crates are already published at this version. Nothing to do.") + + +if __name__ == "__main__": + try: + main(sys.argv, os.environ) + except Refused as refusal: + sys.exit(f"Refused: {refusal}") diff --git a/.github/maple/test_publish.py b/.github/maple/test_publish.py new file mode 100644 index 00000000..67ab916d --- /dev/null +++ b/.github/maple/test_publish.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python3 +"""Tests for publish.py. Run: python3 -m unittest discover -s .github/maple -p 'test_*.py'""" + +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +import publish + +VERSION, UPSTREAM = "0.17.0-maple.1", "0.17.0" +REKOR, VERIFY = publish.CRATES +GIT_ENV = { + "PATH": os.environ["PATH"], "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1", + "GIT_AUTHOR_NAME": "test", "GIT_AUTHOR_EMAIL": "test@example.invalid", + "GIT_COMMITTER_NAME": "test", "GIT_COMMITTER_EMAIL": "test@example.invalid", +} + + +def dependency(name, req, kind=None, path="/workspace/crates/x"): + return {"name": name, "req": req, "kind": kind, "path": path} + + +def metadata(**changes): + """cargo metadata for a correct publish branch, with one field of it changed.""" + packages = { + REKOR: {"name": REKOR, "version": VERSION, "publish": None, "dependencies": [ + dependency("sigstore-types", f"={UPSTREAM}"), + dependency("serde", "^1.0", path=None)]}, + VERIFY: {"name": VERIFY, "version": VERSION, "publish": None, "dependencies": [ + dependency(REKOR, f"={VERSION}"), + dependency("sigstore-bundle", f"={UPSTREAM}"), + dependency("sigstore-sign", "*", kind="dev")]}, + "sigstore-types": {"name": "sigstore-types", "version": UPSTREAM, "publish": None, "dependencies": []}, + } + for name, package in changes.items(): + packages[name.replace("_", "-")] = package + return {"packages": list(packages.values())} + + +class TagTests(unittest.TestCase): + def test_a_maple_tag_names_the_crate_version_and_the_upstream_release(self): + self.assertEqual(publish.tagged_version(f"refs/tags/maple-v{VERSION}"), (VERSION, UPSTREAM)) + + def test_other_refs_are_refused(self): + for ref in ("refs/tags/maple-v0.17.0", "refs/tags/v0.17.0-maple.1", "refs/tags/maple-v0.17.0-maple.0", + "refs/tags/maple-v0.17-maple.1", "refs/heads/maple/0.17-publish", + "refs/tags/maple-v0.17.0-maple.1-rc1", ""): + with self.subTest(ref=ref), self.assertRaises(publish.Refused): + publish.tagged_version(ref) + + +class PublishBranchTests(unittest.TestCase): + HEADS = {"maple/0.17": "b" * 40, "maple/0.17-publish": "a" * 40, "maple/0.16": "d" * 40, + "maple/0.16-publish": "c" * 40} + + def branch(self, sha="a" * 40, heads=None, parents=("b" * 40,), upstream=UPSTREAM): + return publish.publish_branch(sha, self.HEADS if heads is None else heads, list(parents), upstream) + + def test_the_head_of_a_publish_branch_one_commit_on_its_release_branch_is_accepted(self): + self.assertEqual(self.branch(), ("maple/0.17-publish", "maple/0.17")) + + def test_a_release_branch_named_after_the_full_upstream_version_is_accepted(self): + heads = {"maple/0.17.1": "b" * 40, "maple/0.17.1-publish": "a" * 40} + self.assertEqual(self.branch(heads=heads, upstream="0.17.1"), ("maple/0.17.1-publish", "maple/0.17.1")) + + def test_a_commit_that_is_not_a_publish_branch_head_is_refused(self): + for sha in ("b" * 40, "e" * 40): # the release branch head, and a commit on no branch + with self.subTest(sha=sha), self.assertRaisesRegex(publish.Refused, "not the head"): + self.branch(sha=sha) + + def test_more_than_the_one_rename_commit_is_refused(self): + with self.assertRaisesRegex(publish.Refused, "exactly one commit"): + self.branch(parents=("f" * 40,)) # the parent is not the release branch head + + def test_a_release_branch_that_moved_after_the_publish_branch_was_built_is_refused(self): + with self.assertRaisesRegex(publish.Refused, "exactly one commit"): + self.branch(heads={**self.HEADS, "maple/0.17": "9" * 40}) + + def test_a_merge_commit_is_refused(self): + with self.assertRaisesRegex(publish.Refused, "exactly one commit"): + self.branch(parents=("b" * 40, "d" * 40)) + + def test_a_tag_for_another_release_line_is_refused(self): + with self.assertRaisesRegex(publish.Refused, "not the publish branch for upstream 0.18.0"): + self.branch(upstream="0.18.0") + + def test_a_publish_branch_without_its_release_branch_is_refused(self): + with self.assertRaisesRegex(publish.Refused, "does not exist"): + self.branch(heads={"maple/0.17-publish": "a" * 40}) + + def test_two_publish_branches_at_the_same_commit_are_refused(self): + with self.assertRaisesRegex(publish.Refused, "exactly one"): + self.branch(heads={**self.HEADS, "maple/0.16-publish": "a" * 40}) + + +class RemoteHeadsTests(unittest.TestCase): + """The branch heads and parents come from Git as the workflow reads them.""" + + def git(self, cwd, *arguments): + return subprocess.run(["git", *arguments], cwd=cwd, env=GIT_ENV, check=True, text=True, + capture_output=True).stdout.strip() + + def test_heads_are_read_from_the_remote_and_the_parent_from_the_commit(self): + with tempfile.TemporaryDirectory() as temporary: + origin, work = Path(temporary, "origin"), Path(temporary, "work") + origin.mkdir() + self.git(origin, "init", "--quiet", "--initial-branch", "main") + self.git(origin, "commit", "--quiet", "--allow-empty", "-m", "upstream release") + self.git(origin, "switch", "--quiet", "-c", "maple/0.17") + self.git(origin, "commit", "--quiet", "--allow-empty", "-m", "our change") + base = self.git(origin, "rev-parse", "HEAD") + self.git(origin, "switch", "--quiet", "-c", "maple/0.17-publish") + self.git(origin, "commit", "--quiet", "--allow-empty", "-m", "rename") + head = self.git(origin, "rev-parse", "HEAD") + self.git(temporary, "clone", "--quiet", str(origin), str(work)) + # A branch that exists only in this checkout must not count. + self.git(work, "branch", "maple/9.9-publish", head) + previous = os.getcwd() + os.chdir(work) + self.addCleanup(os.chdir, previous) + environment = dict(os.environ) + os.environ.update(GIT_ENV) + self.addCleanup(lambda: (os.environ.clear(), os.environ.update(environment))) + heads = publish.maple_heads() + self.assertEqual(heads, {"maple/0.17": base, "maple/0.17-publish": head}) + parents = publish.output("git", "rev-list", "--parents", "-n", "1", head).split()[1:] + self.assertEqual(publish.publish_branch(head, heads, parents, UPSTREAM), + ("maple/0.17-publish", "maple/0.17")) + + +class ManifestTests(unittest.TestCase): + def refused(self, pattern, **changes): + with self.assertRaisesRegex(publish.Refused, pattern): + publish.check_manifests(metadata(**changes), VERSION, UPSTREAM) + + def package(self, name, **fields): + correct = {package["name"]: package for package in metadata()["packages"]}[name] + return {**correct, **fields} + + def test_the_publish_branch_manifests_are_accepted(self): + publish.check_manifests(metadata(), VERSION, UPSTREAM) + + def test_a_crate_at_another_version_than_the_tag_is_refused(self): + self.refused("is at 0.17.0-maple.2", maple_sigstore_rekor=self.package(REKOR, version="0.17.0-maple.2")) + + def test_a_missing_crate_is_refused(self): + without = {"packages": [p for p in metadata()["packages"] if p["name"] != VERIFY]} + with self.assertRaisesRegex(publish.Refused, "not a package"): + publish.check_manifests(without, VERSION, UPSTREAM) + + def test_a_crate_that_forbids_publishing_is_refused(self): + self.refused("does not allow", maple_sigstore_verify=self.package(VERIFY, publish=[])) + + def test_an_unmodified_sibling_must_be_pinned_to_the_upstream_release(self): + loose = self.package(REKOR, dependencies=[dependency("sigstore-types", "^0.17.0")]) + self.refused("sigstore-types at exactly 0.17.0", maple_sigstore_rekor=loose) + + def test_the_renamed_sibling_must_be_pinned_to_this_version(self): + loose = self.package(VERIFY, dependencies=[dependency(REKOR, f"={UPSTREAM}")]) + self.refused(f"{REKOR} at exactly {VERSION}", maple_sigstore_verify=loose) + + def test_verify_must_depend_on_rekor(self): + self.refused("does not depend", maple_sigstore_verify=self.package(VERIFY, dependencies=[])) + + def test_no_other_crate_may_carry_a_maple_name_or_version(self): + self.refused("maple-sigstore-tsa", maple_sigstore_tsa={ + "name": "maple-sigstore-tsa", "version": VERSION, "publish": None, "dependencies": []}) + self.refused("sigstore-types", sigstore_types={ + "name": "sigstore-types", "version": VERSION, "publish": None, "dependencies": []}) + + +class Registry: + """A stand-in index and upload: what is served, what was uploaded, and when uploads appear.""" + + def __init__(self, served, appears_after=0, upload_status=0, accepts=True): + self.served = {name: set(versions) if versions is not None else None for name, versions in served.items()} + self.appears_after, self.upload_status, self.accepts = appears_after, upload_status, accepts + self.uploads, self.pending, self.slept = [], {}, 0 + + def versions(self, name): + if name in self.pending: + self.pending[name] -= 1 + if self.pending[name] < 0: + del self.pending[name] + self.served[name] = (self.served[name] or set()) | {VERSION} + versions = self.served.get(name) + return None if versions is None else set(versions) + + def upload(self, name): + # Cargo refuses to package verify until the index serves the rekor version it pins. + if name == VERIFY and VERSION not in (self.served.get(REKOR) or ()): + raise AssertionError("verify was uploaded before the index served rekor") + self.uploads.append(name) + if self.accepts: + self.pending[name] = self.appears_after + return self.upload_status + + def sleep(self, seconds): + self.slept += seconds + + def publish(self, token="token"): + publish.publish(VERSION, {"CARGO_REGISTRY_TOKEN": token}, self.versions, self.upload, self.sleep) + + +class RegistryStateTests(unittest.TestCase): + def state(self, served): + return publish.registry_state(VERSION, Registry(served).versions) + + def test_crates_that_were_never_published_need_the_bootstrap_token(self): + self.assertEqual(self.state({REKOR: None, VERIFY: None}), ([REKOR, VERIFY], "bootstrap")) + + def test_a_rerun_after_only_the_first_upload_publishes_the_second(self): + self.assertEqual(self.state({REKOR: {VERSION}, VERIFY: None}), ([VERIFY], "bootstrap")) + + def test_a_later_version_of_existing_crates_uses_trusted_publishing(self): + earlier = {"0.16.0-maple.1"} + self.assertEqual(self.state({REKOR: earlier, VERIFY: earlier}), ([REKOR, VERIFY], "trusted")) + + def test_nothing_is_left_when_both_are_published(self): + self.assertEqual(self.state({REKOR: {VERSION}, VERIFY: {VERSION}}), ([], "none")) + + +class PublishTests(unittest.TestCase): + def test_rekor_is_uploaded_first_and_verify_only_once_the_index_serves_it(self): + registry = Registry({REKOR: None, VERIFY: None}, appears_after=3) + registry.publish() + self.assertEqual(registry.uploads, [REKOR, VERIFY]) + self.assertGreaterEqual(registry.slept, 2 * 3 * publish.POLL_SECONDS) + + def test_a_crate_that_is_already_served_is_not_uploaded_again(self): + registry = Registry({REKOR: {VERSION}, VERIFY: None}) + registry.publish() + self.assertEqual(registry.uploads, [VERIFY]) + + def test_nothing_is_uploaded_when_both_are_served(self): + registry = Registry({REKOR: {VERSION}, VERIFY: {VERSION}}) + registry.publish(token="") + self.assertEqual(registry.uploads, []) + + def test_an_upload_that_cargo_reports_as_failed_but_the_index_serves_counts_as_published(self): + registry = Registry({REKOR: None, VERIFY: None}, upload_status=101) + registry.publish() + self.assertEqual(registry.uploads, [REKOR, VERIFY]) + + def test_a_refused_upload_stops_before_the_second_crate(self): + registry = Registry({REKOR: None, VERIFY: None}, upload_status=101, accepts=False) + with self.assertRaisesRegex(publish.Refused, "not in the crates.io index"): + registry.publish() + self.assertEqual(registry.uploads, [REKOR]) + self.assertLessEqual(registry.slept, publish.SERVED_AFTER_FAILURE) + + def test_an_accepted_upload_the_index_never_serves_fails_the_job(self): + registry = Registry({REKOR: None, VERIFY: None}, accepts=False) + with self.assertRaisesRegex(publish.Refused, "not in the crates.io index"): + registry.publish() + self.assertEqual(registry.uploads, [REKOR]) + + def test_no_upload_is_attempted_without_a_credential(self): + registry = Registry({REKOR: None, VERIFY: None}) + with self.assertRaisesRegex(publish.Refused, "No crates.io credential"): + registry.publish(token="") + self.assertEqual(registry.uploads, []) + + def test_an_index_error_while_waiting_is_retried(self): + registry = Registry({REKOR: {VERSION}, VERIFY: None}) + calls = iter([OSError("reset"), None, {VERSION}]) + + def versions(name): + answer = next(calls) + if isinstance(answer, OSError): + raise answer + return answer + + self.assertTrue(publish.wait_until_served(VERIFY, VERSION, 60, versions, registry.sleep)) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/maple-publish.yml b/.github/workflows/maple-publish.yml new file mode 100644 index 00000000..1f7834a0 --- /dev/null +++ b/.github/workflows/maple-publish.yml @@ -0,0 +1,100 @@ +name: Maple publish + +# Publishes the two crates this fork changes, maple-sigstore-rekor and +# maple-sigstore-verify, to crates.io. Nothing else here publishes anything. +# +# It runs for a tag maple-v and refuses unless the tagged commit is +# the head of a maple/-publish branch that is exactly one commit on +# top of maple/. The upload waits for a reviewer in the maple-crates +# environment. This file lives on the Maple branches only, never on main, so +# it follows each release line. MAPLE.md has the steps. +on: + push: + tags: + - "maple-v*" + +permissions: {} + +# One release at a time; a second tag waits instead of racing the first. +concurrency: + group: maple-publish + cancel-in-progress: false + +jobs: + check: + name: Check the release commit, test and dry-run + if: >- + github.repository == 'MaplePrivacyLabs/sigstore-rust' && + github.repository_id == '1461849084' && + github.repository_owner_id == '322649754' + runs-on: ubuntu-latest + timeout-minutes: 60 + permissions: + contents: read + outputs: + version: ${{ steps.plan.outputs.version }} + missing: ${{ steps.plan.outputs.missing }} + auth: ${{ steps.plan.outputs.auth }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Test the release script + run: python3 -I -m unittest discover -s .github/maple -p 'test_*.py' + + - name: Install Rust toolchain + run: rustup toolchain install + + - name: Refuse anything but a publish branch head, and read crates.io + id: plan + run: python3 -I .github/maple/publish.py plan + + - name: Run tests + run: cargo test --all-features --workspace --locked + + # One invocation for both, so Cargo can build the second crate against + # the first before either is in the registry. + - name: Dry-run the crates that are not published yet + if: steps.plan.outputs.missing != '' + env: + MISSING: ${{ steps.plan.outputs.missing }} + run: | + packages=() + for crate in $MISSING; do packages+=(-p "$crate"); done + cargo publish --dry-run --locked "${packages[@]}" + + publish: + name: Publish to crates.io + needs: check + # Nothing to approve when both crates are already published at this version. + if: needs.check.outputs.auth != 'none' + runs-on: ubuntu-latest + timeout-minutes: 60 + environment: maple-crates + permissions: + contents: read + id-token: write # the crates.io trusted-publishing exchange + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Install Rust toolchain + run: rustup toolchain install + + # crates.io offers trusted publishing only for a crate that already + # exists. A crate's first version uses the environment's bootstrap token. + - name: Obtain a short-lived crates.io credential + id: auth + if: needs.check.outputs.auth == 'trusted' + uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 + + # Repeats the release-commit check: the branches may have moved while + # this job waited for approval. + - name: Publish in dependency order + env: + CARGO_REGISTRY_TOKEN: ${{ needs.check.outputs.auth == 'bootstrap' && secrets.CRATES_BOOTSTRAP_TOKEN || steps.auth.outputs.token }} + run: python3 -I .github/maple/publish.py publish diff --git a/MAPLE.md b/MAPLE.md index 6cda7c0f..01d3417c 100644 --- a/MAPLE.md +++ b/MAPLE.md @@ -25,7 +25,7 @@ other crate is unmodified upstream. | Branch | Starts from | Holds | Rewritten? | | --- | --- | --- | --- | | `main` | upstream `main` | A mirror of upstream. Nothing of Maple's. | Fast-forwarded only | -| `maple/`, for example `maple/0.17` | The upstream release tag | The three changes above, as their own commits, and this file | Never, once something pins a commit on it | +| `maple/`, for example `maple/0.17` | The upstream release tag | The three changes above, as their own commits, this file, and the publish workflow | Never, once something pins a commit on it | | `maple/-publish` | `maple/` | Exactly one commit: the crate renames | Rebuilt whenever `maple/` moves | | `upstream/p384-rekor-v2` | upstream `main` | One commit, the P-384 fix alone: the pull request above | Rebased as upstream asks | | `maple/p384-rekor-v2`, `maple/p384-rekor-v2-publish` | The 0.16.0 tag | The same work on upstream 0.16.0 | Frozen; see below | @@ -75,9 +75,64 @@ pins it. Do new work on `maple/`. vectors. 3. Rebuild `maple/-publish` as one commit on top: the two renames, their versions, and the exact pins on the other crates. -4. `cargo publish --dry-run` both renamed crates, `maple-sigstore-rekor` - first, since `maple-sigstore-verify` depends on it. +4. `cargo publish --dry-run -p maple-sigstore-rekor -p maple-sigstore-verify`: + both in one command, since `maple-sigstore-verify` depends on a + `maple-sigstore-rekor` that is not in the registry yet. 5. Update this file's table. +6. Publish, as described below. + +The publish workflow and its script are commits on the Maple branch, so the +rebase in step 1 carries them to the new release line. Nothing in them names +a release. + +## Publishing to crates.io + +`.github/workflows/maple-publish.yml` publishes `maple-sigstore-rekor` and +then `maple-sigstore-verify`, and nothing else. To release: + +1. Make sure `maple/-publish` is rebuilt on the current head of + `maple/` and both crates carry the version to release. +2. Tag that branch head `maple-v`, for example + `maple-v0.17.0-maple.1`, and push the tag. +3. The `check` job refuses unless the tagged commit is the head of a + `maple/-publish` branch, exactly one commit on top of + `maple/`, with manifests that match the tag. It then runs the + workspace tests and a dry run. +4. The `publish` job waits for a reviewer in the `maple-crates` environment, + repeats the check, uploads `maple-sigstore-rekor`, waits until the + crates.io index serves it, and uploads `maple-sigstore-verify`. + +A rerun is safe. A crate the index already serves at this version is skipped, +and when both are there the run says so and asks for no approval. To redo a +release after a fix, rebuild the publish branch with the next build number +and push a new tag; a published version can never be replaced. + +### Credentials + +crates.io allows trusted publishing only for a crate that already exists. + +- **A crate's first version** is uploaded with an API token held as the + `CRATES_BOOTSTRAP_TOKEN` secret of the `maple-crates` environment, never as + a repository secret. Scope it to publishing new crates named + `maple-sigstore-*`, give it a short expiry, and delete the secret and + revoke the token once both crates exist. +- **Every later version** uses trusted publishing. Each crate needs its own + entry on crates.io (crate Settings, Trusted Publishing): repository + `MaplePrivacyLabs/sigstore-rust`, workflow `maple-publish.yml`, environment + `maple-crates`. + +The workflow picks the method from what the index serves; there is nothing to +select. + +### The workflows inherited from upstream + +Upstream's own workflows come with every branch, including `release-plz.yml`, +which releases upstream's crates on a push to `main`. They cannot publish from +this fork: it holds no repository secret, upstream's crates trust only +upstream's repository, and the two Maple crates trust only +`maple-publish.yml` in `maple-crates`. Keep it that way: never name the +publishing environment `crates-io` (the one `release-plz.yml` uses), and keep +`release-plz.yml` disabled in this repository's Actions settings. ## When the fork can go away From 2c617bbda999f3f8a1a153444cbc3f32184bd323 Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:00:18 -0800 Subject: [PATCH 2/3] docs: describe the locked crates-io environment Co-Authored-By: Claude --- MAPLE.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MAPLE.md b/MAPLE.md index 01d3417c..e262271c 100644 --- a/MAPLE.md +++ b/MAPLE.md @@ -130,9 +130,14 @@ Upstream's own workflows come with every branch, including `release-plz.yml`, which releases upstream's crates on a push to `main`. They cannot publish from this fork: it holds no repository secret, upstream's crates trust only upstream's repository, and the two Maple crates trust only -`maple-publish.yml` in `maple-crates`. Keep it that way: never name the -publishing environment `crates-io` (the one `release-plz.yml` uses), and keep -`release-plz.yml` disabled in this repository's Actions settings. +`maple-publish.yml` in `maple-crates`. + +As a second guard, this repository has an environment named `crates-io`, the +one `release-plz.yml` asks for, that no branch or tag is allowed to use, so +that job cannot start here. Keep both guards: never give `crates-io` an +allowed ref or a secret, and never point a crate's trusted publisher at it. +GitHub lists `release-plz.yml` under Actions only after a push to `main` has +run it once; disable it there when it appears. ## When the fork can go away From 874939a085430dddedeaa1b7c3328f7b4f716bcb Mon Sep 17 00:00:00 2001 From: Anthony Ronning <101225832+AnthonyRonning@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:04:29 -0800 Subject: [PATCH 3/3] docs: say who can push a release tag Co-Authored-By: Claude --- MAPLE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MAPLE.md b/MAPLE.md index e262271c..e353283c 100644 --- a/MAPLE.md +++ b/MAPLE.md @@ -93,7 +93,9 @@ then `maple-sigstore-verify`, and nothing else. To release: 1. Make sure `maple/-publish` is rebuilt on the current head of `maple/` and both crates carry the version to release. 2. Tag that branch head `maple-v`, for example - `maple-v0.17.0-maple.1`, and push the tag. + `maple-v0.17.0-maple.1`, and push the tag. A repository rule lets only + organization admins create, move or delete `maple-v*` tags, because the + checks below run from the tagged commit itself. 3. The `check` job refuses unless the tagged commit is the head of a `maple/-publish` branch, exactly one commit on top of `maple/`, with manifests that match the tag. It then runs the