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
85 changes: 81 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ jobs:
name: Lint and Format Check
runs-on: ubuntu-latest
needs: [detect-changes]
# always(): on workflow_dispatch detect-changes is skipped, and a skipped
# dependency would otherwise skip this job (and every release job after it).
if: |
always() && (
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
needs.detect-changes.outputs.rs-changed == 'true' ||
needs.detect-changes.outputs.toml-changed == 'true' ||
needs.detect-changes.outputs.mjs-changed == 'true' ||
needs.detect-changes.outputs.docs-changed == 'true' ||
needs.detect-changes.outputs.workflow-changed == 'true'
needs.detect-changes.outputs.workflow-changed == 'true')
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -150,6 +153,9 @@ jobs:
- name: Check file size limit
run: node scripts/check-file-size.mjs

- name: Test release scripts
run: node --test scripts/crates-io.test.mjs

# === TEST ===
test:
name: Test (${{ matrix.os }})
Expand Down Expand Up @@ -212,6 +218,9 @@ jobs:
- name: Check package
run: cargo package --list

- name: Verify crates.io package
run: cargo publish --dry-run

# === BENCHMARKS ===
bench:
name: Benchmarks
Expand Down Expand Up @@ -253,10 +262,15 @@ jobs:
auto-release:
name: Auto Release
needs: [lint, test, build]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# always(): changelog is skipped on push, and a skipped job anywhere in the
# dependency chain would otherwise skip this job, so no release ever ran.
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
# crates.io trusted publishing: crates-io-auth-action trades this job's
# GitHub OIDC token for a short-lived crates.io publish token.
id-token: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -280,12 +294,22 @@ jobs:
id: bump_type
run: node scripts/get-bump-type.mjs

- name: Check crates.io for current version
id: crate_status
run: node scripts/crates-io.mjs status

- name: Check if version already released or no fragments
id: check
env:
PUBLISHED: ${{ steps.crate_status.outputs.published }}
run: |
if [ "${{ steps.bump_type.outputs.has_fragments }}" != "true" ]; then
CURRENT_VERSION=$(grep -Po '(?<=^version = ")[^"]*' Cargo.toml)
if git rev-parse "rust-v$CURRENT_VERSION" >/dev/null 2>&1; then
if [ "$PUBLISHED" != "true" ]; then
echo "No changelog fragments but links-queue $CURRENT_VERSION is not on crates.io yet"
echo "should_release=true" >> $GITHUB_OUTPUT
echo "skip_bump=true" >> $GITHUB_OUTPUT
elif git rev-parse "rust-v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "No changelog fragments and rust-v$CURRENT_VERSION already released"
echo "should_release=false" >> $GITHUB_OUTPUT
else
Expand All @@ -306,6 +330,12 @@ jobs:
node scripts/version-and-commit.mjs \
--bump-type "${{ steps.bump_type.outputs.bump_type }}"

# A re-run starts from the pre-release commit again; release the version
# an earlier attempt already tagged instead of the unbumped Cargo.toml.
- name: Check out already tagged version
if: steps.version.outputs.already_released == 'true'
run: git checkout "rust-v${{ steps.version.outputs.new_version }}"

- name: Get current version
id: current_version
if: steps.check.outputs.should_release == 'true'
Expand All @@ -317,6 +347,25 @@ jobs:
if: steps.check.outputs.should_release == 'true'
run: cargo build --release

# Trusted publishing (OIDC) first, the token secret only as a fallback.
# The exchange fails until crates.io has a trusted publisher for this
# repository and rust.yml; continue-on-error lets the publish step fall
# back to CARGO_REGISTRY_TOKEN / CARGO_TOKEN, and that step still fails,
# with instructions, when neither credential works. The action's post
# step revokes the temporary token.
- name: Authenticate with crates.io (trusted publishing)
id: crates_auth
if: steps.check.outputs.should_release == 'true'
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
continue-on-error: true

- name: Publish to crates.io
if: steps.check.outputs.should_release == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates_auth.outputs.token || secrets.CARGO_REGISTRY_TOKEN || secrets.CARGO_TOKEN }}
TRUSTED_PUBLISHING: ${{ steps.crates_auth.outcome }}
run: node scripts/crates-io.mjs publish

- name: Create GitHub Release
if: steps.check.outputs.should_release == 'true'
env:
Expand All @@ -330,10 +379,13 @@ jobs:
manual-release:
name: Manual Release
needs: [lint, test, build]
if: github.event_name == 'workflow_dispatch'
if: always() && github.event_name == 'workflow_dispatch' && needs.build.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
# crates.io trusted publishing: crates-io-auth-action trades this job's
# GitHub OIDC token for a short-lived crates.io publish token.
id-token: write
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -370,10 +422,35 @@ jobs:
--bump-type "${{ github.event.inputs.bump_type }}" \
--description "${{ github.event.inputs.description }}"

# A re-run starts from the pre-release commit again; release the version
# an earlier attempt already tagged instead of the unbumped Cargo.toml.
- name: Check out already tagged version
if: steps.version.outputs.already_released == 'true'
run: git checkout "rust-v${{ steps.version.outputs.new_version }}"

