Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows - step: shell: bash #497

Closed
MSP-Greg opened this issue May 21, 2020 · 14 comments
Closed

Windows - step: shell: bash #497

MSP-Greg opened this issue May 21, 2020 · 14 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@MSP-Greg
Copy link

MSP-Greg commented May 21, 2020

Currently, when choosing the bash shell option in Windows, the following is the command:

C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}

Note that C:\Program Files\Git\bin is already in PATH.

MSYS2 is now included in the Windows image, and the Git bash shell is based on it.

If the path was removed from the command, as below, people could switch to the MSYS2 bash shell by simply adjusting PATH.

bash.exe --noprofile --norc -e -o pipefail {0}

Discussions about MSYS2 have been going on for a while, I know some people have asked for a way to use its bash shell...

EDIT: See issue #460, as custom shells are not working.

@eregon
Copy link

eregon commented Jun 6, 2020

@al-cheb @maxim-lobanov @sergey-akhalkov Could this be prioritized?

Correct me if I'm wrong but I think having this would avoid issues like actions/runner-images#905 when using shell: bash on Windows and MSYS2 is earlier in PATH.

When MSYS2 is earlier in PATH, it's a clear choice one prefers MSYS2, so I would argue using the first bash.exe in path, in that case MSYS2 is intuitive and better than always using Git Bash which can cause issues.

@maxim-lobanov
Copy link

@al-cheb @maxim-lobanov @sergey-akhalkov Could this be prioritized?

Correct me if I'm wrong but I think having this would avoid issues like actions/runner-images#905 when using shell: bash on Windows and MSYS2 is earlier in PATH.

When MSYS2 is earlier in PATH, it's a clear choice one prefers MSYS2, so I would argue using the first bash.exe in path, in that case MSYS2 is intuitive and better than always using Git Bash which can cause issues.

@eregon our team doesn't own runner (only images content) so we can't help here.

cc: @TingluoHuang , @bryanmacfarlane probably can help and take a look at this request

@TingluoHuang
Copy link
Member

What about to use ::add-path::{path} to change PATH dynamically in your workflow?

@TingluoHuang TingluoHuang added the question Further information is requested label Jun 8, 2020
@MSP-Greg
Copy link
Author

MSP-Greg commented Jun 8, 2020

@TingluoHuang

Thanks for suggestion. Tried that already, doesn't work. See:

https://github.com/MSP-Greg/actions-image-testing/runs/751245284

