Skip to content

Commit 514c437

Browse files
ci: add shellcheck linter for ci scripts (#7331)
## Summary Adds [shellcheck](https://www.shellcheck.net/) to the PR linting CI steps -- when a PR has changed a `*.sh` file. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7331-ci-add-shellcheck-linter-for-ci-scripts-2c66d73d365081be889bf256cde92281) by [Unito](https://www.unito.io)
1 parent 18b133d commit 514c437

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Description: Runs shellcheck on tracked shell scripts when they change
2+
name: "CI: Shell Validation"
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- '**/*.sh'
10+
pull_request:
11+
paths:
12+
- '**/*.sh'
13+
14+
jobs:
15+
shell-lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- name: Install shellcheck
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y shellcheck
24+
25+
- name: Run shellcheck
26+
run: bash ./scripts/cicd/check-shell.sh

scripts/cicd/check-shell.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(git rev-parse --show-toplevel)"
5+
cd "$ROOT_DIR"
6+
7+
if ! command -v shellcheck >/dev/null 2>&1; then
8+
echo "Error: shellcheck is required but not installed" >&2
9+
exit 127
10+
fi
11+
12+
mapfile -t shell_files < <(git ls-files -- '*.sh')
13+
14+
if [[ ${#shell_files[@]} -eq 0 ]]; then
15+
echo 'No shell scripts found.'
16+
exit 0
17+
fi
18+
19+
shellcheck --format=gcc "${shell_files[@]}"

scripts/cicd/pr-playwright-deploy-and-comment.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ deploy_report() {
7474

7575

7676
# Project name with dots converted to dashes for Cloudflare
77-
sanitized_browser=$(echo "$browser" | sed 's/\./-/g')
77+
sanitized_browser="${browser//./-}"
7878
project="comfyui-playwright-${sanitized_browser}"
7979

8080
echo "Deploying $browser to project $project on branch $branch..." >&2
@@ -208,7 +208,7 @@ else
208208

209209
# Wait for all deployments to complete
210210
for pid in $pids; do
211-
wait $pid
211+
wait "$pid"
212212
done
213213

214214
# Collect URLs and counts in order
@@ -254,9 +254,9 @@ else
254254
total_tests=0
255255

256256
# Parse counts and calculate totals
257-
IFS='|'
258-
set -- $all_counts
259-
for counts_json; do
257+
IFS='|' read -r -a counts_array <<< "$all_counts"
258+
for counts_json in "${counts_array[@]}"; do
259+
[ -z "$counts_json" ] && continue
260260
if [ "$counts_json" != "{}" ] && [ -n "$counts_json" ]; then
261261
# Parse JSON counts using simple grep/sed if jq is not available
262262
if command -v jq > /dev/null 2>&1; then
@@ -324,13 +324,12 @@ $status_icon **$status_text**
324324

325325
# Add browser results with individual counts
326326
i=0
327-
IFS='|'
328-
set -- $all_counts
329-
for counts_json; do
330-
# Get browser name
331-
browser=$(echo "$BROWSERS" | cut -d' ' -f$((i + 1)))
332-
# Get URL at position i
333-
url=$(echo "$urls" | cut -d' ' -f$((i + 1)))
327+
IFS=' ' read -r -a browser_array <<< "$BROWSERS"
328+
IFS=' ' read -r -a url_array <<< "$urls"
329+
for counts_json in "${counts_array[@]}"; do
330+
[ -z "$counts_json" ] && { i=$((i + 1)); continue; }
331+
browser="${browser_array[$i]:-}"
332+
url="${url_array[$i]:-}"
334333

335334
if [ "$url" != "failed" ] && [ -n "$url" ]; then
336335
# Parse individual browser counts
@@ -374,4 +373,4 @@ $status_icon **$status_text**
374373
🎉 Click on the links above to view detailed test results for each browser configuration."
375374

376375
post_comment "$comment"
377-
fi
376+
fi

0 commit comments

Comments
 (0)