Skip to content

Publish links-queue to crates.io with trusted publishing (token fallback) - #54

Merged
konard merged 4 commits into
mainfrom
issue-53-38f499605add
Oct 23, 2026
Merged

konard merged 4 commits into
mainfrom
issue-53-38f499605add

Conversation

@konard

@konard konard commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #53

Decision: links-queue is meant for crates.io. It is a library plus a CLI binary, and the docs already send users to crates.io (docs/README.md links https://crates.io/crates/links-queue, and the install guides say links-queue = "0.11"). The name is still free on crates.io (GET /api/v1/crates/links-queue → crate links-queue does not exist). So instead of publish = false, this PR adds a crates.io release path that follows the 2026-10-13 policy comment: trusted publishing (OIDC) first, with a token fallback.

Release pipeline (.github/workflows/rust.yml)

  • Both Auto Release and Manual Release now have id-token: write and these steps:
    • rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6. That is the newest release; I checked that v1.0.6 and v1 both resolve to this SHA. The step has continue-on-error: true.
    • Publish to crates.io, using CARGO_REGISTRY_TOKEN: ${{ steps.crates_auth.outputs.token || secrets.CARGO_REGISTRY_TOKEN || secrets.CARGO_TOKEN }}.
  • Publishing runs before the GitHub release is created. After publishing, the job checks that crates.io actually serves the new version.
  • If neither credential is available, or crates.io rejects one, the release job fails with an ::error:: that explains what to do: run package-registry-manager setup --repository . --registry crates-io --execute for the first version, register the trusted publisher (owner link-foundation, repository links-queue, workflow rust.yml, no environment), or add the CARGO_REGISTRY_TOKEN secret. Nothing is hidden by continue-on-error.
  • New helper rust/scripts/crates-io.mjs (Node built-ins only), with two commands:
    • status: is the Cargo.toml version already on crates.io?
    • publish: skips versions that are already published, warns when it falls back to the token, runs cargo publish, treats "already uploaded/exists" as success, and polls crates.io afterwards.

Root-cause fix: Rust releases never ran

Every Rust run on main skipped Auto Release. For example, run 37563629623 shows lint/test/build success but Auto Release skipped, and the repository has no rust-v* tag. The job condition had no status function, so the job was skipped because one of its dependencies was skipped: changelog on push. The same thing happened to lint (and through it, Manual Release) on workflow_dispatch, where detect-changes is skipped. I fixed this with the always() && … needs.build.result == 'success' pattern that js.yml already uses. Without this fix the new publish step would never have run.

Robustness

  • A version that is tagged but missing from crates.io is now released by the next run on main. Before, "tag exists" alone meant "already released".
  • A re-run of a release that already pushed its tag checks out that tag, so it publishes the bumped version and not the unbumped Cargo.toml.
  • PR CI runs cargo publish --dry-run. I checked that it only warns, and does not fail, once a version exists.
  • Cargo.toml excludes changelog.d/, scripts/ and package-lock.json from the crate (86 → 75 files).

Docs

  • rust/README.md: installation (cargo add / cargo install) and a Releasing section covering the one-time first-publish setup.
  • The install snippets in docs/ now say links-queue = "0.3" instead of the non-existent 0.11.
  • Changelog fragment (patch).

One-time maintainer action (cannot be done from CI or this PR)

crates.io can only register a trusted publisher for a crate that already exists. So the first version needs one of these:

  1. After merging, run package-registry-manager setup --repository . --registry crates-io --execute, as step 2 of the issue says. It publishes the first version with a short-lived token and registers the trusted publisher. or
  2. Add a CARGO_REGISTRY_TOKEN secret before merging. The first release then publishes through the fallback; afterwards, register the trusted publisher.

Until one of these is done, the Auto Release job on main will fail with the instructions above. That is intentional. Every later version publishes from CI with no secret.

How to reproduce / verify

  • node --test rust/scripts/crates-io.test.mjs: 11 unit tests, also run in the CI lint job. They cover Cargo.toml parsing (the package name, not the [lib] name), a guard that publish = false is not set, the trusted-publisher text, classification of cargo publish failures, the help messages, and how crates.io status codes map to true/false/unknown.
  • experiments/issue-53-crates-io-publish-paths.sh exercises the paths against the real crates.io without uploading anything:
    • status → published=false
    • publishing without credentials → the explicit error and exit 1
    • publishing an existing version (serde 1.0.0) → skipped and verified, exit 0
  • Local checks: cargo fmt --check, cargo clippy --all-targets --all-features with -Dwarnings, cargo test --all-features (513 passed, 0 failed), cargo publish --dry-run and actionlint on rust.yml all pass.

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #53
@konard konard self-assigned this Oct 23, 2026
Tries the trusted publishing token passed by the workflow, falls back to the
CARGO_REGISTRY_TOKEN / CARGO_TOKEN secret, skips versions already on
crates.io, explains missing or rejected credentials and verifies that
crates.io serves the published version.
Add id-token: write, rust-lang/crates-io-auth-action pinned to v1.0.6 with
continue-on-error, and a publish step using the OIDC token or the
CARGO_REGISTRY_TOKEN / CARGO_TOKEN fallback to both release jobs.

Fix the release job conditions: a skipped job in the dependency chain
(changelog on push, detect-changes on workflow_dispatch) skipped Auto
Release and Manual Release, so no Rust version was ever released.

Release versions that are tagged but missing from crates.io, run
cargo publish --dry-run in CI and keep release tooling out of the crate.
@konard konard changed the title [WIP] crates.io: publish links-queue with trusted publishing, or mark it publish = false Publish links-queue to crates.io with trusted publishing (token fallback) Oct 23, 2026
@konard
konard marked this pull request as ready for review October 23, 2026 07:57
@konard

konard commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Working session summary

PR #54 is ready for review: #54. I chose to publish links-queue to crates.io rather than set publish = false. The Rust release jobs now try trusted publishing (OIDC) first and fall back to the CARGO_REGISTRY_TOKEN / CARGO_TOKEN secret, as the policy comment asks. The release jobs only run on main or a manual run, so CI on the PR couldn't test the actual publish.

Why publish: it's a library plus a command-line tool, the docs already link to crates.io/crates/links-queue and tell users to add it as a dependency, and the name is still free on crates.io.

What changed in .github/workflows/rust.yml:

  • Publishing: both release jobs (automatic and manual) now:
  - get the permission GitHub needs to issue an OIDC token;
  - run `rust-lang/crates-io-auth-action` pinned to the v1.0.6 commit, with `continue-on-error: true`;
  - publish with the OIDC token, or the token secret if the exchange fails;
  - check that crates.io actually serves the new version.

Publishing happens before the GitHub release is created. If no credential works, the job fails with a message saying exactly what to set up. That logic is in a new script, rust/scripts/crates-io.mjs.

  • A bug that blocked this: no Rust version was ever released. Every run on main skipped the automatic release job (for example run 37563629623, where everything else passed), and there is no rust-v* tag. The cause: GitHub skips a job when a job it depends on was skipped, and the changelog check is always skipped on pushes. Manual releases were blocked the same way. I fixed both with the always() pattern that js.yml already uses; without it the new publish step would never run.
  • Recovery: a version that got a tag but never reached crates.io is published on the next run, and re-running a failed release publishes the version it already tagged.
  • PR checks: CI now runs cargo publish --dry-run. I checked that this only warns, rather than fails, once a version already exists.

Smaller changes:

  • Cargo.toml leaves the release tooling out of the published crate (86 → 75 files).
  • rust/README.md gets an Installation section and a Releasing section.
  • The install snippets in docs/ now say links-queue = "0.3" instead of "0.11", a version that doesn't exist.
  • A changelog fragment (patch).

Tests: 11 unit tests for the new script, also run in CI, and a script in experiments/ that tries the publish paths against crates.io without uploading anything. Locally, fmt, clippy with warnings as errors, 513 Rust tests and the publish dry-run all pass, and actionlint finds nothing in the workflow. The PR's CI run (39920566005) passed every job; the two release jobs were skipped, as expected on a PR.

Still needed from a maintainer: crates.io only lets you register a trusted publisher for a crate that already exists, so the first version needs one of these:

  1. After merging, run package-registry-manager setup --repository . --registry crates-io --execute (step 2 of the issue). It publishes the first version and registers the trusted publisher.
  2. Or add a CARGO_REGISTRY_TOKEN repository secret before merging; the first release then publishes with the token, and you register the trusted publisher afterwards.

Until one of these is done, the release job on main will fail with those instructions. That's on purpose; after the first version, every release publishes from CI with no secret.


This summary was automatically extracted from the AI working session output.

@konard

konard commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $1.831127

📊 Context and tokens usage:

  • 88.6K / 1M (9%) input tokens, 34.3K / 128K (27%) output tokens

Total: (86 new + 79.2K cache writes + 2.6M cache reads) input tokens, 34.3K output tokens, $1.831127 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus (claude-opus-5-5)
  • Thinking level: high (~23999 tokens)
  • Model: Claude Opus 5.5 (claude-opus-5-5)

📎 Log file uploaded as Gist (1383KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
konard merged commit 2612654 into main Oct 23, 2026
10 checks passed
@konard

konard commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

🎉 Auto-merged

This pull request has been automatically merged by hive-mind.

  • All CI checks have passed

Linked issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crates.io: publish links-queue with trusted publishing, or mark it publish = false

1 participant