name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Version to release, for example 2.0.0"
required: true
type: string
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Resolve release version
id: version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF_NAME#v}"
fi
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid release version: $VERSION" >&2
exit 1
fi
MANIFEST_VERSION="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json, sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
if [[ "$MANIFEST_VERSION" != "$VERSION" ]]; then
echo "Cargo.toml version $MANIFEST_VERSION does not match release version $VERSION" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Create tag for manual release
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
TAG="${{ steps.version.outputs.tag }}"
CURRENT_SHA="$(git rev-parse HEAD)"
if git rev-parse "$TAG" >/dev/null 2>&1; then
TAG_SHA="$(git rev-list -n 1 "$TAG")"
if [[ "$TAG_SHA" != "$CURRENT_SHA" ]]; then
echo "Tag $TAG already exists at $TAG_SHA, not current HEAD $CURRENT_SHA" >&2
exit 1
fi
else
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "$TAG"
git push origin "$TAG"
fi
- name: Check formatting
run: cargo fmt -- --check
- name: Lint
run: cargo clippy --all-features -- -D warnings
- name: Test all features
run: cargo test --all-features
- name: Test no-default feature matrix
run: cargo test --no-default-features --features serde,bytes,simd
- name: Package crate
run: cargo package
- name: Publish crate to crates.io
run: cargo publish --token "$CARGO_REGISTRY_TOKEN"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
VERSION: ${{ steps.version.outputs.version }}
run: |
gh release create "$TAG" \
"target/package/cheetah-string-$VERSION.crate#cheetah-string-$VERSION.crate" \
--verify-tag \
--title "cheetah-string $TAG" \
--generate-notes