name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
verify-version:
name: Verify tag matches crate version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with:
persist-credentials: false
- name: Check tag matches Cargo.toml version
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CARGO_VERSION="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/^version = "(.*)"/\1/')"
echo "Tag version: $TAG_VERSION"
echo "Cargo version: $CARGO_VERSION"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "::error::Tag v$TAG_VERSION does not match Cargo.toml version $CARGO_VERSION. Bump Cargo.toml (and Cargo.lock) to match the tag before releasing."
exit 1
fi
create-release:
name: Create Release
needs: verify-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with:
persist-credentials: false
- name: Create Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${GITHUB_REF_NAME#v}"
# Extract this version's section from CHANGELOG.md
NOTES="$(awk -v ver="$VERSION" '
$0 ~ "^## \\[" ver "\\]" { flag = 1; next }
/^## \[/ { flag = 0 }
flag
' CHANGELOG.md)"
if [ -z "$NOTES" ]; then
NOTES="See CHANGELOG.md for details."
fi
gh release create "${{ github.ref_name }}" \
--title "Vimanam ${{ github.ref_name }}" \
--notes "$NOTES
---
Binaries for Linux, macOS (Intel & Apple Silicon), and Windows are attached. Also available via \`cargo install vimanam\`."
publish-crate:
name: Publish to crates.io
needs: verify-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with:
persist-credentials: false
- name: Setup Rust
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 with:
toolchain: stable
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
build-and-upload:
name: Build and Upload
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: vimanam
asset_name: vimanam-linux-x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: vimanam.exe
asset_name: vimanam-windows-x86_64.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: vimanam
asset_name: vimanam-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: vimanam
asset_name: vimanam-macos-arm64
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with:
persist-credentials: false
- name: Setup Rust
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Upload Release Asset
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cp "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "${{ matrix.asset_name }}"
gh release upload "${{ github.ref_name }}" "${{ matrix.asset_name }}" --clobber