From db475590d56881c6cef7b3f96f6f3dd9532ea1f4 Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Sat, 24 Dec 2022 15:06:31 +0000 Subject: [PATCH] Allow keeping Cygwin out of PATH 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. --- .github/workflows/test.yml | 16 ++++++++++++++++ README.md | 5 ++++- action.yml | 9 ++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1116f90..429026c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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'" @@ -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' diff --git a/README.md b/README.md index 2a9a8d8..54b1b66 100644 --- a/README.md +++ b/README.md @@ -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 ------------ @@ -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: @@ -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 -------- diff --git a/action.yml b/action.yml index c039af1..a6b6b95 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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