首页 > 解决方案 > Github action windows runner:如何从 PATH 中删除所有 sh.exe

问题描述

在 github windows 运行器中,我需要从 PATH 中删除所有sh.exefind 否则我的基于 Make 4.3 的构建将无法正确解析我们的 Makefile...

我目前看到 2 个解决方案来解决它:

  1. 从中删除所有sh.exedirname 路径PATH(即更新GITHUB_PATH)。
  2. 另一种方法可能是直接删除sh.exe在 Windows 操作运行器中找到的任何内容。

到目前为止我测试过的都没有成功...

  1. 第一次尝试
- name: Remove sh.exe from PATH
  run: set GITHUB_PATH -= "/c/Program Files/Git/bin"

错误:A positional parameter cannot be found that accepts argument '/c/Program Files/Git/bin'.

  1. 尝试改用 bash
- name: Remove sh.exe from PATH
  run: |
        echo "$PATH"
        set PATH=%PATH:C:\Program Files\Git\bin;=%
        set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
        echo "$PATH" > $GITHUB_PATH
  shell: bash

错误:line 2: =%: command not found

附件

Github 仅提供将路径添加到 PATH 而不删除路径的示例。参考:https ://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path

标签: powershellgithub-actions

解决方案


要摆脱sh.exe(即解决方案 2),您应该尝试将以下 cmd 添加到您的.yml文件中:

    - name: Find sh.exe
      run: where sh
    - name: remove Git\usr\bin\sh.exe
      run: rm 'C:\Program Files\Git\usr\bin\sh.exe'
      shell: bash
    - name: remove Git\bin\sh.exe
      run: rm 'C:\Program Files\Git\bin\sh.exe'
      shell: bash

或者

    - name: Clean sh.exe
      run: |
        where sh
        rm 'C:\Program Files\Git\usr\bin\sh.exe'
        rm 'C:\Program Files\Git\bin\sh.exe'
      shell: bash

推荐阅读