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”.

This Python 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
    - uses: actions/setup-python
      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
    - uses: actions/setup-python
      with:
        python-version: '3.x'

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

    - run: pytest

This Fortran + Python example uses the default GCC / Gfortran. Use 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
    - uses: actions/setup-python
      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
    - uses: actions/setup-python
      with:
        python-version: '3.8'

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

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


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

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

    - run: pytest