bai 1.0.3

Create common files from a large collection of templates
name: Release

on:
  push:
    tags: ["v*.*.*"]

jobs:
  publish:
    name: Publish

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        name: Checkout

      - run: |
          version="v$(cat Cargo.toml | grep -m 1 "version" | sed -r "s/version *= *\"([[:digit:].]+)\"/\1/")"
          if [ "$version" != "${{ github.ref_name }}" ]; then
            echo "tag ${{ github.ref_name }} does not match version $version in Cargo.toml"
            exit 1
          fi
        name: Version

      - run: cargo test
        name: Test

      - run: cargo publish
        name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - uses: softprops/action-gh-release@v1
        name: Release

  package:
    strategy:
      fail-fast: false
      matrix:
        release:
          # TODO: Figure out how to "setup pkg-config for cross-compilation"
          # - os: ubuntu-latest
          #   target: aarch64-unknown-linux-gnu
          #   executable: bai

          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            executable: bai

          - os: windows-latest
            target: aarch64-pc-windows-msvc
            executable: bai.exe

          - os: windows-latest
            target: x86_64-pc-windows-msvc
            executable: bai.exe

          - os: macos-latest
            target: aarch64-apple-darwin
            executable: bai

          - os: macos-latest
            target: x86_64-apple-darwin
            executable: bai

    name: Package.${{ matrix.release.target }}

    runs-on: ${{ matrix.release.os }}

    needs:
      - publish

    steps:
      - uses: actions/checkout@v4
        name: Checkout

      - run: rustup target add ${{ matrix.release.target }}
        name: Configure Rust

      - run: cargo build --target ${{ matrix.release.target }} --release
        name: Build

      - run: mkdir dist/
        name: Prepare for packaging

      # Create .tar.gz files for Linux and macOS
      - run: tar -a -cf ../../../dist/bai-${{ github.ref_name }}-${{ matrix.release.target }}.tar.gz ${{ matrix.release.executable }}
        name: Package (tar) — ${{ matrix.release.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/
        if: ${{ !startsWith(matrix.release.os, 'windows') }}

      # Create .zip files for Linux and macOS
      - run: zip -r ../../../dist/bai-${{ github.ref_name }}-${{ matrix.release.target }}.zip ${{ matrix.release.executable }}
        name: Package (zip) — ${{ matrix.reclease.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/
        if: ${{ !startsWith(matrix.release.os, 'windows') }}

      # Create .zip files for Windows
      - run: Compress-Archive ${{ matrix.release.executable }} -DestinationPath ../../../dist/bai-${{ github.ref_name }}-${{ matrix.release.target }}.zip
        name: Package (zip) — ${{ matrix.release.target }}
        working-directory: ./build/${{ matrix.release.target }}/release/
        if: ${{ startsWith(matrix.release.os, 'windows') }}

      # Upload archives to a Github release for this version
      - uses: softprops/action-gh-release@v1
        name: Publish
        with:
          files: ./dist/bai-${{ github.ref_name }}-${{ matrix.release.target }}.*