- name: Build release
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
run: cargo build --release

# Trusted publishing (OIDC) first, the token secret only as a fallback.
# The exchange fails until crates.io has a trusted publisher for this
# repository and rust.yml; continue-on-error lets the publish step fall
# back to CARGO_REGISTRY_TOKEN / CARGO_TOKEN, and that step still fails,
# with instructions, when neither credential works. The action's post
# step revokes the temporary token.
- name: Authenticate with crates.io (trusted publishing)
id: crates_auth
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
continue-on-error: true

- name: Publish to crates.io
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates_auth.outputs.token || secrets.CARGO_REGISTRY_TOKEN || secrets.CARGO_TOKEN }}
TRUSTED_PUBLISHING: ${{ steps.crates_auth.outcome }}
run: node scripts/crates-io.mjs publish

- name: Create GitHub Release
if: steps.version.outputs.version_committed == 'true' || steps.version.outputs.already_released == 'true'
env:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add to your `Cargo.toml`:

```toml
[dependencies]
links-queue = "0.11"
links-queue = "0.3"
tokio = { version = "1", features = ["full"] }
```

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Add to your `Cargo.toml`:

```toml
[dependencies]
links-queue = "0.11"
links-queue = "0.3"
tokio = { version = "1", features = ["full"] }
```

Expand Down
18 changes: 18 additions & 0 deletions experiments/issue-53-crates-io-publish-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Issue #53: exercise rust/scripts/crates-io.mjs without publishing anything.
# 1. status of the real crate (not on crates.io before the first release)
# 2. publish without credentials -> explicit "credentials missing" error, exit 1
# 3. publish of a version that already exists (serde 1.0.0) -> skipped, verified
set -u
SCRIPT="$(cd "$(dirname "$0")/.." && pwd)/rust/scripts/crates-io.mjs"

(cd "$(dirname "$SCRIPT")/.." && node "$SCRIPT" status)

(cd "$(dirname "$SCRIPT")/.." && env -u CARGO_REGISTRY_TOKEN TRUSTED_PUBLISHING=failure node "$SCRIPT" publish)
echo "publish without credentials exit=$?"

TMP=$(mktemp -d)
printf '[package]\nname = "serde"\nversion = "1.0.0"\n' > "$TMP/Cargo.toml"
(cd "$TMP" && VERIFY_ATTEMPTS=1 node "$SCRIPT" publish)
echo "publish of existing version exit=$?"
rm -rf "$TMP"
2 changes: 2 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ categories = ["development-tools"]
repository = "https://github.com/link-foundation/links-queue"
documentation = "https://github.com/link-foundation/links-queue"
rust-version = "1.70"
# Release tooling stays in the repository; the crate ships the library and binary.
exclude = ["changelog.d/", "scripts/", "package-lock.json"]

[lib]
name = "links_queue"
Expand Down
36 changes: 36 additions & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ Rust implementation of Links Queue - a universal queue system using links.

## Quick Start

### Installation

The crate is published to [crates.io](https://crates.io/crates/links-queue):

```bash
cargo add links-queue

# Or install the command-line binary
cargo install links-queue
```

### Development

```bash
Expand Down Expand Up @@ -52,6 +63,31 @@ rust/
└── CHANGELOG.md # Release history
```

## Releasing

Merging changelog fragments to `main` (or running the workflow manually)
bumps the version, publishes the crate to crates.io and creates a GitHub
release. Publishing tries **trusted publishing (OIDC)** first and falls back
to the `CARGO_REGISTRY_TOKEN` or `CARGO_TOKEN` repository secret, so no
long-lived token is needed once the trusted publisher is registered.

crates.io registers trusted publishers only for existing crates, so the first
version needs a one-time setup by a maintainer:

```bash
package-registry-manager setup --repository . --registry crates-io --execute
```

It publishes the first version with a short-lived crate-scoped token and
registers the trusted publisher. To do it by hand instead, publish once with a
token, then open <https://crates.io/crates/links-queue/settings> and add the
GitHub trusted publisher: owner `link-foundation`, repository `links-queue`,
workflow `rust.yml`, no environment. If neither credential works, the release
job fails with these instructions.

A version that was tagged but never reached crates.io is published by the next
run on `main`, or by re-running the failed run.

## API

### Functions
Expand Down
13 changes: 13 additions & 0 deletions rust/changelog.d/20261023_080000_crates_io_trusted_publishing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
bump: patch
---

### Added

- Publish the crate to crates.io from the release jobs, trying trusted publishing (OIDC) first and falling back to the `CARGO_REGISTRY_TOKEN` / `CARGO_TOKEN` secret, then verify that crates.io serves the new version. Missing or rejected credentials fail the release with setup instructions.

### Fixed

- Run the Auto Release and Manual Release jobs again: a skipped job in their dependency chain had skipped them, so no Rust version was ever released.
- Publish a version that was tagged but never reached crates.io on the next run or a re-run, and check publishability with `cargo publish --dry-run` in CI.
- Point the installation docs at the current `links-queue = "0.3"` version.
Loading
Loading