Skip to content

Commit 3c539c2

Browse files
committed
ci: fix ShellCheck workflow to run correctly on PRs and main
- Updated to properly differentiate between PRs and direct pushes to - On pull_request: only runs ShellCheck on changed files to avoid false positives from main - On push to main and manual dispatch: runs ShellCheck on all files in the repository - Ensures accurate and relevant linting results on both CI and developer PRs - Fixes issue where shellcheck errors from main were incorrectly reported on unrelated PRs Signed-off-by: Srikanth Muppandam <[email protected]>
1 parent 0d12ca5 commit 3c539c2

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

.github/workflows/shellcheck.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Shell Lint
22

33
on:
4-
pull_request_target:
4+
pull_request:
55
branches: [ "main" ]
66
push:
77
branches: [ "main" ]
@@ -10,10 +10,30 @@ on:
1010
jobs:
1111
shellcheck:
1212
runs-on: ubuntu-latest
13+
1314
steps:
14-
- uses: actions/checkout@v3
15-
- name: Install ShellCheck 0.9.0-1
16-
run: sudo apt-get install -y shellcheck=0.9.0-1
17-
- name: Run ShellCheck with exclusions
15+
- name: Checkout source
16+
uses: actions/checkout@v3
17+
18+
- name: Install ShellCheck from apt
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y shellcheck=0.9.0-1
22+
23+
- name: Run ShellCheck on changed .sh files in PR
24+
if: github.event_name == 'pull_request'
25+
run: |
26+
echo "Checking only changed shell files in PR..."
27+
git fetch origin ${{ github.base_ref }}
28+
FILES=$(git diff --name-only origin/${{ github.base_ref }} -- '*.sh' | xargs -r -n1 echo | xargs -r realpath --no-symlinks --canonicalize-missing 2>/dev/null || true)
29+
if [ -n "$FILES" ]; then
30+
echo "$FILES" | tr ' ' '\n' | xargs -r shellcheck -S warning -e SC1091,SC2230,SC3043
31+
else
32+
echo "No shell files to lint."
33+
fi
34+
35+
- name: Run ShellCheck on all .sh files (main or manual trigger)
36+
if: github.event_name != 'pull_request'
1837
run: |
19-
find . -name '*.sh' -print0 | xargs -0 shellcheck -S warning -e SC1091,SC2230,SC3043
38+
echo "Linting all shell files in repository..."
39+
find . -type f -name '*.sh' -print0 | xargs -0 -r shellcheck -S warning -e SC1091,SC2230,SC3043

0 commit comments

Comments
 (0)