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

Disable shellcheck when shell is powershell or pwsh #315

Closed
lorengordon opened this issue Jun 26, 2023 · 5 comments
Closed

Disable shellcheck when shell is powershell or pwsh #315

lorengordon opened this issue Jun 26, 2023 · 5 comments

Comments

@lorengordon
Copy link

I'm trying to figure out how to disable the shellcheck integration only when the shell is powershell or pwsh. I know about -shellcheck=, but for projects that exercise both linux and windows runners, we want shellcheck to run on the linux runners. Is there any way to exempt some workflow files from shellcheck entirely?

Here's a run with an example of the failure we're seeing: https://github.com/plus3it/actions-workflows/actions/runs/5380111038/jobs/9762319339?pr=18

@lorengordon
Copy link
Author

Hmm, seemingly, it doesn't run shellcheck when I explicitly set shell: pwsh on each step, but it doesn't work when using defaults:

defaults:
  run:
    shell: pwsh

lorengordon added a commit to lorengordon/actions-workflows that referenced this issue Jun 26, 2023
@rhysd
Copy link
Owner

rhysd commented Jun 29, 2023

Please branch your workflow step.

- run: actionlint
  if: ${{ runner.os != 'Windows' }}
- run: actionlint -shellcheck=
  if: ${{ runner.os == 'Windows' }}

It doesn't make sense to disable shellcheck on Windows by default because shellcheck supports Windows.

@rhysd rhysd closed this as completed Jun 29, 2023
@lorengordon
Copy link
Author

lorengordon commented Jul 6, 2023

Sorry, I was out of town until this morning. I think I understand. The problem was because actionlint was running shellcheck on a Windows-based runner, and the Windows runners do not support bash or sh as shell options, so that's never valid. While you can run shellcheck on Windows against bash scripts, that doesn't really apply in the context of GitHub Actions. I can use the workaround you suggest though, if you don't see a way of handling that internal to actionlint.

@rhysd
Copy link
Owner

rhysd commented Jul 7, 2023

The problem was because actionlint was running shellcheck on a Windows-based runner, and the Windows runners do not support bash or sh as shell options, so that's never valid.

Though the default shell is pwsh on Windows runner, it also supports Bash. Please try shell: bash. I recommend to use shell: bash persistently in all runners so that you can reuse same run: step across platforms (this is effective when you use matrix for runs-on:).

@lorengordon
Copy link
Author

🤯 oooooh! I had no idea bash was supported on windows runners in GitHub Actions. That's... interesting... I was migrating an old project from Appveyor when I hit this problem and opened the issue. All the logic I'm working with is in Powershell. Switching to bash might offer some interesting cross-platform consolidation options for our GitHub Actions... I'll have to think about that.

Ok, how about this bit then. It seems like actionlint skips shellcheck when shell: pwsh is added directly to the step. But it doesn't skip it when using:

defaults:
  run:
    shell: pwsh

See this commit for how I worked around the original error in the first place. But perhaps actionlint could detect an explicitly set default shell that is not sh/bash, and skip shellcheck? Would that be something that you think actionlint ought to handle?

Of course you've offered some other workarounds, so I understand if you think it's good enough as is. Really appreciate all your help!

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

No branches or pull requests

2 participants