name: Publish
on:
push:
tags: ["v*"]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Validate tag matches Cargo.toml
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CARGO_VERSION="$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "hexal") | .version')"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "::error::Tag v$TAG_VERSION doesn't match Cargo.toml $CARGO_VERSION"
exit 1
fi
echo "version=$TAG_VERSION" >> "$GITHUB_OUTPUT"
id: version
- uses: taiki-e/install-action@v2
with:
tool: just, cargo-nextest, cargo-hack
- run: just check
- run: just test-all
- run: just msrv
- name: Extract changelog for this version
run: |
VERSION="${{ steps.version.outputs.version }}"
awk -v ver="[$VERSION]" '
/^## \[/ {
if (found) exit
if (index($0, ver)) found=1
next
}
found { print }
' CHANGELOG.md > release-notes.md
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
- uses: softprops/action-gh-release@v2
with:
body_path: release-notes.md
prerelease: ${{ contains(steps.version.outputs.version, '-') }}