Skip to content

Commit d1589c5

Browse files
committedDec 19, 2024
Fix issues reported by 'shellcheck'
This helps to address issue shader-slang#5520.

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed
 

‎.github/workflows/ci-examples.sh

+37-40
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Skip file:
3434
EOF
3535
}
3636

37+
function user_error() {
38+
echo "error: $1" >&2
39+
echo "" >&2
40+
show_help >&2
41+
exit 1
42+
}
43+
3744
while [[ "$#" -gt 0 ]]; do
3845
case $1 in
3946
-h | --help)
@@ -55,9 +62,7 @@ while [[ "$#" -gt 0 ]]; do
5562
case $2 in
5663
windows | linux | macos) ;;
5764
*)
58-
printf "error: Unrecognized os: '$2'\n\n" >&2
59-
show_help >&2
60-
exit 1
65+
user_error "Unrecognized os: '$2'"
6166
;;
6267
esac
6368
os="$2"
@@ -67,56 +72,44 @@ while [[ "$#" -gt 0 ]]; do
6772
case $2 in
6873
debug | release) ;;
6974
*)
70-
printf "error: Unrecognized config: '$2'\n\n" >&2
71-
show_help >&2
72-
exit 1
75+
user_error "Unrecognized config: '$2'"
7376
;;
7477
esac
7578
config="$2"
7679
shift
7780
;;
7881
*)
79-
echo "unrecognized argument: $1" >&2
80-
show_help >&2
81-
exit 1
82+
user_error "Unrecognized argument: '$1'"
8283
;;
8384
esac
8485
shift
8586
done
8687

8788
if [[ "$os" == "" ]]; then
88-
echo "error: No OS specified.\n\n"
89-
show_help >&2
90-
exit 1
89+
user_error "No OS specified."
9190
fi
9291

9392
if [[ "$config" == "" ]]; then
94-
printf "error: No build configuration specified.\n\n" >&2
95-
show_help >&2
96-
exit 1
93+
user_error "No build configuration specified."
9794
fi
9895

9996
if [[ "$bin_dir" == "" ]]; then
100-
printf "error: No binary directory specified.\n\n" >&2
101-
show_help >&2
102-
exit 1
97+
user_error "No binary directory specified."
10398
fi
10499

105100
if [[ "$skip_file" == "" ]]; then
106-
printf "error: No skip file specified.\n\n" >&2
107-
show_help >&2
108-
exit 1
101+
user_error "No skip file specified."
109102
fi
110103

111104
if [[ ! -f "$skip_file" ]]; then
112-
printf "error: Skip file '$skip_file' does not exist.\n\n" >&2
105+
user_error "Skip file '$skip_file' does not exist."
113106
fi
114107

115108
if [[ ! -d "$bin_dir" ]]; then
116-
printf "error: Binary directory '$bin_dir' does not exist.\n\n" >&2
109+
user_error "Binary directory '$bin_dir' does not exist."
117110
fi
118111

119-
summary=""
112+
summary=()
120113
failure_count=0
121114
skip_count=0
122115
sample_count=0
@@ -126,46 +119,45 @@ function skip {
126119
local line_index
127120
p="$1"
128121
line_index=1
129-
while read pattern; do
122+
while read -r pattern; do
130123
pat=$pattern
131124
if [[ ! $pat =~ .*# ]]; then
132-
echo "error: Skip pattern on line $line_index is missing a comment!"
133-
exit 1
125+
user_error "Skip pattern on line $line_index is missing a comment!"
134126
fi
135127
pat="${pattern%% *#*}"
136128
if [[ $p =~ ^$pat$ ]]; then
137129
return 0
138130
fi
139131
line_index=$((line_index + 1))
140-
done <$skip_file
132+
done <"$skip_file"
141133

142134
return 1
143135
}
144136

145137
function run_sample {
146-
local command
147138
local sample
148-
command=$@
139+
local args
140+
sample="$1"
149141
shift
150-
sample="${command%% *}"
142+
args=( "$@" )
151143
sample_count=$((sample_count + 1))
152-
summary+="$sample: "
144+
summary=("${summary[@]}" "$sample: ")
153145
if skip "$os:$config:$sample"; then
154146
echo "Skipping $sample..."
155-
summary+="\n skipped\n"
147+
summary=("${summary[@]}" " skipped")
156148
skip_count=$((skip_count + 1))
157149
return
158150
fi
159-
echo "Running '$command'..."
151+
echo "Running '$sample ${args[*]}'..."
160152
result=0
161-
pushd $bin_dir 1>/dev/null 2>&1
153+
pushd "$bin_dir" 1>/dev/null 2>&1
162154
if [[ ! "$dry_run" = true ]]; then
163-
./$command || result=$?
155+
./"$sample" "${args[@]}" || result=$?
164156
fi
165157
if [[ $result -eq 0 ]]; then
166-
summary+="\n success\n"
158+
summary=("${summary[@]}" " success")
167159
else
168-
summary+="\n failure (exit code: $result)\n"
160+
summary=("${summary[@]}" " failure (exit code: $result)")
169161
failure_count=$((failure_count + 1))
170162
fi
171163
popd 1>/dev/null 2>&1
@@ -187,13 +179,18 @@ sample_commands=(
187179
)
188180

189181
for sample_command in "${sample_commands[@]}"; do
190-
run_sample $sample_command
182+
run_sample ${sample_command}
191183
echo ""
192184
done
193185

194186
echo ""
195187
echo "Summary: "
196-
printf "\n$summary\n\n"
188+
echo
189+
for line in "${summary[@]}"
190+
do
191+
printf ' %s\n' "$line"
192+
done
193+
echo ""
197194
echo "$failure_count failed, and $skip_count skipped, out of $sample_count tests"
198195
if [[ $failure_count -ne 0 ]]; then
199196
exit 1

0 commit comments

Comments
 (0)
Please sign in to comment.