Skip to content

ci(release): publish library crate to crates.io via Trusted Publishing#53

Merged
amondnet merged 1 commit into
mainfrom
ci/crates-io-trusted-publishing
Jun 22, 2026
Merged

ci(release): publish library crate to crates.io via Trusted Publishing#53
amondnet merged 1 commit into
mainfrom
ci/crates-io-trusted-publishing

Conversation

@amondnet

@amondnet amondnet commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

Adds crates.io publishing for the library crate via Trusted Publishing (OIDC, no token), mirroring the npm setup.

The short name csp is already taken on crates.io (an unrelated crate at 3.0.0), so the library is published as code-search-please while keeping the library name csp:

[package]
name = "code-search-please"
[lib]
name = "csp"   # downstream still writes `use csp::...`

cargo add code-search-pleaseuse csp::.... The README example and @pleaseai/csp npm package are unaffected.

Changes

  • crates/csp/Cargo.toml: rename package → code-search-please, add [lib] name = "csp", add crates.io metadata (keywords, categories, homepage, documentation, readme).
  • crates/csp/README.md: new crate-level README for the crates.io listing.
  • Cargo.toml (root): csp workspace dep gains package = "code-search-please" so csp-cli keeps use csp.
  • Cargo.lock: regenerated (cspcode-search-please).
  • release-please.yml: new publish-crate job using rust-lang/crates-io-auth-action@v1.0.5 (SHA-pinned), id-token: write, cargo publish -p code-search-please --locked. Gated on the CRATES_IO_PUBLISH repo variable.

One-time bootstrap (required before CI can publish)

