
name: PyRAF CI test

on: [push]

jobs:
  tests:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    env:
      tmp: /tmp/
      iraf:  ${{ matrix.iraf }}
      TERM: dumb

    strategy:
      matrix:
        include:
          - name: Ubuntu 20.04 (Python-3.8.2), native
            os: ubuntu-20.04
            method: native
            iraf: /usr/lib/iraf/

          - name: Ubuntu 18.04 (Python-3.7), pip
            os: ubuntu-18.04
            method: pip
            iraf: /usr/lib/iraf/

          - name: macOS 10.15, pip
            os: macos-10.15
            method: pip
            iraf: /Users/runner/work/iraf/

    steps:
      - name: Checkout repository
        if: matrix.method == 'native'
        uses: actions/checkout@v2

      - name: Setup dependencies
        if: startsWith(matrix.os, 'ubuntu') && matrix.method == 'native'
        run: |
          sudo apt-get update
          sudo apt-get install --no-install-recommends iraf iraf-noao iraf-dev build-essential libx11-dev
          sudo apt-get install --no-install-recommends python3-dev python3-pip python3-astropy python3-numpy-dev python3-setuptools python3-setuptools-scm python3-tk python3-pytest python3-pytest-cov ipython3
          pip3 install "stsci.tools>=4.0.1" coveragepy

      - name: Setup dependencies
        if: startsWith(matrix.os, 'ubuntu') && matrix.method == 'pip'
        run: |
          sudo apt-get update
          sudo apt-get install --no-install-recommends iraf iraf-noao iraf-dev build-essential libx11-dev
          sudo apt-get install --no-install-recommends python3-dev python3-pip
          pip3 install ipython

      - name: Setup dependencies, Mac
        if: startsWith(matrix.os, 'macos') && matrix.method == 'pip'
        run: |
          mkdir $iraf
          curl https://cloud.aip.de/index.php/s/iPj7LGxbRedYnqa/download/iraf-macintel.tar.gz | tar -C $iraf -x -z
          (cd $iraf ; ./install < /dev/null || true)
          export PATH=${HOME}/.iraf/bin:${PATH}
          mkiraf -t=$TERM -n
          echo "PATH=$PATH" >> $GITHUB_ENV

      - name: Build PyRAF locally
        if: matrix.method == 'native'
        run: |
           python3 setup.py build_ext -i

      - name: Install PyRAF via pip
        if: matrix.method == 'pip'
        run: |
          pip3 install git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=pyraf[test]

      - name: Run tests (locally built)
        if: matrix.method == 'native'
        run: |
          python3 -m pytest --cov=pyraf

      - name: Run tests (installed package)
        if: matrix.method == 'pip'
        run: |
          python3 -m pytest -s --pyargs pyraf

      - name: "Upload coverage to Codecov"
        if: startsWith(matrix.os, 'ubuntu') && matrix.method == 'native'
        uses: codecov/codecov-action@v1
        with:
          fail_ci_if_error: false
