Skip to content

Commit

Permalink
Linting fixes for ci-examples.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
aleino-nv committed Dec 18, 2024
1 parent 41c627f commit 5b2bd3a
Showing 1 changed file with 45 additions and 29 deletions.
74 changes: 45 additions & 29 deletions .github/workflows/ci-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ while [[ "$#" -gt 0 ]]; do
case $2 in
windows | linux | macos) ;;
*)
printf "error: Unrecognized os: '$2'\n\n" >&2
echo "error: Unrecognized os: '$2'" >&2
echo "" >&2
show_help >&2
exit 1
;;
Expand All @@ -67,7 +68,8 @@ while [[ "$#" -gt 0 ]]; do
case $2 in
debug | release) ;;
*)
printf "error: Unrecognized config: '$2'\n\n" >&2
echo "error: Unrecognized config: '$2'" >&2
echo "" >&2
show_help >&2
exit 1
;;
Expand All @@ -77,6 +79,7 @@ while [[ "$#" -gt 0 ]]; do
;;
*)
echo "unrecognized argument: $1" >&2
echo "" >&2
show_help >&2
exit 1
;;
Expand All @@ -85,38 +88,46 @@ while [[ "$#" -gt 0 ]]; do
done

if [[ "$os" == "" ]]; then
echo "error: No OS specified.\n\n"
echo "error: No OS specified."
echo "" >&2
show_help >&2
exit 1
fi

if [[ "$config" == "" ]]; then
printf "error: No build configuration specified.\n\n" >&2
echo "error: No build configuration specified." >&2
echo "" >&2
show_help >&2
exit 1
fi

if [[ "$bin_dir" == "" ]]; then
printf "error: No binary directory specified.\n\n" >&2
echo "error: No binary directory specified." >&2
echo "" >&2
show_help >&2
exit 1
fi

if [[ "$skip_file" == "" ]]; then
printf "error: No skip file specified.\n\n" >&2
echo "error: No skip file specified." >&2
echo "" >&2
show_help >&2
exit 1
fi

if [[ ! -f "$skip_file" ]]; then
printf "error: Skip file '$skip_file' does not exist.\n\n" >&2
echo "error: Skip file '$skip_file' does not exist." >&2
echo "" >&2
exit 1
fi

if [[ ! -d "$bin_dir" ]]; then
printf "error: Binary directory '$bin_dir' does not exist.\n\n" >&2
echo "error: Binary directory '$bin_dir' does not exist." >&2
echo "" >&2
exit 1
fi

summary=""
summary=()
failure_count=0
skip_count=0
sample_count=0
Expand All @@ -126,7 +137,7 @@ function skip {
local line_index
p="$1"
line_index=1
while read pattern; do
while read -r pattern; do
pat=$pattern
if [[ ! $pat =~ .*# ]]; then
echo "error: Skip pattern on line $line_index is missing a comment!"
Expand All @@ -137,7 +148,7 @@ function skip {
return 0
fi
line_index=$((line_index + 1))
done <$skip_file
done <"$skip_file"

return 1
}
Expand All @@ -147,53 +158,58 @@ function run_sample {
local sample
command=$@
shift
sample="${command%% *}"
sample="${command[0]}"
sample_count=$((sample_count + 1))
summary+="$sample: "
summary=("${summary[@]}" "$sample: ")
if skip "$os:$config:$sample"; then
echo "Skipping $sample..."
summary+="\n skipped\n"
summary=("${summary[@]}" " skipped")
skip_count=$((skip_count + 1))
return
fi
echo "Running '$command'..."
echo "Running '${command[@]}'..."
result=0
pushd $bin_dir 1>/dev/null 2>&1
pushd "$bin_dir" 1>/dev/null 2>&1
if [[ ! "$dry_run" = true ]]; then
./$command || result=$?
./${command[@]} || result=$?
fi
if [[ $result -eq 0 ]]; then
summary+="\n success\n"
summary=("${summary[@]}" " success")
else
summary+="\n failure (exit code: $result)\n"
summary=("${summary[@]}" " failure (exit code: $result)")
failure_count=$((failure_count + 1))
fi
popd 1>/dev/null 2>&1
}

sample_commands=(
'cpu-com-example'
'cpu-hello-world'
'gpu-printing'
'hello-world'
'model-viewer --test-mode'
'platform-test --test-mode'
'ray-tracing-pipeline --test-mode'
'ray-tracing --test-mode'
'ray-tracing-pipeline --test-mode'
'reflection-api'
'shader-object'
'shader-toy --test-mode'
'triangle --test-mode'
'model-viewer --test-mode'
'shader-object'
'reflection-api'
'hello-world'
'gpu-printing'
'cpu-hello-world'
'cpu-com-example'
)

for sample_command in "${sample_commands[@]}"; do
run_sample $sample_command
run_sample "$sample_command"
echo ""
done

echo ""

echo "Summary: "
printf "\n$summary\n\n"
echo ""
for line in "${summary[@]}"
do
echo " $line"
done
echo "$failure_count failed, and $skip_count skipped, out of $sample_count tests"
if [[ $failure_count -ne 0 ]]; then
exit 1
Expand Down

0 comments on commit 5b2bd3a

Please sign in to comment.