This document provides instructions for repository maintainers to complete the setup for automated publishing to crates.io.
To enable automated publishing to crates.io, you need to create and configure a crates.io API token:
-
Get a crates.io account:
- Sign up or log in at https://crates.io/
-
Generate an API token:
- Go to https://crates.io/me
- Click on "API Tokens"
- Click "New Token"
- Name:
rust-guardian-ci(or any descriptive name) - Scope: Select
publish-updateto allow publishing and updating existing crates - Click "Create"
- Important: Copy the token immediately - you won't be able to see it again
-
Add the token to GitHub repository secrets:
- Go to the GitHub repository: https://github.com/cloudfunnels/rust-guardian
- Navigate to: Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
CRATES_TOKEN - Value: Paste the token you copied from crates.io
- Click "Add secret"
Once the token is configured, you can test the automation:
-
Test CI workflow:
# Any push to main will trigger CI git push origin main -
Test release workflow:
# Update version in Cargo.toml first git tag v0.1.0 git push origin v0.1.0
- ✅ Code formatting checks
- ✅ Linting with clippy
- ✅ Tests on stable, beta, nightly Rust
- ✅ Security audit
- ✅ Documentation validation
- ✅ All CI checks
- ✅ Version verification
- ✅ Automatic crates.io publishing
- ✅ GitHub release creation
- ✅ Binary artifact generation
- Crates.io: https://crates.io/crates/rust-guardian
- Documentation: https://docs.rs/rust-guardian (automatically updated)
- Repository: https://github.com/cloudfunnels/rust-guardian
-
"Invalid token" error:
- Verify the CRATES_TOKEN secret is correctly set
- Ensure the token has
publish-updatescope
-
"Version already exists" error:
- Crates.io doesn't allow republishing the same version
- Increment the version in Cargo.toml and create a new tag
-
Test failures:
- The release will be blocked if any tests fail
- Fix issues and create a new tag
- Check GitHub Actions logs for detailed error messages
- See
RELEASE.mdfor detailed release process documentation - Create an issue if you encounter problems
- The CRATES_TOKEN should only have
publish-updatescope (not admin access) - Only repository maintainers should have access to manage secrets
- The token is only used for publishing, not for downloading or other operations
- Consider rotating the token periodically for security
Once the CRATES_TOKEN secret is configured, the repository is ready for automated publishing to crates.io. The first release can be created by:
- Ensuring the version in
Cargo.tomlis correct (e.g.,0.1.0) - Creating and pushing a version tag:
git tag v0.1.0 && git push origin v0.1.0 - The automation will handle the rest!
The crate will then be available at https://crates.io/crates/rust-guardian and documentation will be published at https://docs.rs/rust-guardian.