name: Monthly cron

on:
  schedule:
    # run every 19th of the month at 6am UTC
    - cron: '0 6 19 * *'

jobs:
  test_more_architectures:

    # The following architectures are emulated and are therefore slow, so
    # we include them just in the monthly cron. These also serve as a test
    # of using system libraries and using pytest directly.

    name: Test on ${{ matrix.arch }}
    # Don't run on forks of the repository.
    if: startsWith(github.repository, 'mhvk')
    runs-on: ubuntu-20.04
    env:
      apt_packages: git python3-astropy python3-pyfftw python3-h5py python3-yaml python3-pip
      pip_packages: baseband
      distro: ubuntu20.04

    strategy:
      fail-fast: false
      matrix:
        include:
          - arch: s390x
          - arch: aarch64
          # ppc64le has strange errors that seem more likely numpy related.

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: uraimo/run-on-arch-action@v2.0.5
        name: Run tests
        id: build
        with:
          arch: ${{ matrix.arch }}
          distro: ${{ env.distro }}
          # Speeds up builds by storing container images in a GitHub package registry.
          githubToken: ${{ github.token }}
          shell: /bin/bash
          install: |
            apt-get update -q -y
            apt-get install -y ${{ env.apt_packages }}
            python3 -m pip install --user ${{ env.pip_packages }}
          run: |
            python3 setup.py egg_info
            python3 -m pytest

  test_with_apt:
    name: Test using apt
    runs-on: ubuntu-20.04
    if: startsWith(github.repository, 'mhvk')
    env:
      apt_packages: git python3-astropy python3-pyfftw python3-h5py python3-yaml python3-pip
      pip_packages: baseband

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Install system dependencies
      if: env.apt_packages
      run: sudo apt-get install ${{ env.apt_packages }}
    - name: Install Python dependencies
      if: env.pip_packages
      run: python -m pip install --user ${{ env.pip_packages }}
    - name: Run tests
      run: |
        python3 setup.py egg_info
        python3 -m pytest

  test_other_os:
    name: Test on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    if: startsWith(github.repository, 'mhvk')
    strategy:
      fail-fast: false
      matrix:
        include:

         - os: windows-latest
           python: 3.8
           toxenv: py38-test

         - os: macos-latest
           python: 3.8
           toxenv: py38-test

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python }}
    - name: Install Python dependencies
      run: python -m pip install --upgrade tox ${{ matrix.pip_packages }}
    - name: Run tests
      run: tox ${{ matrix.toxargs }} -e ${{ matrix.toxenv }} -- ${{ matrix.toxposargs }}
