name: Test

env:
  PROJECT_NAME: swiss-qr-bill-decoder
  CARGO_TERM_COLOR: always

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  test:
    runs-on: ${{ matrix.platform.runner }}
    strategy:
      matrix:
       platform:
         - name: linux-amd64
           runner: ubuntu-latest
           target: x86_64-unknown-linux-gnu
         - name: macos-amd64
           runner: macos-latest
           target: x86_64-apple-darwin
         - name: macos-arm64
           runner: macos-latest
           target: aarch64-apple-darwin

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

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: "${{ matrix.platform.target }}"

    - name: Rust (Cargo) Caching
      uses: Swatinem/rust-cache@v2

    - name: Install ghostscript (for linux)
      uses: awalsh128/cache-apt-pkgs-action@latest
      if: matrix.platform.runner == 'ubuntu-latest'
      with:
        packages: ghostscript
        version: 1.0

    - name: Install ghostscript (for macos)
      run: brew install ghostscript
      if: matrix.platform.runner == 'macos-latest'

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

    - name: Run tests
      run: cargo test --locked --target ${{ matrix.platform.target }}