Skip to content

Commit 60aa629

Browse files
authored
Merge pull request qualcomm-linux#116 from smuppand/shell-lint-workflow
ci: fix ShellCheck workflow to run correctly on PRs and main
2 parents 0d12ca5 + 3c539c2 commit 60aa629

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)