name: Release Binary
on:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
jobs:
build:
name: Build and Publish Rust Binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verify version matches release tag
run: |
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | cut -d'"' -f2)
TAG_VERSION=${GITHUB_REF#refs/tags/v}
if [ "v$CARGO_VERSION" != "v$TAG_VERSION" ]; then
echo "Error: Cargo.toml version (v$CARGO_VERSION) doesn't match release tag (v$TAG_VERSION)"
echo "Deleting release and tag..."
gh release delete ${{ github.ref_name }} --yes
gh api -X DELETE /repos/${{ github.repository }}/git/refs/tags/${{ github.ref_name }}
exit 1
fi
echo "Version verified: v$CARGO_VERSION matches tag v$TAG_VERSION"
- uses: dtolnay/rust-toolchain@stable
- uses: extractions/setup-just@v3
- name: Generate changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --latest -vv
- name: Update release notes
run: |
cat "${{ steps.git-cliff.outputs.changelog }}"
gh release edit ${{ github.ref_name }} --notes-file "${{ steps.git-cliff.outputs.changelog }}"
rm ${{ steps.git-cliff.outputs.changelog }}
- name: Publish
run: just publish
- name: Cleanup on failure
if: failure()
run: |
echo "Workflow failed, cleaning up release and tag..."
gh release delete ${{ github.ref_name }} --yes || true
gh api -X DELETE /repos/${{ github.repository }}/git/refs/tags/${{ github.ref_name }} || true