GitHub Actions MSYS2 with Python

MSYS2 is useful for end user and developer laptops as well as CI. Using MSYS2 with Python on GitHub Actions CI requires adding MSYS2 to PATH just like the laptop. One factor is that MSYS2 is installed to a temporary directory.

Here is an example YaML workflow using MSYS2 with Python. Note we don’t use MSYS2 Python packages because they tend to be older versions than might be needed. The packages installed below aren’t specifically needed, it’s just an example of real-life use where I often use Ninja, Gfortran, HDF5, and CMake. This is a “build on run” package where the “pytest” command ultimately invokes CMake. We use GitHub Actions timeout parameters to avoid accidentally trying to build pip packages from source.

jobs:

  windows:
    runs-on: windows-latest
    steps:
    - uses: msys2/setup-msys2
      with:
        update: true
        install: >-
          mingw-w64-x86_64-ninja
          mingw-w64-x86_64-gcc-fortran
          mingw-w64-x86_64-hdf5          

    - uses: actions/setup-python
      with:
        python-version: '3.x'

    - uses: actions/checkout

    - run: echo "${{ runner.temp }}/msys/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

    - run: python -m pip install .[tests]
      timeout-minutes: 2

    - run: pytest
      env:
        CMAKE_GENERATOR: Ninja
      timeout-minutes: 7