Skip to content

Commit

Permalink
Allow keeping Cygwin out of PATH
Browse files Browse the repository at this point in the history
In some circumstances, it might be useful to have Cygwin installed, but
not have its executables take precedence over pre-installed packages.
Add an "add-to-path" option that, if set to "false", will skip the step
of adding Cygwin's /bin directory to PATH.

Also update documentation to mention this option, and update the test
scripts to check it works as expected; the default behaviour is tested
as part of the "install-dir-test", and the new behaviour as part of the
main test.
  • Loading branch information
me-and authored and jon-turney committed Dec 29, 2022
1 parent f5e0f04 commit db47559
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
with:
platform: ${{ matrix.platform }}
packages: ${{ matrix.packages }}
add-to-path: false

- name: Explicitly running shell
run: C:\cygwin\bin\bash -lc "echo 'Explicitly run shell'"
Expand All @@ -52,6 +53,21 @@ jobs:
run: C:\cygwin\bin\sponge.exe tmp
if: contains(matrix.packages, 'moreutils')

- name: Check PATH hasn't changed
run: |
if [[ "${OSTYPE}" = "cygwin" ]]; then
echo "unexpectedly using Cygwin Bash"
exit 1
fi
if [[ "$(cygpath -aw "$(which cygpath)")" = 'C:\cygwin\'* ]]; then
echo "unexpectedly using Cygwin cygpath"
exit 1
fi
shell: bash # If Cygwin is not in PATH -- as expected -- this will be Git Bash
env:
SHELLOPTS: igncr

complex-test:
runs-on: windows-latest
name: 'Complex Test'
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Parameters
| install-dir | C:\cygwin | Installation directory
| site | http://mirrors.kernel.org/sourceware/cygwin/ | Mirror site to install from
| check-sig | true | Whether to check the setup.ini signature
| add-to-path | true | Whether to add Cygwin's `/bin` directory to the system `PATH`

Line endings
------------
Expand Down Expand Up @@ -52,7 +53,7 @@ Alternatively, you can also use:
PATH
----

This action prepends Cygwin's /usr/bin directory to the PATH.
By default, this action prepends Cygwin's /usr/bin directory to the PATH.

However, if you want to ensure that PATH only contains Cygwin executables,
and other stuff installed in the VM image isn't going to get picked up:
Expand All @@ -69,6 +70,8 @@ or,
* prevent the profile script from changing directory by putting
`CHERE_INVOKING` into the environment

If you want the opposite – the system PATH to remain unchanged by this action – add `add-to-path: false` to the action settings.

Symlinks
--------

Expand Down
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
site:
description: Download site URL
required: false
add-to-path:
description: Should Cygwin's bin directory be added to the system PATH?
required: false
default: true

runs:
using: "composite"
Expand Down Expand Up @@ -78,8 +82,11 @@ runs:
& C:\setup.exe $args | Out-Default
shell: powershell
- if: ${{ inputs.add-to-path == 'true' }}
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
shell: powershell

- run: |
echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
# run login shell to copy skeleton profile files
${{ inputs.install-dir }}\bin\bash.exe --login
shell: powershell
Expand Down

0 comments on commit db47559

Please sign in to comment.