crates.io Trusted Publishing can't be configured on a crate that doesn't exist yet, so:

  1. Claim + first publish (needs a crates.io token / your account — I can't authenticate):
    cargo publish -p code-search-please --locked
    This publishes code-search-please@0.1.4 (first version of the new crate name; crates.io is independent of our GH/npm releases).
  2. Configure the trusted publisher on crates.io → crate Settings → Trusted Publishing → GitHub: owner pleaseai, repo code-search, workflow release-please.yml.
  3. Enable CI: set repo variable CRATES_IO_PUBLISH=true.

After that, every release auto-publishes the new version via OIDC.

Verification

  • cargo fmt --all --check, cargo clippy --all-targets --all-features -D warnings, cargo test --workspace (257 + 8 pass) all green
  • cargo publish -p code-search-please --dry-run --locked packages + verifies (27 files)
  • csp-cli still builds via use csp (package rename transparent)

Follow-up

The CLI crate (code-search-please-cli, binary csp) needs intra-workspace dependency-version management (the csp-cli → csp dep must carry a synced version for publish) — a separate PR, ideally via release-please's cargo strategy.


Summary by cubic

Set up crates.io publishing for the Rust library via Trusted Publishing (OIDC). Publishes as code-search-please while keeping the Rust lib name csp, so use csp::... stays the same.

  • New Features

    • Added a publish-crate job to release-please.yml using rust-lang/crates-io-auth-action@v1.0.5 with id-token: write; runs cargo publish -p code-search-please --locked when a release is created and CRATES_IO_PUBLISH=true.
    • Renamed package in crates/csp/Cargo.toml to code-search-please; set [lib] name = "csp". Added crates.io metadata and a crate README.
    • Mapped workspace dep csp to package = "code-search-please" to keep imports unchanged. Regenerated Cargo.lock.
  • Migration

    • Manual first publish: cargo publish -p code-search-please --locked.
    • On crates.io, enable Trusted Publishing for repo pleaseai/code-search, workflow release-please.yml.
    • Set repo variable CRATES_IO_PUBLISH=true.

Written for commit ceefff1. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Rust library now published to crates.io as code-search-please, enabling integration into Rust projects.
  • Documentation

    • Added comprehensive README with installation instructions, usage examples, and technical details about the library's hybrid scoring and chunking approach.
  • Chores

    • Automated crate publishing workflow to registry.

…shing

The short name `csp` is already taken on crates.io, so the library crate is
published as `code-search-please` while keeping the library name `csp`
(`[lib] name = "csp"`) — downstream code still writes `use csp::...`, matching
the README and the @pleaseai/csp npm package. The csp-cli dependency keeps the
`csp` key via `package = "code-search-please"`.

- crates/csp: rename package -> code-search-please, add [lib] name = csp, add
  crates.io metadata (keywords, categories, homepage, docs, readme) + a crate
  README.
- release-please.yml: new publish-crate job using rust-lang/crates-io-auth-action
  (OIDC, no token), gated on the CRATES_IO_PUBLISH repo variable so it stays
  dormant until the one-time bootstrap (claim name + configure trusted publisher)
  is done.
- Verified: cargo fmt/clippy/test --workspace all green; cargo publish --dry-run
  packages and verifies the crate.

The CLI crate (code-search-please-cli) is a follow-up: it needs intra-workspace
dependency-version management before it can publish.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The csp crate's published package name is changed from csp to code-search-please while keeping the Rust library name as csp via an explicit [lib] section. The workspace dependency alias is updated accordingly. A README is added, and a gated publish-crate CI job is introduced to publish to crates.io on release.

Changes

crates.io Publish Setup

Layer / File(s) Summary
Crate rename and workspace alias
crates/csp/Cargo.toml, Cargo.toml
package.name is set to code-search-please and [lib] name = "csp" is added to keep the Rust-facing name. The workspace root maps the csp alias to package = "code-search-please" so member crates continue to use csp::....
csp crate README
crates/csp/README.md
New README with install instructions, a CspIndex/LoadOptions/QueryOptions usage example, hybrid scoring/chunking description, and license note.
CI publish-crate job
.github/workflows/release-please.yml
Adds a publish-crate job gated on release_created and vars.CRATES_IO_PUBLISH == 'true'. Checks out the released tag, authenticates via OIDC using rust-lang/crates-io-auth-action, and runs cargo publish -p code-search-please --locked.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • pleaseai/code-search#39: Also modifies crates/csp/Cargo.toml around the tree-sitter-language-pack dependency, which is part of the same crate metadata being updated in this PR.
  • pleaseai/code-search#43: Also modifies .github/workflows/release-please.yml with --locked release behavior, directly connected to the cargo publish --locked step added here.

Poem

🐇 Hop, hop, a new name takes flight,
code-search-please shines on crates.io tonight!
The lib stays csp, a familiar friend,
OIDC tokens ensure it won't bend.
A README blooms, a job clicks green—
The cleanest publish a bunny has seen! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'ci(release): publish library crate to crates.io via Trusted Publishing' accurately and specifically describes the main change: adding CI automation to publish the library crate to crates.io using OIDC Trusted Publishing, which aligns with the core purpose of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/crates-io-trusted-publishing

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@amondnet amondnet merged commit 8fa0494 into main Jun 22, 2026
8 of 9 checks passed
@amondnet amondnet deleted the ci/crates-io-trusted-publishing branch June 22, 2026 14:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request renames the core library crate from 'csp' to 'code-search-please' to resolve a naming conflict on crates.io, while maintaining the library name as 'csp' for backward compatibility. It also adds package metadata and a new README file. The review feedback points out that the Rust usage example in the README will fail doc tests because the '?' operator is used outside of a function returning 'Result', and suggests wrapping the example in a hidden 'main' function.

Comment thread crates/csp/README.md
Comment on lines +17 to +27
use std::path::Path;
use csp::indexing::index::{CspIndex, LoadOptions, QueryOptions};

// Index a local directory and search it
let index = CspIndex::from_path(Path::new("./my-project"), &LoadOptions::default())?;
let results = index.search("save model to disk", &QueryOptions { top_k: Some(3), ..Default::default() });

for r in &results {
println!("{}:{}-{}", r.chunk.file_path, r.chunk.start_line, r.chunk.end_line);
}
# Ok::<(), String>(())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[MEDIUM] README의 사용 예제가 컴파일되지 않습니다.

문제점: ? 연산자는 Result를 반환하는 함수 내에서만 사용할 수 있습니다. 현재 코드 조각은 함수로 감싸여 있지 않아 cargo test --doc 실행 시 컴파일 오류가 발생합니다.

근거: Rust 문서 테스트는 유효하고 컴파일 가능한 코드 예제를 제공해야 합니다. 이는 라이브러리 사용자가 예제를 복사하여 붙여넣고 바로 사용할 수 있도록 보장합니다.

제안: rustdoc이 테스트할 수 있도록 예제 코드를 숨겨진 main 함수로 감싸는 것을 제안합니다. 이렇게 하면 문서의 가독성을 해치지 않으면서 코드의 정확성을 보장할 수 있습니다. 또한, 예제를 실행하기 위해 필요한 설정(예: 디렉토리 생성)에 대한 주석을 추가하는 것이 좋습니다.

Suggested change
use std::path::Path;
use csp::indexing::index::{CspIndex, LoadOptions, QueryOptions};
// Index a local directory and search it
let index = CspIndex::from_path(Path::new("./my-project"), &LoadOptions::default())?;
let results = index.search("save model to disk", &QueryOptions { top_k: Some(3), ..Default::default() });
for r in &results {
println!("{}:{}-{}", r.chunk.file_path, r.chunk.start_line, r.chunk.end_line);
}
# Ok::<(), String>(())
# fn main() -> Result<(), String> {
use std::path::Path;
use csp::indexing::index::{CspIndex, LoadOptions, QueryOptions};
// Index a local directory and search it
// To make this example runnable, create a dummy directory first: `mkdir my-project`
let index = CspIndex::from_path(Path::new("./my-project"), &LoadOptions::default())?;
let results = index.search("save model to disk", &QueryOptions { top_k: Some(3), ..Default::default() });
for r in &results {
println!("{}:{}-{}", r.chunk.file_path, r.chunk.start_line, r.chunk.end_line);
}
# Ok(())
# }

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.

1 participant