GitHub Actions MSYS2 with Python

MSYS2 is very 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.

Example

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: actions/checkout@v2
    - uses: msys2/setup-msys2@v2
      with:
        update: true
        install: >-
          git
          mingw-w64-x86_64-cmake
          mingw-w64-x86_64-ninja
          mingw-w64-x86_64-gcc-fortran
          mingw-w64-x86_64-hdf5          
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'

    - run: echo "D:/a/_temp/msys/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

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

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