Issue
I'd like to make sure all my shell scripts are properly linted using shellcheck
. One of the problems is that a lot of shell code is wrapped inside GitHub Actions workflows (.github/workflows/*.yml
), for example:
- name: Install Conda environment packages
run: foo install bar="${{ env.GDAL_VERSION }}" "${{ matrix.baz }}"
yq --nul-output '.jobs.*.steps[].run | select( . != null )' .github/workflows/*.yml
will get the raw YAML values for these, but the command as written in the YAML is not valid Bash - it's got GitHub Actions-specific ${{ NAME }}
syntax in there. I can't easily replace all such variable references with dummy values, so the better alternative would be to get the command as actually run by GitHub. Is this possible?
Solution
As Benjamin W. mentioned, the actionlint not only runs ShellCheck on the run steps but also handles the GitHub Actions-specific ${{ ... }}
syntax by replacing it with underscores, and it's worth noting that setting values in the environment of the step is often considered safer than expanding them directly, so, instead of using ${{ env.VARIABLE_NAME }}
, you can simply use $VARIABLE_NAME
.
first of all install actionlint
and ShellCheck
in your development environment and run actionlint
on your GitHub Actions workflow files (.github/workflows/*.yml)
to perform linting checks on the run steps, then try to verify that any GitHub Actions-specific syntax, such as ${{ ... }}
, is replaced with underscores by actionlint
and finally consider setting values in the environment of the step using $VARIABLE_NAME
rather than expanding them directly with ${{ env.VARIABLE_NAME }}
!
Answered By - Freeman Answer Checked By - Mildred Charles (WPSolving Admin)