Skip to content

PATH of bash shell in Windows is not correct. #26149

PATH of bash shell in Windows is not correct. #26149
Mar 12, 2020 · 5 answers

I have these pieces of configurations in my workflow.

steps:
      - uses: actions/checkout@v1
      - uses: DanTup/gh-actions/setup-dart@master
      - name: Build
        run: |
          pub get
          mkdir build
          dart2native bin/main.dart -v -o build/${{ matrix.output-name }}
        shell: bash

I got pub: command not found issue.
If I remove shell: bash and use the builtin shell, then it’s ok.

Finally, I refactor the code like the following.

- name: Build
        run: |
          # check Linux/MacOS or Windows
          if hash pub 2>/dev/null; then PUB=pub; DART2NATIVE=dart2native; else PUB=pub.bat; DART2NATIVE=dart2native.bat; fi
          mkdir build
          $PUB get
          $DART2NATIVE bin/main.dart -v -o build/${{ matrix.output-name }}
        shell: bash

Replies

5 suggested answers

@liudonghua123 ,

You can try using " pub.bat" instead of directly " pub" to run the commands, this can also work on bash shell.

For example:

- name: Run pub with bash
  shell: bash
  run: |
    pub.bat get
  • name: Run pub with pwsh
    shell: pwsh
    run: |
    pub.bat get
0 replies

I can’t use this syntax, because I used matrix strategy and I need to run the command in MacOS and Linux too. In my opinion, we should find the true reasons, fix the PATH inheritance in bash of git in Windows. Command of Windows can run without extension defined in PATHEXT environment variable.

0 replies

Finally, I refactor the code like the following.

- name: Build
        run: |
          # check Linux/MacOS or Windows
          if hash pub 2>/dev/null; then PUB=pub; DART2NATIVE=dart2native; else PUB=pub.bat; DART2NATIVE=dart2native.bat; fi
          mkdir build
          $PUB get
          $DART2NATIVE bin/main.dart -v -o build/${{ matrix.output-name }}
        shell: bash
0 replies
Answer selected

@liudonghua123 ,

Thanks for sharing your workarond.
I also tested the pub commands after installing the Dart-SDK on my local Windows machine, and I also reproduce same issue. Looks like, this problem occurs on Windows, and it should not be an issue for GitHub Actions.
Similar to your shared workaround, I also have a workaround to run the pub commands with bash shell on different OSs.

jobs:
  TEST:
    name: Test
    runs-on: ${{ matrix.os }}
    env:
      PUB: pub
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
    steps:
      - name: setup-dart
        uses: DanTup/gh-actions/setup-dart@master
  - name: Change env
    if: matrix.os == 'windows-latest'
    run: echo "::set-env name=PUB::pub.bat"

  - name: Test pub command
    shell: bash
    run: |
      $PUB --help

0 replies

@brightran wrote:

@liudonghua123 ,

Thanks for sharing your workarond.
I also tested the pub commands after installing the Dart-SDK on my local Windows machine, and I also reproduce same issue. Looks like, this problem occurs on Windows, and it should not be an issue for GitHub Actions.
Similar to your shared workaround, I also have a workaround to run the pub commands with bash shell on different OSs.

jobs:
TEST:
name: Test
runs-on: ${{ matrix.os }}
env:
PUB: pub
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:

  • name: setup-dart
    uses: DanTup/gh-actions/setup-dart@master
  • name: Change env
    if: matrix.os == ‘windows-latest’
    run: echo “::set-env name=PUB::pub.bat”
  • name: Test pub command
    shell: bash
    run: |
    $PUB --help

Thanks, your solution is more elegance and readable.

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants