polytune 0.2.0-alpha.4

Maliciously-Secure Multi-Party Computation (MPC) Engine using Authenticated Garbling
Documentation
name: CI

on:
  # By using the pull_request event, the workflow is run on
  # the merge commit before it is added to main. This ensures
  # that the pipeline won't break after the merge.
  pull_request:
  push:
    branches: 
      - main
    

env:
  CARGO_TERM_COLOR: always
  RUST_LOG: debug
  POLYTUNE_LOG: debug
  RUSTFLAGS: "-C target-feature=+avx2"

jobs:
  lint:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
      - run: cargo fmt --check --all
      - run: cargo clippy --all-targets -F __bench --package polytune --package polytune-server-core --package polytune-http-server -- -Dwarnings
      - name: Install cargo-machete
        uses: taiki-e/install-action@537c30d2b45cc3aa3fb35e2bbcfb61ef93fd6f02
        with:
          tool: cargo-machete@0.8.0 # install-action checks sha for the binary
      - name: Check for unused dependencies 
        run: cargo machete

  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
      - run: cargo doc --no-deps --package polytune --package polytune-server-core
        env:
          RUSTDOCFLAGS: '-D warnings'
      - run: cargo doc --no-deps --document-private-items --package polytune-http-server
        env:
          RUSTDOCFLAGS: '-D warnings'

  # This job checks that we can build polytune with the msrv specified in the
  # Cargo.toml and that we *can't build* with one previous version.
  check-msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Install taplo for extracting rust-version
        uses: taiki-e/install-action@537c30d2b45cc3aa3fb35e2bbcfb61ef93fd6f02
        with:
          tool: taplo@0.10.0
      - run: |
          rust_version=$(taplo get -f Cargo.toml 'package.rust-version')
          prev_rust_version=$(echo "$rust_version" | awk -F'.' -v OFS='.' '{ $2 = $2 - 1; print }')
          echo "rust-version=$rust_version" >> $GITHUB_OUTPUT
          echo "prev-rust-version=$prev_rust_version" >> $GITHUB_OUTPUT
        id: get-rust-version
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: ${{  steps.get-rust-version.outputs.rust-version }}
      - run: cargo build
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: ${{  steps.get-rust-version.outputs.prev-rust-version }}
      - run: sed --in-place '/^rust-version/d' Cargo.toml
      - run: cargo build
        id: build-prev-version
        continue-on-error: true
      - run: |
          if [[ "${{ steps.build-prev-version }}" == "success" ]]; then
            echo "::error::Build with previous of MSRV succeeded unexpectedly. Change rust-version in Cargo.toml"
            exit 1
          fi

  test-lib:
    strategy:
      matrix:
        runner:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.runner }}
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
      # No avx2 on apple ARM
      - name: Set RUSTFLAGS for macOS
        if: runner.os == 'macOS'
        run: echo "RUSTFLAGS=" >> $GITHUB_ENV
      - run: cargo test --release

  test-examples:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      matrix:
        workspace-member:
          - http-multi-server-channels
          - http-single-server-channels
          - sql-integration
          - api-integration
    defaults:
      run:
        working-directory: examples/${{ matrix.workspace-member }}
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
        with:
          key: ${{ matrix.workspace-member }}
      - if: ${{ matrix.workspace-member == 'sql-integration' }}
        run: docker compose -f docker-compose.yml up -d
      - if: ${{ matrix.workspace-member == 'api-integration' }}
        run: cargo test --profile debug-release -- --nocapture
      - if: ${{ matrix.workspace-member != 'api-integration' }}
        run: cargo test --release -- --nocapture

  test-wasm-example:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    defaults:
      run:
        working-directory: examples/wasm-http-channels
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
      - name: Install wasm-pack
        uses: taiki-e/install-action@537c30d2b45cc3aa3fb35e2bbcfb61ef93fd6f02
        with:
          tool: wasm-pack@0.13.1 # install-action will download from github releases and verify the SHA of the binary
      - run: wasm-pack build --target web
        working-directory: ./examples/wasm-http-channels
        env:
          RUSTFLAGS: '--cfg getrandom_backend="wasm_js"'

  test-crates:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5
      - run: cargo test --profile debug-release --package polytune-server-core --package polytune-http-server -- --nocapture

  build-polytune-http-server-image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Build crates/polytune-http-server Dockerfile
        run: docker build . -f crates/polytune-http-server/Dockerfile --tag 'polytune-http-server'