name: release
on:
push:
tags: [ 'v*' ]
workflow_dispatch:
inputs:
tag:
description: Existing tag to publish, e.g. v0.7.0
required: true
type: string
env:
CARGO_TERM_COLOR: always
jobs:
crate:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- name: Check tag matches crate version
env:
TAG: ${{ inputs.tag || github.ref_name }}
run: |
version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if [ "v$version" != "$TAG" ]; then
echo "tag $TAG does not match Cargo.toml version $version"
exit 1
fi
- name: Run tests
run: cargo test --verbose
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub release
run: |
if gh release view "$TAG" >/dev/null 2>&1; then
echo "release $TAG already exists"
else
gh release create "$TAG" --verify-tag --generate-notes --title "$TAG"
fi
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ inputs.tag || github.ref_name }}