cargo-version-info
A Cargo subcommand for unified version management across CI/CD, Rust code, and shell scripts.
Overview
cargo-version-info provides a single source of truth for version
operations, replacing scattered version logic in GitHub Actions
workflows, bash scripts, Makefiles, and Rust build scripts.
Installation
Using cargo-binstall (Recommended)
The fastest way to install pre-built binaries:
Using cargo install
Build from source (slower, requires Rust toolchain):
Commands
cargo version-info next
Calculate the next patch version from the latest GitHub release.
# Basic usage (auto-detects repo from git remote)
# Specify repository explicitly
# Output as tag format
# Output as JSON
Output formats:
version(default): Just the version number (e.g.,0.0.6)tag: Version with v prefix (e.g.,v0.0.6)json: JSON object withlatest,next, andnext_tagfields
cargo version-info current
Get the current version from Cargo.toml.
# Read from default Cargo.toml
# Specify custom manifest path
# Output as JSON
Output formats:
version(default): Just the version numberjson: JSON object withversionfield
cargo version-info latest
Get the latest published GitHub release version.
# Auto-detect repository
# Specify repository
# Output as tag format
Output formats:
version(default): Just the version numbertag: Version with v prefixjson: JSON object withversionandtagfields
cargo version-info dev
Generate a dev version from the current git SHA.
# Use current directory
# Specify repository path
# Output as JSON
Output format: 0.0.0-dev-<short-sha> (e.g., 0.0.0-dev-a1b2c3d)
cargo version-info tag
Generate a tag name from a version string.
# Generate tag from version
# Output as JSON
Output: v0.1.2
cargo version-info bump
Bump the version in Cargo.toml and create a commit.
# Bump patch version (0.1.0 -> 0.1.1)
# Bump minor version (0.1.0 -> 0.2.0)
# Bump major version (0.1.0 -> 1.0.0)
# Set specific version
# Update version without committing
# Skip Cargo.lock update
# Skip README.md version updates
Features:
- Updates
Cargo.tomlversion - Updates
Cargo.lock(unless--no-lock) - Updates version badges in
README.md(unless--no-readme) - Creates a conventional commit:
chore(version): bump X.Y.Z -> X.Y.Z - Pure Rust implementation - no git CLI required
- SSH commit signing without external tools
Pure Rust Git Operations:
All git operations (commits, tree building, index manipulation) are
performed using gix - a pure Rust
git implementation. This means cargo version-info bump works in
environments where the git CLI is not installed, such as minimal
Docker containers or restricted CI runners.
Commit Signing (No GPG/SSH CLI Required):
SSH commit signing is implemented in pure Rust using the ssh-key
crate. When signing is enabled in git config, the tool signs commits
by communicating directly with ssh-agent - no ssh-keygen or gpg
CLI tools needed.
# Configure signing (standard git config)
# bump will create signed commits without calling git or ssh-keygen
GPG signing is not yet implemented (requires gpg-agent).
cargo version-info compare
Compare two versions.
# Compare versions (outputs true if version1 > version2)
# Output as JSON
# Output as diff format
Output formats:
bool(default):trueif version1 > version2,falseotherwisejson: JSON object with comparison resultdiff: Human-readable comparison (e.g.,0.1.2 < 0.1.3)
Environment Variables
GITHUB_TOKEN: GitHub personal access token for API access (optional, falls back toghCLI)GITHUB_REPOSITORY: Repository inowner/repoformat (auto-detected from git remote if not set)
Use Cases
GitHub Actions
Replace bash scripts in GitHub Actions workflows:
- name: Calculate next version
run: |
NEXT_VERSION=$(cargo version-info next --format version)
echo "version=$NEXT_VERSION" >> $GITHUB_OUTPUT
Bash Scripts
Replace version extraction logic:
# Instead of: VERSION=$(grep '^version' Cargo.toml | ...)
VERSION=
# Instead of: gh release list ... | jq ...
LATEST=
Makefiles
Use in Make targets:
VERSION :=
NEXT_VERSION :=
Rust Build Scripts
Can be called from build.rs:
#
Integration with Existing Workflows
This tool is designed to replace:
- GitHub Actions: See
dataroadinc/github-actions
for
calculate-next-versionandget-versionactions - Bash scripts: Version extraction in
.bash/*.shfiles - Rust build scripts: Version resolution in
crates/ekg-util-env/build.rs(can call this tool)
License
Same as the workspace (see root LICENSE file).