cygwin / cygwin-install-action

GitHub action to install Cygwin
GNU General Public License v3.0
22 stars 11 forks source link

Cannot cd ${GITHUB_WORKSPACE} #11

Closed robandpdx closed 10 months ago

robandpdx commented 10 months ago

I'll start by acknowledging that this is probably not an issue with this action. However, anyone that uses this action and intends to use shell: C:\cygwin\bin\bash.exe -l '{0}' will likely face this issue. Therefore, solving this issue here would be helpful to the community of uses here.

This section of the README says to cd ${GITHUB_WORKSPACE} in your shell script if you are using a login shell (bash -l). It seem so simple, yet I cannot make that work.

Here is my workflow to demonstrate the issue with cd ${GITHUB_WORKSPACE} using a login shell...

name: Cygwin testing
on:
  push:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - labeled
  issue_comment:
  workflow_dispatch:
  issues:
    types: 
      - opened

jobs:
  install-cygwin-and-do-stuff:
    runs-on: windows-latest
    steps:
      - run: git config --global core.autocrlf input
      - uses: actions/checkout@v2

      - name: Install cygwin
        uses: cygwin/cygwin-install-action@master
        with:
          packages: >-
            coreutils
            moreutils

      - name: Show cygwin env with login shell
        shell: C:\cygwin\bin\bash.exe -l '{0}'
        env:
          CYGWIN_NOWINPATH: 1
        run: |
          echo "PWD = $(pwd)"
          echo "GITHUB_WORKSPACE = ${GITHUB_WORKSPACE}"
          echo "cygpath GITHUB_WORKSPACE = $(cygpath ${GITHUB_WORKSPACE})"
          echo "cd into GITHUB_WORKSPACE..."
          cd "${GITHUB_WORKSPACE}"
I have tried several different things in place of ${GITHUB_WORKSPACE} in the workflow above with different results, noted below... Attempt Result
cd "$(cygpath ${GITHUB_WORKSPACE})" cd: $'/cygdrive/d/a/tools/tools\r': No such file or directory
cd /cygdrive/d/ cd: $'/cygdrive/d/\r': No such file or directory
cd "${GITHUB_WORKSPACE}" cd: $'D:\\a\\tools\\tools\r': No such file or directory

I appreciate any help with this. Thank you!

jon-turney commented 10 months ago

Interesting.

I think perhaps this is falling afoul of the line ending issue mentioned above in the README : "if you have multiple lines of shell script in a YAML block for run: in your workflow file, the file this is written into on the runner ends up with \r\n line endings."

So you need to use one of the methods there for ensuring that the "cd ${GITHUB_WORKSPACE}" line isn't presented to bash with a \r at the end, or causing it to be ignored?

robandpdx commented 10 months ago

@jon-turney Thanks for the help! That was it. My workflow now looks like the following, and it works!

name: Cygwin testing
on:
  push:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - labeled
  issue_comment:
  workflow_dispatch:
  issues:
    types: 
      - opened

jobs:
  install-cygwin-and-do-stuff:
    runs-on: windows-latest
    steps:
      - run: git config --global core.autocrlf input
      - uses: actions/checkout@v2

      - name: Install cygwin
        uses: cygwin/cygwin-install-action@master
        with:
          packages: >-
            coreutils
            moreutils

      - name: Show cygwin env with login shell
        shell: C:\cygwin\bin\bash.exe -l '{0}'
        env:
          CYGWIN_NOWINPATH: 1
        run: >-
          echo "PWD = $(pwd)" ;
          echo "GITHUB_WORKSPACE = ${GITHUB_WORKSPACE}" ;
          echo "cygpath GITHUB_WORKSPACE = $(cygpath ${GITHUB_WORKSPACE})" ;
          echo "cd into GITHUB_WORKSPACE..." ;
          cd "${GITHUB_WORKSPACE}"
jon-turney commented 10 months ago

Great!

I think maybe the "Line endings" section in the README could be clarified, maybe the two separate issues is covers being marked with bullets or something to make it easier to pick up that point.