name: Run tests

# Trigger the workflow on push or pull request
on: [push, pull_request]

env:
  prefix: "/tmp/prefix"
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        configflags: ["", "--with-ntl --with-flint", "--without-ntl --with-flint"]

    steps:
      - uses: actions/checkout@v3
      - name: "Install dependencies"
        run: |
               FLINT_JLL="https://github.com/JuliaBinaryWrappers/FLINT_jll.jl/releases/download/FLINT-v200.700.0%2B0/FLINT.v200.700.0"
               if [ "$RUNNER_OS" == "Linux" ]; then
                    # sharutils is for uudecode
                    sudo apt install sharutils libgmp-dev libreadline-dev libmpfr-dev libntl-dev libcdd-dev 4ti2 normaliz
                    # install new enough FLINT
                    wget -O FLINT.tar.gz "${FLINT_JLL}.x86_64-linux-gnu.tar.gz"
                    sudo tar -C /usr -xvf FLINT.tar.gz
                    rm -f FLINT.tar.gz
               elif [ "$RUNNER_OS" == "macOS" ]; then
                    brew install autoconf automake libtool gmp readline mpfr ntl cddlib
                    # TODO: 4ti2?
                    # TODO: normaliz?
                    # install new enough FLINT
                    wget -O FLINT.tar.gz "${FLINT_JLL}.x86_64-apple-darwin.tar.gz"
                    sudo mkdir -p /usr/local
                    sudo tar -C /usr/local -xvf FLINT.tar.gz
                    rm -f FLINT.tar.gz
               else
                    echo "$RUNNER_OS not supported"
                    exit 1
               fi
      - run: ./autogen.sh
      - run: ./configure --prefix=$prefix --enable-gfanlib ${{ matrix.configflags }}
      - run: make -j3
      - run: make check
      - run: make install
      - run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Old/universal.lst
        if: ${{ always() }}
      #- run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Buch/buch.lst
      #  if: ${{ always() }}
      - run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Plural/short.lst
        if: ${{ always() }}
      - run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Plural/dmod.lst
        if: ${{ always() }}
      - run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Short/ok_s.lst
        if: ${{ always() }}
      #- run: cd Tst && ./regress.cmd -s $prefix/bin/Singular Long/ok_l.lst
      #  if: ${{ always() }}

# TODO: code coverage?
