GitHub Actions quick start

GitHub Actions is among the best no-cost CI and is relatively easy to use. Here are a couple example GitHub Actions templates we use across many projects. Each workflow is stored in the project under directory “.github/workflows”. For clarity, usually we use a filename like “.github/workflows/ci.yml”.

Pure Python

This template tests on Linux, MacOS and Windows. It waits to see if Linux succeeds before running MacOS and Windows, to save resources.

name: ci

on:
  push:
    paths:
      - "**.py"
      - .github/workflows/ci.yml


jobs:

  linux:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'

    - run: pip install .
    - run: pip install flake8 mypy pytest

    - run: flake8
    - run: mypy

    - run: pytest


  integration:
    needs: linux
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest, macos-latest]
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'

    - run: pip install .
    - run: pip install pytest

    - run: pytest

Fortran + Python

This uses the default GCC / Gfortran 9. You would instead apt install gfortran and other packages for ABI compatibility if you need say libhdf5-dev. Note how we version lock Python so that when a new Python release arrives, we don’t get false CI failures due to Python packages not being immediately ready for the new Python release.

name: ci

on:
  push:
    paths:
    - "**.py"
    - .github/workflows/ci.yml

jobs:

  linux:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: '3.8'

    - run: pip install .
    - run: pip install mypy flake8 pytest

    - run: flake8
    - run: mypy

    - run: pytest
      env:
        FC: gfortran-9

  macos:
    needs: linux
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: '3.8'

    - run: pip install .
    - run: pip install pytest

    - run: pytest
      env:
        CC: gcc-9
        FC: gfortran-9


  windows:
    needs: linux
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: '3.8'

    - run: pip install .
    - run: pip install pytest

    - run: pytest