name: Release a new version
on:
push:
branches: [ main ]
paths: [ "Cargo.toml" ]
workflow_dispatch: {}
permissions:
contents: write
jobs:
release:
name: Define Tags for version in Cargo.toml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2.7.3
- name: Create Tag
id: tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG=v$(cargo metadata --no-deps --quiet --format-version 1 | jq -r '.packages | last | .version')
git fetch --tags
if [ $(git tag -l $TAG) ]
then
echo "::error::Git tag $TAG already exists."
exit 1
fi
git config user.name "Add Tag from CI"
git config user.email ""
git tag $TAG
git push --tags
gh release view $TAG &> /dev/null || gh release create $TAG --generate-notes
- name: Publish to Crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}