name: Covasim CI workflow
on: [push, pull_request]

jobs:
  install_and_test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      max-parallel: 8
      matrix:
        python-version: ['3.7', '3.8']
    name: Install and test
    steps:
      - name: Set repo owner env variable
        shell: python
        run: print("::set-env name=GITHUB_OWNER::{}".format('${{github.repository}}'.split('/')[0]))
      - name: Checkout sources
        uses: actions/checkout@v1
      - name: Checkout synthpops
        uses: actions/checkout@v2
        with:
            repository: ${{ env.GITHUB_OWNER }}/synthpops
            token: ${{ secrets.GitHub_PAT }}
            path: ./synthpops
      - uses: actions/setup-python@master
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64
      - name: Install Covasim
        run: python setup.py develop
      - name: Install synthpops
        working-directory: ./synthpops
        run: python setup.py develop
      - name: Run tests
        working-directory: ./tests
        run: |
          pip install pytest
          pytest test*.py unittests/test*.py --junitxml=test-results.xml # Run actual tests
      - name: Run examples
        working-directory: ./examples
        run: python *.py
      - name: Run cruise ship
        working-directory: ./covasim/cruise_ship
        run: python test*.py
      - name: Upload test results
        uses: actions/upload-artifact@v1
        if: failure()
        with:
          name: test_results
          path: tests/test-results.xml