name: Tests
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  ubuntu:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        container_directory: [fedora-latest, rocky-8, centos-9-stream, alpine-edge, opensuse-leap, debian-latest, ubuntu-rolling, ubuntu-lts]

    name: Compile and run tests
    steps:
      - uses: actions/checkout@v2

      - name: Prep container
        run: ./autotest/${{ matrix.container_directory }}/prep.sh

      - name: Compile zchunk
        run: ./autotest/${{ matrix.container_directory }}/build.sh

      - name: Run zchunk tests
        run: ./autotest/${{ matrix.container_directory }}/test.sh

  windows-mamba:
    runs-on: windows-latest

    name: Compile and run tests (windows-latest-mamba)
    steps:
      - uses: actions/checkout@v2

      - name: Install mamba
        uses: mamba-org/setup-micromamba@main
        with:
          environment-file: .github/environment.yml
          init-shell: cmd.exe

      - name: Compile zchunk
        shell: cmd /C CALL {0}
        run: |
          CALL micromamba activate zchunk_test_env
          meson setup builddir
          meson compile -C builddir

      - name: Run zchunk tests
        shell: cmd /C CALL {0}
        run: |
          CALL micromamba activate zchunk_test_env
          cd builddir
          ninja test

  windows-meson-wrap:
    runs-on: windows-latest

    name: Compile and run tests (windows-latest-meson-wrap)
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v1
        with:
          python-version: '3.x'

      - name: Install meson and ninja
        run: pip install meson ninja

      - name: Compile zchunk
        shell: cmd /C CALL {0}
        run: |
          meson setup builddir
          meson compile -C builddir

      - name: Run zchunk tests
        shell: cmd /C CALL {0}
        run: |
          cd builddir
          ninja test

  windows-static:
    runs-on: windows-latest

    name: Compile and run tests (windows-latest-static)
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v1
        with:
          python-version: '3.x'

      - name: Install meson and ninja
        run: pip install meson ninja

      - name: Compile zchunk
        shell: cmd /C CALL {0}
        run: |
          meson setup builddir --default-library=static
          meson compile -C builddir

      - name: Run zchunk tests
        shell: cmd /C CALL {0}
        run: |
          cd builddir
          ninja test


  macos:
    runs-on: macos-latest

    name: Compile and run tests (macos-latest)
    steps:
      - uses: actions/checkout@v2

      - name: Install mamba
        uses: mamba-org/setup-micromamba@main
        with:
          environment-file: .github/environment.yml

      - name: Compile zchunk
        shell: bash -l {0}
        run: |
          meson builddir --prefix=$CONDA_PREFIX
          cd builddir
          ninja

      - name: Run zchunk tests
        shell: bash -l {0}
        run: |
          cd builddir
          ninja test
