name: Release
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- run: rustup show
- uses: Swatinem/rust-cache@v2
- name: Verify tag matches Cargo.toml version
run: |
tag="${GITHUB_REF_NAME#v}"
cargo_version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$tag" != "$cargo_version" ]; then
echo "::error::Tag v${tag} does not match Cargo.toml version ${cargo_version}"
exit 1
fi
- run: cargo clippy --all-features -- -D warnings
- run: cargo build --all-features
- run: cargo test --all-features
- name: Publish to crates.io
run: cargo publish --all-features
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Bump version for next development cycle
run: |
current=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
IFS='.' read -r major minor patch <<< "$current"
patch=$((patch + 1))
next="${major}.${minor}.${patch}"
sed -i "0,/^version = \"${current}\"/s//version = \"${next}\"/" Cargo.toml
echo "NEXT_VERSION=${next}" >> "$GITHUB_ENV"
- name: Commit and push version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml
git commit -m "chore: bump version to ${NEXT_VERSION}"
git push origin HEAD:main