preprintd 0.3.5

Printer swarm-worker daemon implementation for PreConnect.
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write

env:
  SCCACHE_GHA_ENABLED: "true"
  SCCACHE_CACHE_SIZE: 2G
  RUSTC_WRAPPER: "sccache"

jobs:
  build-win:
    runs-on: windows-latest

    env:
      FILE_NAME: target/release/preprintd-win-latest.zip

    steps:
      - uses: actions/checkout@v6

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

      - uses: Swatinem/rust-cache@v2
      - uses: mozilla-actions/sccache-action@v0.0.9

      - run: cargo build --release --quiet --locked
      - run: sccache --show-stats || true

      - name: Compress binary
        run: |
          powershell -Command "Compress-Archive -Path target/release/preprintd.exe -DestinationPath $env:FILE_NAME"

      - name: Upload compressed binary to release
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: ${{ env.FILE_NAME }}
          tag: ${{ github.ref }}
          overwrite: true

  build-unix:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]

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

    env:
      FILE_NAME: target/release/preprintd-${{ matrix.os }}.tar.gz

    steps:
      - uses: actions/checkout@v6

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - uses: Swatinem/rust-cache@v2
      - uses: mozilla-actions/sccache-action@v0.0.9

      - run: cargo build --release --quiet --locked
      - run: sccache --show-stats || true

      - name: Compress binary
        run: tar -czf ${{ env.FILE_NAME }} -C target/release preprintd

      - name: Upload compressed binary to release
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: ${{ env.FILE_NAME }}
          tag: ${{ github.ref }}
          overwrite: true

  publish:
    needs: [build-win, build-unix]
    runs-on: ubuntu-latest

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

      - uses: Swatinem/rust-cache@v2
      - uses: mozilla-actions/sccache-action@v0.0.9
      - run: sccache --show-stats || true

      - uses: rust-lang/crates-io-auth-action@v1
        id: auth

      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

      - name: Extract latest changelog
        id: changelog
        run: |
          awk '/^### v/ { if (found) exit; found=1 } found' CHANGELOG.md > latest.md
          echo "notes<<EOF" >> $GITHUB_OUTPUT
          cat latest.md >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          body: ${{ steps.changelog.outputs.notes }}