使用 Cygwin Bash 而不是 Git Bash 的 Github Actions 和 Windows。

huangapple go评论60阅读模式
英文:

Github Actions and Windows: using Cygwin bash instead of git-bash

问题

我正在使用在 Windows 上运行的 Github Actions。镜像是 `windows-2022`,并且在工作流程的一部分中安装了 Cygwin。据我了解,Windows 镜像已经预装了 git-bash。

Cygwin 的安装步骤如下:

    - name: "Windows: Cygwin 下载"
      if: runner.os == 'Windows'
      run: |
        Invoke-WebRequest 'https://cygwin.com/setup-x86_64.exe' -OutFile 'setup-x86_64.exe'

    - name: "Windows: Cygwin 设置"
      if: runner.os == 'Windows'
      # 由于某种原因,PowerShell 中的设置无法正确完成
      shell: cmd
      run: .\setup-x86_64.exe --quiet-mode --site http://cygwin.mirror.constant.com --symlink-type=sys --packages mingw64-i686-binutils=2.37-2,mingw64-x86_64-binutils=2.37-2,curl,diffutils,git,m4,make,mercurial,mingw64-i686-gcc-core,mingw64-i686-gcc-g++,mingw64-x86_64-gcc-core,mingw64-x86_64-gcc-g++,patch,perl,rsync,unzip

当我为步骤指定 `shell: bash` 时,我发现无法运行任何 Cygwin 工具。`bash --version` 报告:

    GNU bash, version 5.2.12(1)-release (x86_64-pc-msys)

而 `C:\\cygwin64\\bin\\bash --version` 报告:

    GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)

因此,显然我是在运行 `git-bash` 而不是 Cygwin 版本。

如何让 Github Actions 在 Cygwin 的 bash 版本中执行特定步骤(或所有步骤)?
英文:

I am working with Github Actions running on Windows. The image is windows-2022 and has Cygwin installed a part of the workflow. As I have learned, the Windows image has git-bash on board already.

Cygwin is installed as follows:

- name: "Windows: Cygwin download"
  if: runner.os == 'Windows'
  run: |
    Invoke-WebRequest 'https://cygwin.com/setup-x86_64.exe' -OutFile 'setup-x86_64.exe'

- name: "Windows: Cygwin setup"
  if: runner.os == 'Windows'
  # The setup does not complete properly in powershell for some reason
  shell: cmd
  run: .\setup-x86_64.exe --quiet-mode --site http://cygwin.mirror.constant.com --symlink-type=sys --packages mingw64-i686-binutils=2.37-2,mingw64-x86_64-binutils=2.37-2,curl,diffutils,git,m4,make,mercurial,mingw64-i686-gcc-core,mingw64-i686-gcc-g++,mingw64-x86_64-gcc-core,mingw64-x86_64-gcc-g++,patch,perl,rsync,unzip

When I specify shell: bash for a step, I find I cannot run any Cygwin tools. bash --version reports:

GNU bash, version 5.2.12(1)-release (x86_64-pc-msys)

whereas C:\\cygwin64\\bin\\bash --version reports:

GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)

So apparently I am running in git-bash rather than the Cygwin version.

How can I get GHA to execute a particular step (or all of them) in Cygwin’s version of bash, not git-bash?

答案1

得分: 2

使用以下方式配置Cygwin与shell

shell: C:\cygwin64\bin\bash.exe --login '{0}'

对于所有步骤,请使用defaults.run。但是,在Windows运行器中(20192022),至少需要为安装Cygwin的一步指定不同的shell,就像您在工作流程中已经在做的那样。

对于逐步的shell配置,您可以使用jobs.<job_id>.steps[*].shell

这个操作(https://github.com/marketplace/actions/install-cygwin)可能对安装Cygwin会有所帮助,而不是自己手动安装。

英文:

Configure Cygwin with shell like this:

shell: C:\cygwin64\bin\bash.exe --login &#39;{0}&#39;

For all the steps, use defaults.run. However, Cygwin is not preinstalled in Windows runners (2019 or 2022), at least for one step which installs Cygwin, you'll have to specify a different shell as you're already doing in your workflow.

For per-step shell configuration, you can use jobs.&lt;job_id&gt;.steps[*].shell.

This action (https://github.com/marketplace/actions/install-cygwin) might be helpful for installing Cygwin instead of doing it yourself.

huangapple
  • 本文由 发表于 2023年2月19日 09:26:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定