name: Release
on:
push:
tags:
- "v*.*.*"
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build & test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release --verbose -j 2
- name: Test
run: cargo test --verbose
- name: Package release binary (Windows only)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$version = (Select-String -Path Cargo.toml -Pattern '^version\s*=\s*"(.*)"' | Select-Object -First 1).Matches.Groups[1].Value
$zipName = "idmrs-$version-x86_64-pc-windows-msvc.zip"
Compress-Archive -Path target/release/idmrs.exe, README.md, LICENSE -DestinationPath $zipName
echo "ASSET_PATH=$zipName" >> $env:GITHUB_ENV
- name: Upload release binary artifact
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: idmrs-windows-binary
path: idmrs-*-x86_64-pc-windows-msvc.zip
publish:
name: Publish to crates.io
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify Cargo.toml version matches tag
shell: bash
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CRATE_VERSION=$(grep -m1 '^version' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
echo "Tag version: $TAG_VERSION / Crate version: $CRATE_VERSION"
if [ "$TAG_VERSION" != "$CRATE_VERSION" ]; then
echo "::error::Tag ($TAG_VERSION) and Cargo.toml version ($CRATE_VERSION) do not match"
exit 1
fi
- name: cargo publish (dry run)
run: cargo publish --dry-run
- name: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download Windows binary artifact
uses: actions/download-artifact@v4
with:
name: idmrs-windows-binary
path: dist
- name: Create release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: dist/*.zip