actions / runner-images

GitHub Actions runner images
MIT License
9.22k stars 2.86k forks source link

Add MSYS2 to Windows #30

Closed kaylangan closed 4 years ago

kaylangan commented 4 years ago

Tool information

Virtual environments affected

Can this tool be installed during the build? Yes, via choco install msys2.

Are you willing to submit a PR?

MSP-Greg commented 4 years ago

@andreasdotorg

Git's bash shell has been the default on Win images, so MSYS2 is not included in Path. Pacman is located at C:\msys64\usr\bin. You may need to add other locations to Path to use the MSYS2 MinGW tools.

1480c1 commented 4 years ago

In appveyor, I used

$path = ([System.Environment]::GetEnvironmentVariable('PATH', 'Machine').Split(';') | Where-Object { $_ -notmatch 'Git' }) -join ';'
[System.Environment]::SetEnvironmentVariable('PATH', $path, 'Machine')

to remove git from the path so I could use msys2's C:\msys64\usr\bin;C:\msys64\mingw64\bin in the path without any conflicts, you might be able to modify it to match github actions better

nulano commented 4 years ago

I'm using the following to run commands in MSYS/MinGW32 or MSYS/MinGW64 bash shell:

name: Test Windows
on: [push, pull_request]
jobs:
  msys:
    runs-on: windows-2019
    strategy:
      matrix:
        mingw: ["MINGW32", "MINGW64"]
        include:
          - mingw: "MINGW32"
            package: "mingw-w64-i686"
          - mingw: "MINGW64"
            package: "mingw-w64-x86_64"
    defaults:
      run:
        shell: bash.exe --login -eo pipefail "{0}"
    env:
      MSYSTEM: ${{ matrix.mingw }}
      CHERE_INVOKING: 1
    name: MSYS2 ${{ matrix.mingw }}
    steps:
      - name: Set up shell
        run: echo ::add-path::C:\msys64\usr\bin\
        shell: pwsh
      - name: Print system version
        run: |
          uname
      - name: Install package
        run: |
          # install python
          pacman -S --noconfirm ${{ matrix.package }}-python3-setuptools
          # build the project
          python3 setup.py install

The first step adds msys at the start of the path, and the MSYSTEM and CHERE_INVOKING envvars tell MSYS bash to run on the given platform (MinGW32 or MinGW64) and in the project directory. I'm setting a default custom shell to run multiple steps in the MSYS shell, but you can explicitly set it for each step.

Edit: added @1480c1's suggestion

1480c1 commented 4 years ago

You might want to add -eo pipefail to your shell: line to emulate what github actions uses for their bash

eine commented 4 years ago

@nulano, I updated the README in eine/setup-msys2 to show how to set a default shell, as you did. The main differences between your approach and setup-msys2 are the following:

You can find multiple workflow setups in https://github.com/eine/setup-msys2/blob/master/.github/workflows/action.yml.

Ref #916 #908 #906 #899 #355 #342

vsafonkin commented 4 years ago

Msys2 was added to Windows images, this issue is closed.