name: Release
on:
release:
types: [published]
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: matrix.archive == 'tar.gz'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../libpgs-${{ github.ref_name }}-${{ matrix.target }}.tar.gz libpgs
cd ../../..
- name: Package (Windows)
if: matrix.archive == 'zip'
shell: bash
run: |
cd target/${{ matrix.target }}/release
7z a ../../../libpgs-${{ github.ref_name }}-${{ matrix.target }}.zip libpgs.exe
cd ../../..
- name: Upload to release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload ${{ github.ref_name }} libpgs-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive }} --clobber
publish-crate:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
- name: Verify tag matches Cargo.toml version
run: |
TAG="${{ github.ref_name }}"
TAG_VERSION="${TAG#v}"
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | python3 -c "import json,sys; print(json.load(sys.stdin)['packages'][0]['version'])")
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish