This GitHub Action ensures that the version in your Rust project's Cargo.toml matches the version in the Git tag that triggered the workflow. It is useful for enforcing semantic versioning in release workflows.
jobs:
check-version:
name: Ensure Tag Matches Cargo.toml
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check Cargo Version Matches Tag
uses: spice-labs-inc/action-check-version@main
This action expects your workflow to be triggered by a Git tag in the format vX.Y.Z (e.g. v1.2.3). It will:
- Parse the version from the first package in Cargo.toml
- Extract the version from the Git tag
- Fail the workflow if the two versions do not match
This is a composite action, meaning it runs a shell script in your workflow. The script:
- Uses
cargo metadataandjqto extract the version number fromCargo.toml - Extracts the Git tag version from
GITHUB_REF - Compares the two
- Exits with an error if they differ
The action requires:
- cargo
- jq These are typically available on ubuntu-22.04 and ubuntu-24.04. If not, add:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq- The Git tag does not start with v
- The version in
Cargo.tomland Git tag do not match