Skip to content

shell in step/defaults cannot use job/matrix templates #444

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

Open
jacekkow opened this issue Apr 22, 2020 · 10 comments
Open

shell in step/defaults cannot use job/matrix templates #444

jacekkow opened this issue Apr 22, 2020 · 10 comments
Assignees
Labels
Runner Feature Feature scope to the runner

Comments

@jacekkow
Copy link

shell parameter in steps context should allow ${{ job/steps. }} variables.
I can see no reason for disallowing such expressions there.

To Reproduce

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
       - run: no matter what
         shell: echo ${{ job.status }}

https://github.com/jacekkow/github-actions-bugs/blob/master/.github/workflows/bug1.yml

Expected behavior
Step returns:

Success

Runner Version and Platform

GitHub Actions

What's not working?

The workflow fails:

The workflow is not valid. .github/workflows/bug1.yml (Line: 9, Col: 17): Unrecognized named-value: 'job'. Located at position 1 within expression: job.status

As far as I can tell this is due to non-empty-string being used instead of string-steps-context (or perhaps new non-empty-string-steps-context?) here:

"shell": "non-empty-string"

Similar change should also be made here:

"shell": "non-empty-string"

@jacekkow jacekkow added the bug Something isn't working label Apr 22, 2020
@TingluoHuang
Copy link
Member

Shell is mean to set to ‘cmd’ ‘bash’ ‘sh’ and ‘powershell’
We do support expressions in the script content

  • run: echo ${{job.status}}
    Shell: bash

@jacekkow
Copy link
Author

Shell is mean to set to ‘cmd’ ‘bash’ ‘sh’ and ‘powershell’

Per docs:

You can use built-in shell keywords, or you can define a custom set of shell options.

https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell

So I'm defining custom shell and its options (as documented). I really don't see a reason for "run" accepting expressions and "shell" not.

@TingluoHuang
Copy link
Member

@chrispat for whether we allow expression in script's shell option

@chrispat
Copy link
Member

I don't see any reason not to. The only reason we don't allow it is uses is so we can implement policy to prevent running certain actions.

@TingluoHuang TingluoHuang added enhancement New feature or request runner Runner Feature Feature scope to the runner and removed bug Something isn't working enhancement New feature or request runner labels Jun 8, 2020
@JustinGrote
Copy link

@chrispat any update? I want to run Powershell test/builds in matrix and right now I have two very redundant tasks with an if expression gating them.

@nikola-jokic
Copy link
Contributor

Hi @JustinGrote,

While reproducing this issue, I noticed that shell expression would work now. Could you please tell me if you are still experiencing this issue? If you do, could you provide an example repository so I can reproduce this behaviour with your workflow, so I don't miss anything?

@oplik0
Copy link

oplik0 commented Feb 8, 2022

Using the originally given example still seems to fail for me with Invalid workflow file error: https://github.com/oplik0/github-actions-shell-variables-test/actions/runs/1814312081/workflow

Full repo: https://github.com/oplik0/github-actions-shell-variables-test

Looking at files mentioned in the original post nothing seems to have changed there. The workflow I wanted to use this in (matrix for testing with different shells) also still doesn't seem to work, returning the same error.

Edit: added a quick example of my desired usage with matrix: https://github.com/oplik0/github-actions-shell-variables-test/blob/main/.github/workflows/matrix-example.yml - obviously also fails with same error: https://github.com/oplik0/github-actions-shell-variables-test/actions/runs/1819103791/workflow

@nikola-jokic
Copy link
Contributor

Thank you for providing an example @oplik0!

I added this issue to the feature board.

@thboop thboop changed the title shell in step cannot use job template shell in step cannot use job/matrix templates Feb 14, 2022
@thboop thboop changed the title shell in step cannot use job/matrix templates shell in step/defaults cannot use job/matrix templates Feb 14, 2022
@sio
Copy link

sio commented Jul 20, 2022

Another example where expressions could be useful in shell:

I tried to use custom shell with GitHub actions, and installed in previous step. But I can not reference the absolute path with: shell: ${{ github.workspace }}/bin/shell {0} because:

The workflow is not valid. .github/workflows/test.yml (Line: 77, Col: 16): Unrecognized named-value: 'github'

sio added a commit to sio/Makefile.venv that referenced this issue Jul 21, 2022
Adding a simple `git config...` command toppled the house of cards it was.
Multiple changes were requried to make Cygwin actions work again while
remaining somewhat readable and editable.

Here are some highlights in no particular order:

* Cygwin scripts now use custom shell in GitHub Actions.
  This is the proper way, but `shell:` definitions do not support contexts
  yet [1][2], so we have to resort to hardcoding CYGWIN_ROOT path everywhere.

  [1]: actions/runner#444
  [2]: https://docs.github.com/en/actions/learn-github-actions/contexts

* $HOME directory is now created in Cygwin for writing ~/.gitconfig

* $PATH definition must happen within Cygwin scripts and not in Actions
  config, because otherwise GitHub runner tries to be helpful and
  translates non-Windows $PATH to gibberish

* GitHub actions save custom scripts with CRLF delimiters, this is Windows
  after all. Bash does not support CRLF by default, so we need SHELLOPTS now

* Reformat Cygwin packages list while we're at it
@msJinLei
Copy link

I modifiy the example workflow https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#example-expanding-configurations
into the following one.
It reports the same error as above.

name: Conditional Shell Matrix Workflow

on: [push]

jobs:
  example_matrix:
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest]
        node: [14, 16]
        include:
          - os: windows-latest
            node: 16
            npm: 6
            shell: powershell
          - os: ubuntu-latest
            shell: bash
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout repository
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - name: Install NPM
        if: ${{ matrix.npm }}
        run: |
            npm install -g npm@${{ matrix.npm }}
            npm --version
      - name: Print current working directory
        shell: ${{ matrix.shell }}
        run: |
          echo "The current working directory is $GITHUB_WORKSPACE"
          ls "$GITHUB_WORKSPACE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Runner Feature Feature scope to the runner
Projects
None yet
Development

No branches or pull requests

8 participants