Notes:

  1. In the `where bash' step, the first exe listed is the MSYS2 shell.

  2. In the 'Show Path' step, the MSYS2/MSYS64 paths precede the Git paths.

  3. In the 'shell: bash' and 'shell: bash.exe' steps, expanding them shows that 'shell:' has been
    expanded to: shell: C:\Program Files\Git\bin\bash.exe --noprofile --norc -e -o pipefail {0}

  4. Using a full path fails, as shown in the last step.

Sorry about the duplicate issues, I'll close #460.

@TingluoHuang
Copy link
Member

@MSP-Greg I am able to make it work by

    - name:  "add-path"
      shell: cmd
      run:   |
        echo ::add-path::C:\msys64\usr\bin
        dir C:\msys64\usr\bin
    - name:  "shell: bash.exe"
      shell: bash
      run:   |
        openssl version -d
        pwd

Output:

##[debug]Evaluating condition for step: 'add-path'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: add-path
##[debug]Loading inputs
##[debug]Loading env
Run echo ::add-path::C:\msys64\usr\bin
##[debug]C:\windows\system32\cmd.EXE /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\f0f87a25-cbf0-41c6-96c8-df6e837e85e5.cmd""
::add-path::C:\msys64\usr\bin
 Volume in drive C is Windows
 Volume Serial Number is AEDA-A7B9

 Directory of C:\msys64\usr\bin

05/31/2020  11:13 AM    <DIR>          .
05/31/2020  11:13 AM    <DIR>          ..
05/18/2020  08:39 AM                99 2to3
05/18/2020  08:39 AM                99 2to3-3.8
04/16/2020  08:18 PM            37,247 a2x
04/16/2020  08:18 PM            37,247 a2x.py
03/02/2020  11:10 AM           148,315 accessdb.exe
06/12/2018  07:24 AM             4,626 aclocal
07/21/2015  06:50 AM            31,162 aclocal-1.10
07/21/2015  06:47 AM            31,104 aclocal-1.11
07/21/2015  06:44 AM            31,726 aclocal-1.12
07/21/2015  06:39 AM            36,734 aclocal-1.13
  shell: bash.exe1s
    env2: 200
##[debug]Evaluating condition for step: 'shell: bash.exe'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: shell: bash.exe
##[debug]Loading inputs
##[debug]Loading env
Run openssl version -d
  openssl version -d
  pwd
  shell: C:\msys64\usr\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    env1: 1000
    env2: 200
##[debug]C:\msys64\usr\bin\bash.EXE --noprofile --norc -e -o pipefail d:\a\_temp\ace68999-b711-4827-bbbb-f8657d41345b.sh

@TingluoHuang
Copy link
Member

The problem with your example is we are trying to run which against the full path you provide and the runner throw exception on it. I am going to fix that.

@MSP-Greg
Copy link
Author

MSP-Greg commented Jun 8, 2020

@TingluoHuang

Thanks. I tried adding the echo ::add-path::C:\msys64\usr\bin step, and that works. But, if you expand the detail in the steps (the 'Run' section), it doesn't appear to be changing the Path, so why is it working?

run which against

Been a while since I coded in cs, but I also found that.

Question: Not sure if I can phrase this well, is the runner assembling all the workflow steps in one pass (before running them), or does it parse steps 'real-time' (after the previous step runs)?

@TingluoHuang
Copy link
Member

@MSP-Greg it parse steps 'real-time' after the previous step runs.

@MSP-Greg
Copy link
Author

MSP-Greg commented Jun 8, 2020

@TingluoHuang

Thanks. Given that, I'm confused about the Path behavior. I'll look at the code more later...

@MSP-Greg
Copy link
Author

MSP-Greg commented Jun 8, 2020

@TingluoHuang

I might know what the problem is. I assume the runner needs to maintain it's Path, and probably caches it. But your above fix shows that ::add-path:: affects that.

In the ruby/setup-ruby action, since we'd prefer to remove the 'system' ruby from Path, items are both removed and added to Path. It was done via one call to core.exportVariable('PATH', newPath).

I split that up, so it used core.addPath(item) for the additions, and the shell: command works as your example above.

Unfortunately, the MSYS2 shell and the Git shell behave a little differently, so I have to check that, since the change would swap the shells for anyone using a script: bash step after using the action... Thanks.

@TingluoHuang
Copy link
Member

@MSP-Greg Cool, let me know if there is anything else I can help on this, feel free to close the issue if you get everything you want. 😄

@MSP-Greg
Copy link
Author

MSP-Greg commented Jun 9, 2020

@TingluoHuang Thanks. I've got some odd things with Path, but I've also got some odd things with the Ruby MSVC build. Most people use Ruby MSYS2/MinGW builds, but both are tested in CI.

I may be back begging for a core method to remove apps from Path, so (for example) one could remove the 'system' Ruby from Path. I'll look at actions/setup-ruby to see if they leave the system one active; haven't looked at that code for a while..

@charankumar510
Copy link

@MSP-Greg I am able to make it work by

    - name:  "add-path"
      shell: cmd
      run:   |
        echo ::add-path::C:\msys64\usr\bin
        dir C:\msys64\usr\bin
    - name:  "shell: bash.exe"
      shell: bash
      run:   |
        openssl version -d
        pwd

Output:

##[debug]Evaluating condition for step: 'add-path'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: add-path
##[debug]Loading inputs
##[debug]Loading env
Run echo ::add-path::C:\msys64\usr\bin
##[debug]C:\windows\system32\cmd.EXE /D /E:ON /V:OFF /S /C "CALL "d:\a\_temp\f0f87a25-cbf0-41c6-96c8-df6e837e85e5.cmd""
::add-path::C:\msys64\usr\bin
 Volume in drive C is Windows
 Volume Serial Number is AEDA-A7B9

 Directory of C:\msys64\usr\bin

05/31/2020  11:13 AM    <DIR>          .
05/31/2020  11:13 AM    <DIR>          ..
05/18/2020  08:39 AM                99 2to3
05/18/2020  08:39 AM                99 2to3-3.8
04/16/2020  08:18 PM            37,247 a2x
04/16/2020  08:18 PM            37,247 a2x.py
03/02/2020  11:10 AM           148,315 accessdb.exe
06/12/2018  07:24 AM             4,626 aclocal
07/21/2015  06:50 AM            31,162 aclocal-1.10
07/21/2015  06:47 AM            31,104 aclocal-1.11
07/21/2015  06:44 AM            31,726 aclocal-1.12
07/21/2015  06:39 AM            36,734 aclocal-1.13
  shell: bash.exe1s
    env2: 200
##[debug]Evaluating condition for step: 'shell: bash.exe'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: shell: bash.exe
##[debug]Loading inputs
##[debug]Loading env
Run openssl version -d
  openssl version -d
  pwd
  shell: C:\msys64\usr\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    env1: 1000
    env2: 200
##[debug]C:\msys64\usr\bin\bash.EXE --noprofile --norc -e -o pipefail d:\a\_temp\ace68999-b711-4827-bbbb-f8657d41345b.sh

@TingluoHuang I was able to run the first action but the second one "shell: bash.exe" is failing with error "Error: bash: command not found"

@Wilhelmsson177
Copy link

Wilhelmsson177 commented Mar 30, 2023

@charankumar510 Please check the documentation on how to add something to path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants