forked from qualcomm-linux/qcom-linux-testkit
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (120 loc) · 4.04 KB
/
shellcheck.yml
File metadata and controls
155 lines (120 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Shell Lint
on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
shellcheck:
runs-on: ubuntu-latest
defaults:
run:
shell: sh
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install ShellCheck from apt
run: |
sudo apt-get update
sudo apt-get install -y shellcheck=0.9.0-1
shellcheck --version
- name: Run ShellCheck on changed .sh files in PR
if: github.event_name == 'pull_request'
env:
BASE_BRANCH: ${{ github.base_ref }}
run: |
set -eu
if [ -z "$BASE_BRANCH" ]; then
echo "BASE_BRANCH is empty"
exit 1
fi
if ! git check-ref-format --branch "$BASE_BRANCH" >/dev/null 2>&1; then
echo "Invalid base branch name: $BASE_BRANCH"
exit 1
fi
git fetch --no-tags origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}"
MERGE_BASE="$(git merge-base HEAD "refs/remotes/origin/${BASE_BRANCH}")"
files_list="$(mktemp)"
trap 'rm -f "$files_list"' EXIT
git diff --diff-filter=d --name-only -z "${MERGE_BASE}"...HEAD -- '*.sh' > "$files_list"
if [ ! -s "$files_list" ]; then
echo "No shell files to lint."
exit 0
fi
echo "Checking changed shell files:"
tr '\0' '\n' < "$files_list"
xargs -0 -r sh -c '
is_functestlib() {
lint_file_path="$1"
case "$lint_file_path" in
./Runner/utils/functestlib.sh|Runner/utils/functestlib.sh)
return 0
;;
esac
return 1
}
run_shellcheck() {
lint_file_path="$1"
base_excludes="SC1091,SC2230,SC3043"
lint_excludes="$base_excludes"
if is_functestlib "$lint_file_path"; then
lint_excludes="${base_excludes},SC2317"
echo "ShellCheck functestlib mode: $lint_file_path"
else
echo "ShellCheck strict mode: $lint_file_path"
fi
shellcheck -s sh -e "$lint_excludes" -- "$lint_file_path"
}
rc=0
for lint_file_path do
if ! run_shellcheck "$lint_file_path"; then
rc=1
fi
done
exit "$rc"
' sh < "$files_list"
- name: Run ShellCheck on all .sh files (push/manual)
if: github.event_name != 'pull_request'
run: |
set -eu
files_list="$(mktemp)"
trap 'rm -f "$files_list"' EXIT
echo "Linting all shell files in repository..."
find . -type f -name '*.sh' -print0 > "$files_list"
if [ ! -s "$files_list" ]; then
echo "No shell files to lint."
exit 0
fi
xargs -0 -r sh -c '
is_functestlib() {
lint_file_path="$1"
case "$lint_file_path" in
./Runner/utils/functestlib.sh|Runner/utils/functestlib.sh)
return 0
;;
esac
return 1
}
run_shellcheck() {
lint_file_path="$1"
base_excludes="SC1091,SC2230,SC3043"
lint_excludes="$base_excludes"
if is_functestlib "$lint_file_path"; then
lint_excludes="${base_excludes},SC2317"
echo "ShellCheck functestlib mode: $lint_file_path"
else
echo "ShellCheck strict mode: $lint_file_path"
fi
shellcheck -s sh -e "$lint_excludes" -- "$lint_file_path"
}
rc=0
for lint_file_path do
if ! run_shellcheck "$lint_file_path"; then
rc=1
fi
done
exit "$rc"
' sh < "$files_list"