Skip to content

Commit ac64a9d

Browse files
authored
GitHub Actions: Fix Shellsheck workflow to only run on changes *.sh files (#1423)
1 parent 7376250 commit ac64a9d

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

.github/workflows/shellcheck.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,45 @@ jobs:
1818
- uses: actions/checkout@v4
1919

2020
- name: Get changed files
21-
id: changes
21+
id: changed-files
22+
uses: tj-actions/changed-files@v45
23+
with:
24+
files: |
25+
**.sh
26+
27+
# This is a manual copy from https://github.com/ludeeus/action-shellcheck/blob/00b27aa7cb85167568cb48a3838b75f4265f2bca/action.yaml#L59
28+
# Why? Because the action is not capable of adding ONLY a list of files.
29+
# We aim to only check the files that have changed.
30+
# This is used as we deal with a codebase that throws a lot of warnings.
31+
# Checking only the changed files is a good compromise to improve the codebase over time.
32+
- name: Download shellcheck
33+
shell: bash
34+
env:
35+
INPUT_VERSION: "v0.10.0"
2236
run: |
23-
if ${{ github.event_name == 'pull_request' }}; then
24-
echo "files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
37+
if [[ "${{ runner.os }}" == "macOS" ]]; then
38+
osvariant="darwin"
2539
else
26-
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
40+
osvariant="linux"
2741
fi
2842
43+
baseurl="https://github.com/koalaman/shellcheck/releases/download"
44+
45+
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
46+
"${baseurl}/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz"
47+
48+
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
49+
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
50+
"${{ github.action_path }}/shellcheck"
51+
52+
- name: Display shellcheck version
53+
shell: bash
54+
run: |
55+
"${{ github.action_path }}/shellcheck" --version
56+
2957
- name: Run ShellCheck
30-
if: steps.changes.outputs.files != ''
58+
if: steps.changed-files-specific.outputs.any_changed == 'true'
59+
env:
60+
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
3161
run: |
32-
echo "${{ steps.changes.outputs.files }}" | xargs shellcheck
62+
echo "${ALL_CHANGED_FILES}" | xargs shellcheck

0 commit comments

Comments
 (0)