Skip to content

Commit 940fc53

Browse files
authored
Merge pull request #335 from smuppand/shell-lint-workflow
ci(shelllint): align PR linting with local ShellCheck runs
2 parents 63b49be + b663174 commit 940fc53

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

.github/workflows/shellcheck.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,44 @@ jobs:
1111
shellcheck:
1212
runs-on: ubuntu-latest
1313

14+
defaults:
15+
run:
16+
shell: sh
17+
1418
steps:
1519
- name: Checkout source
16-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
1723

1824
- name: Install ShellCheck from apt
1925
run: |
2026
sudo apt-get update
2127
sudo apt-get install -y shellcheck=0.9.0-1
28+
shellcheck --version
2229
2330
- name: Run ShellCheck on changed .sh files in PR
2431
if: github.event_name == 'pull_request'
2532
run: |
26-
echo "Checking only changed shell files in PR..."
27-
git fetch origin ${{ github.base_ref }}
28-
FILES=$(git diff --diff-filter=d --name-only origin/${{ github.base_ref }} -- '*.sh')
33+
set -eu
34+
35+
BASE_BRANCH="${{ github.base_ref }}"
36+
git fetch origin "${BASE_BRANCH}" --depth=1
37+
38+
MERGE_BASE="$(git merge-base HEAD "origin/${BASE_BRANCH}")"
39+
FILES="$(git diff --diff-filter=d --name-only "${MERGE_BASE}"...HEAD -- '*.sh')"
40+
2941
if [ -n "$FILES" ]; then
30-
echo "$FILES" | tr '\n' '\0' | xargs -0 -r shellcheck -S warning -e SC1091,SC2230,SC3043
42+
echo "Checking changed shell files:"
43+
printf '%s\n' "$FILES"
44+
printf '%s\n' "$FILES" | tr '\n' '\0' | xargs -0 -r shellcheck -s sh -e SC1091,SC2230,SC3043
3145
else
3246
echo "No shell files to lint."
3347
fi
3448
35-
- name: Run ShellCheck on all .sh files (main or manual trigger)
49+
- name: Run ShellCheck on all .sh files (push/manual)
3650
if: github.event_name != 'pull_request'
3751
run: |
52+
set -eu
3853
echo "Linting all shell files in repository..."
39-
find . -type f -name '*.sh' -print0 | xargs -0 -r shellcheck -S warning -e SC1091,SC2230,SC3043
54+
find . -type f -name '*.sh' -print0 | xargs -0 -r shellcheck -s sh -e SC1091,SC2230,SC3043

0 commit comments

Comments
 (0)