1+ # Copyright (c) 2025, NVIDIA CORPORATION.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ name : ' Shell Check'
16+ description : ' Check shell syntax'
17+ inputs :
18+ excluded_codes :
19+ description : " Excluded issue codes (comma-separated). e.g. SC2086,SC2046"
20+ required : false
21+ type : string
22+ default : " "
23+
24+ runs :
25+ using : " composite"
26+ steps :
27+ - name : Configure ShellCheck Options
28+ shell : bash
29+ run : |
30+ base_excludes=(
31+ # Double quote to prevent globbing and word splitting.
32+ "SC2086"
33+ # Quote this to prevent word splitting.
34+ "SC2046"
35+ # Declare and assign separately to avoid masking return values.
36+ "SC2155"
37+ # Use $(...) notation instead of legacy backticks `...`.
38+ "SC2006"
39+ # Variable referenced but not assigned
40+ "SC2154"
41+ # Ranges can only match single chars (mentioned due to duplicates).
42+ "SC2102"
43+ # Prefer mapfile or read -a to split command output (or quote to avoid splitting).
44+ "SC2207"
45+ # Note that A && B || C is not if-then-else. C may run when A is true.
46+ "SC2015"
47+ # Argument mixes string and array. Use * or separate argument.
48+ "SC2145"
49+ # Variable appears unused. Verify use (or export if used externally).
50+ "SC2034"
51+ # Not following: File was not specified as input (see shellcheck -x).
52+ "SC1091"
53+ # Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
54+ "SC2010"
55+ # This does not export 'VAR'. Remove $/${} for that, or use ${var?} to quiet.
56+ "SC2163"
57+ # See if you can use ${variable//search/replace} instead.
58+ "SC2001"
59+ # Use find instead of ls to better handle non-alphanumeric filenames.
60+ "SC2012"
61+ # Expressions don't expand in single quotes, use double quotes for that.
62+ "SC2016"
63+ )
64+ final_excludes=("${base_excludes[@]}")
65+ if [ -n "${{ inputs.excluded_codes }}" ]; then
66+ IFS=',' read -r -a user_excludes <<< "${{ inputs.excluded_codes }}"
67+ final_excludes+=("${user_excludes[@]}")
68+ fi
69+ SHELLCHECK_OPTS=""
70+ for code in "${final_excludes[@]}"; do
71+ SHELLCHECK_OPTS+=" -e $code"
72+ done
73+
74+ SHELLCHECK_OPTS="${SHELLCHECK_OPTS# }"
75+
76+ echo "SHELLCHECK_OPTS=$SHELLCHECK_OPTS" >> $GITHUB_ENV
77+ env :
78+ GITHUB_ENV : ${{ github.env_path }}
79+
80+ - name : Run ShellCheck
81+ uses : ludeeus/action-shellcheck@master
82+ env :
83+ SHELLCHECK_OPTS : ${{ env.SHELLCHECK_OPTS }}
84+
0 commit comments