cargo-search2

Crates.iocargo-search2
lib.rscargo-search2
version0.2.2
sourcesrc
created_at2021-10-04 01:19:52.220815
updated_at2021-10-11 18:42:22.329741
descriptioncargo search, optimized for CI caching in GitHub Actions and elsewhere
homepage
repositoryhttps://github.com/sunshowers/cargo-search2
max_upload_size
id459876
size58,440
Rain (sunshowers)

documentation

README

cargo-search2

cargo-search2 on crates.io Documentation (latest release) Documentation (main) License License

A binary utility that provides a more convenient version of cargo search.

Installation

Grab pre-built binaries for your platform from the releases page.

To grab releases in CI or other automation:

curl -LsSf https://github.com/sunshowers/cargo-search2/releases/latest/download/cargo-search2-{platform}.zip | tar xzf - -C ~/.cargo/bin

Install manually:

cargo install cargo-search2

Examples

$ cargo search2 serde
# output:
serde 1.0.130 (hash: blake2b24:2e6117acae4f6f2d2d698c9fc0b43de60ac26556f44ad96b)

$ cargo search2 serde --message-format toml
serde = "1.0.130"

$ cargo search2 serde --message-format json
{"crate-name":"serde","version":"1.0.130","hash":"blake2b24:2e6117acae4f6f2d2d698c9fc0b43de60ac26556f44ad96b"}

# Get an exact version or semver range
$ cargo search2 serde --req '=1.0.120'
serde 1.0.120 (hash: blake2b24:f79131f50c298569f841e47287c3b0a443c29cfda3ffd475)

# Use --cache-version/-c to invalidate caches
$ cargo run -- serde --req '=1.0.120' -c1
serde 1.0.120 (hash: blake2b24:168778241e3b0e96f5547fba1eb4b4b84efa8291c3c14b37)
$ cargo run -- serde --req '=1.0.120' -c2
serde 1.0.120 (hash: blake2b24:344d8a8d08a16dbce8c4e0d90fd6aad513631ca081185ea8)

# Step outputs for GitHub Actions
$ cargo search2 serde --message-format github
::set-output name=crate-name::serde
::set-output name=version::1.0.120
::set-output name=hash::blake2b24:f79131f50c298569f841e47287c3b0a443c29cfda3ffd475

For an example GitHub Action, see .github/workflows/example.yml.

Why?

People sometimes use cargo search to generate cache keys for tools. This is an easier way to achieve the same goal with a couple more features.

cargo search2 supports:

  • looking for exact versions and semver ranges
  • producing results in plain, JSON, and GitHub Actions formats
  • easy cache invalidation through the --cache-version option

Hash contents

The hashes produced by cargo search2 are derived from:

  • The name of the crate
  • The exact version number
  • The cache version

Notably, the operating system and other parts of the environment are not part of the hash.

Stability guarantees

Within a semver range, the command-line interface is append-only, and hashes stay the same.

Contributing

Pull requests are welcome! Please follow the code of conduct.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

Commit count: 15

cargo fmt