配置脚本在 GitHub 操作上找不到 Windows 上的 grep

The configure script can't find grep on Windows on GitHub Actions

我正在尝试制作一个 PR to build my Haskell project on Windows on Github Actions, but the configuration script of the process-1.6.14.0 can't find grep. The complete GA log is here and here(相同的日志,但我已将其作为 Gists 上传,以防日志保留时间过期)。

grep 安装在 /usr/bin/grep

  which grep
  grep --version
  /usr/bin/grep --version
  shell: D:\a\_temp\setup-msys2\msys2.CMD {0}
  env:
    MSYSTEM: MINGW64
/usr/bin/grep
grep (GNU grep) 3.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
grep (GNU grep) 3.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

但是,配置脚本找不到它。

checking for grep that handles long lines and -e... configure: error: no acceptable grep could be found in /mingw64/bin:/c/Users/runneradmin/AppData/Roaming/cabal/bin:/usr/bin:/d/a/_temp/msys64/mingw64/bin:/d/a/_temp/msys64/usr/local/bin:/d/a/_temp/msys64/usr/bin:/d/a/_temp/msys64/usr/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/d/a/_temp/msys64/usr/bin/site_perl:/d/a/_temp/msys64/usr/bin/vendor_perl:/d/a/_temp/msys64/usr/bin/core_perl;/usr/xpg4/bin

我认为 grep 满足所有要求,因为我可以在本地 Windows 上使用相同版本的 grep 构建 process-1.6.14.0

这是 GA 脚本。

name: Haskell CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:

    strategy:
      matrix:
        sys:
        - { os: ubuntu-latest, shell: bash }
        - { os: windows-latest, shell: 'msys2 {0}' }

    runs-on: ${{ matrix.sys.os }}

    defaults:
      run:
        shell: ${{ matrix.sys.shell }}

    steps:
    - uses: actions/checkout@v2

    - uses: msys2/setup-msys2@v2
      with:
        update: true
        install: |
            base-devel
            mingw-w64-x86_64-pkg-config
            mingw-w64-x86_64-SDL2
            mingw-w64-x86_64-freeglut
            mingw-w64-x86_64-glew
            mingw-w64-x86_64-freetype
      if: runner.os == 'Windows'

    - uses: haskell/actions/setup@v1
      id: haskell_setup
      with:
        ghc-version: '8.10.7'
        cabal-version: '3.6.0.0'

    # Adding a path to msys2's PATH on GitHub Actions is pretty troublesome. So I'll output the path to a file.
    # (See https://github.com/msys2/setup-msys2/issues/98 to how to add a path to PATH.)
    - name: Store the path to Cabal (Windows)
      run: |
        echo "$(cygpath --unix '${{ steps.haskell_setup.outputs.cabal-exe }}') "'$@ '"-w $(cygpath --unix '${{ steps.haskell_setup.outputs.ghc-exe }}')" > cabal.sh
        chmod +x cabal.sh
      if: runner.os == 'Windows'

    - name: Store the path to Cabal (Linux)
      run: |
        echo '${{ steps.haskell_setup.outputs.cabal-exe }} $@' > cabal.sh
        chmod +x cabal.sh
      if: runner.os == 'Linux'

    - name: Cache
      uses: actions/cache@v2
      env:
        cache-name: cache-cabal
      with:
        path: |
          ~/.cabal/packages
          ~/.cabal/store
          dist-newstyle
        key: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }}-${{ github.sha }}
        restore-keys: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }}

    - name: Install dependencies (Linux)
      run: |
        sudo apt update
        sudo apt install libsdl2-dev libglew-dev moreutils
      if: runner.os == 'Linux'

    - name: Update Cabal
      run: ./cabal.sh update

    - name: Test grep
      run: |
        which grep
        grep --version
        /usr/bin/grep --version
      if: runner.os == 'Windows'

    - name: Build
      run: ./cabal.sh build --enable-tests --enable-benchmarks all -j

    - name: Run tests
      run: ./cabal.sh test all -j

  format_and_lint:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - uses: haskell/actions/setup@v1
      with:
        ghc-version: '8.10.7'
        cabal-version: '3.6.0.0'

    - name: Cache
      uses: actions/cache@v2
      env:
        cache-name: cache-cabal
      with:
        path: |
          ~/.cabal/packages
          ~/.cabal/store
          dist-newstyle
        key: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }}-${{ github.sha }}
        restore-keys: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }}

    - name: Update the PATH environment variable
      run: echo "$HOME/.cabal/bin" >> $GITHUB_PATH

    - name: Install dependencies
      run: |
        sudo apt update
        sudo apt install libsdl2-dev libglew-dev moreutils

        cabal update -j

        # See https://tokuchan3515.hatenablog.com/entry/2022/03/26/133158 why we separate `cabal install`s.
        cabal install weeder -j -z
        cabal install hindent -j -z
        cabal install stylish-haskell -j -z

    - name: Generate `cabal.project.local` for `weeder`
      run: "echo \"package * \n  ghc-options: -fwrite-ide-info\" > cabal.project.local"

    - name: Detect unused lines
      run: |
        cabal clean # This is necessary to run `weeder` correctly. See https://hackage.haskell.org/package/weeder.
        weeder

    - name: Set up HLint
      uses: haskell/actions/hlint-setup@v1

    - name: Run HLint
      uses: haskell/actions/hlint-run@v1
      with:
        path: '["src/", "tests/", "app/"]'
        fail-on: warning

    - name: Check format
      run: ./formatter.sh --check


为什么在 GA 上构建失败?

配置脚本接受 GREP 变量来指定 grep 的位置。所以,我更新了 GA 脚本。

    - name: Store the path to Cabal (Windows)
      run: |
        echo "GREP=$(which grep) $(cygpath --unix '${{ steps.haskell_setup.outputs.cabal-exe }}') "'$@ '"-w $(cygpath --unix '${{ steps.haskell_setup.outputs.ghc-exe }}')" > cabal.sh
        chmod +x cabal.sh
      if: runner.os == 'Windows'