name: Publish
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
id-token: write
env:
CARGO_TERM_COLOR: always
BIN_NAME: string-analyze
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check tag matches Cargo.toml version
run: |
TAG="${GITHUB_REF#refs/tags/v}"
VER=$(sed -n 's/^version *= *"\([^"]*\)".*/\1/p' Cargo.toml | head -1)
echo "tag=$TAG cargo=$VER"
if [ "$TAG" != "$VER" ]; then
echo "::error::Tag v$TAG != Cargo.toml version $VER"
exit 1
fi
test:
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features --all-targets --locked
publish-crates:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Dry run
run: cargo publish --locked --dry-run
- name: Publish
run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
build:
needs: publish-crates
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
ext: ""
archive: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
ext: .exe
archive: zip
- os: macos-latest
target: aarch64-apple-darwin
ext: ""
archive: tar.gz
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install Rust stable + target
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build release binary
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package (unix tar.gz)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
BIN="${{ env.BIN_NAME }}${{ matrix.ext }}"
OUT="${{ env.BIN_NAME }}-${GITHUB_REF_NAME}-${{ matrix.target }}"
mkdir -p "$OUT"
cp "target/${{ matrix.target }}/release/$BIN" "$OUT/"
cp README.md CHANGELOG.md LICENSE "$OUT/" 2>/dev/null || true
tar -czf "$OUT.tar.gz" "$OUT"
echo "ASSET=$OUT.tar.gz" >> "$GITHUB_ENV"
- name: Package (windows zip)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$bin = "${{ env.BIN_NAME }}${{ matrix.ext }}"
$out = "${{ env.BIN_NAME }}-${{ github.ref_name }}-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $out | Out-Null
Copy-Item "target/${{ matrix.target }}/release/$bin" "$out/"
Copy-Item README.md,CHANGELOG.md,LICENSE $out/ -ErrorAction SilentlyContinue
Compress-Archive -Path "$out/*" -DestinationPath "$out.zip"
echo "ASSET=$out.zip" >> $env:GITHUB_ENV
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ${{ env.ASSET }}
generate_release_notes: true