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

Add option to skip downloading shellcheck on every run #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Shellcheck can print output in these formats: `checkstyle`, `diff`, `gcc`, `json

## Run a specific version of Shellcheck

If running the latest stable version of Shellcheck is not to your liking, you can specify a concrete version of Shellcheck to be used. When specifying a custom version, please use any of the released versions listed in the [Shellcheck repository](https://github.com/koalaman/shellcheck/tags).
If downloading the latest stable version of Shellcheck on each run is not to your liking, you can specify a concrete version of Shellcheck to be used, or skip downloading altogether in favor of pre-installed shellcheck in GitHub-hosted runners. When specifying a concrete version, please use any of the released versions listed in the [Shellcheck repository](https://github.com/koalaman/shellcheck/tags).

```yaml
...
Expand All @@ -166,3 +166,5 @@ If running the latest stable version of Shellcheck is not to your liking, you ca
with:
version: v0.9.0
```

To skip downloading shellcheck, use the special value `version: system`. Note that the version of Shellcheck [present in GitHub Actions runner images](https://github.com/actions/runner-images) might be behind the latest released version of Shellcheck.
mislav marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 16 additions & 14 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inputs:
required: false
default: "gcc"
version:
description: "Specify a concrete version of ShellCheck to use"
description: "The version of ShellCheck to download. Set to 'system' to use pre-installed shellcheck."
required: false
default: "stable"
outputs:
Expand All @@ -61,26 +61,30 @@ runs:
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
OS_NAME: ${{ runner.os }}
run: |
if [[ "${{ runner.os }}" == "macOS" ]]; then
if [ "${INPUT_VERSION}" = "system" ]; then
echo "Using system shellcheck: $(command -v shellcheck)"
exit 0
fi
mislav marked this conversation as resolved.
Show resolved Hide resolved

if [ "${OS_NAME}" = "macOS" ]; then
osvariant="darwin"
download_dir="$(mktemp -d -t shellcheck)"
else
osvariant="linux"
download_dir="$(mktemp -d --tmpdir shellcheck.XXX)"
mislav marked this conversation as resolved.
Show resolved Hide resolved
fi

baseurl="https://github.com/koalaman/shellcheck/releases/download"

curl -Lso "${{ github.action_path }}/sc.tar.xz" \
"${baseurl}/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz"
curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz" | \
tar -xz -C "${download_dir}" --strip-components 1 -- "shellcheck-${INPUT_VERSION}/shellcheck"

tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
"${{ github.action_path }}/shellcheck"
echo "${download_dir}" >> "$GITHUB_PATH"
Comment on lines +79 to +82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Verify shellcheck binary after extraction.

The download and extraction should be verified to ensure we have a working shellcheck binary.

 curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz" | \
   tar -xz -C "${download_dir}" --strip-components 1 -- "shellcheck-${INPUT_VERSION}/shellcheck"

+if [ ! -x "${download_dir}/shellcheck" ]; then
+  echo "::error::Failed to download or extract shellcheck"
+  exit 1
+fi
+
 echo "${download_dir}" >> "$GITHUB_PATH"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz" | \
tar -xz -C "${download_dir}" --strip-components 1 -- "shellcheck-${INPUT_VERSION}/shellcheck"
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
"${{ github.action_path }}/shellcheck"
echo "${download_dir}" >> "$GITHUB_PATH"
curl -fsSL "https://github.com/koalaman/shellcheck/releases/download/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz" | \
tar -xz -C "${download_dir}" --strip-components 1 -- "shellcheck-${INPUT_VERSION}/shellcheck"
if [ ! -x "${download_dir}/shellcheck" ]; then
echo "::error::Failed to download or extract shellcheck"
exit 1
fi
echo "${download_dir}" >> "$GITHUB_PATH"


- name: Display shellcheck version
shell: bash
run: |
"${{ github.action_path }}/shellcheck" --version
shellcheck --version

- name: Set options
shell: bash
Expand Down Expand Up @@ -204,13 +208,11 @@ runs:
-print0)

if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
shellcheck ${INPUT_SHELLCHECK_OPTIONS} \
"${filepaths[@]}" || statuscode=$?
else
for file in "${filepaths[@]}"; do
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
shellcheck ${INPUT_SHELLCHECK_OPTIONS} \
"$file" || statuscode=$?
done
fi
Expand Down