scal3 0.4.1

Verify that systems operate under your sole control (prototype, patent pending)
Documentation
name: Prototype continuous integration

on:
  push:
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  build_and_test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        toolchain:
          - stable
    steps:
      - uses: actions/checkout@v4
      - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
      - run: cargo build --verbose
      - run: cargo test --verbose
  release:
    if: startsWith(github.ref, 'refs/tags/v')
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            suffix: linux-x86_64
            target: x86_64-unknown-linux-musl
            ext: so
          - os: macos-14
            suffix: macos-arm64
            target: aarch64-apple-darwin
            ext: dylib
    runs-on: ${{ matrix.os }}
    needs: build_and_test
    steps:
      - uses: actions/checkout@v4
      - run: rustup update stable && rustup default stable
      - run: rustup target add ${{ matrix.target }}
      - name: Extract version from tag
        id: extract
        run: echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
      - run: cargo build --release --target ${{ matrix.target }}
      - name: Archive and rename binary
        shell: bash
        run: |
          VERSION=${{ steps.extract.outputs.VERSION }}
          SUFFIX=${{ matrix.suffix }}
          EXT=${{ matrix.ext }}
          mkdir -p dist
          SRC="target/${{ matrix.target }}/release/libscal3.${EXT}"
          cp "$SRC" "dist/libscal3-${VERSION}-${SUFFIX}.${EXT}"
      - uses: actions/upload-artifact@v4
        with:
          name: bin-${{ matrix.suffix }}
          path: dist/*
  publish:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Publish crate
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
      - uses: actions/download-artifact@v4
        with: { name: bin-linux-x86_64, path: dist/ }
      - uses: actions/download-artifact@v4
        with: { name: bin-macos-arm64, path: dist/ }
      - name: Create GitHub Release with all binaries
        run: |
          VERSION=${GITHUB_REF##*/}
          gh release create "$VERSION" dist/* \
            --title "Release $VERSION" \
            --verify-tag
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}