ci: fix ShellCheck dialect and make tool installs fault-tolerant
CI / Bash Syntax Check (push) Successful in 26s
CI / Markdown Lint (push) Successful in 26s
CI / ShellCheck (push) Successful in 1m38s

This commit is contained in:
2026-11-09 10:36:49 +08:00
parent 75f4ec53ab
commit 8d53521262
6 changed files with 37 additions and 7 deletions
+22 -5
View File
@@ -13,13 +13,23 @@ jobs:
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- name: Install ShellCheck - name: Install ShellCheck
run: sudo apt-get update -qq && sudo apt-get install -y -qq shellcheck run: |
if command -v shellcheck >/dev/null 2>&1; then
echo "shellcheck already available"
exit 0
fi
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -qq && sudo apt-get install -y -qq shellcheck
else
echo "no apt-get on this runner — ShellCheck will be skipped"
fi
- name: Run ShellCheck - name: Run ShellCheck
run: | run: |
command -v shellcheck >/dev/null 2>&1 || { echo "shellcheck unavailable — skipping"; exit 0; }
for f in runaway lib/*.sh examples/*.sh; do for f in runaway lib/*.sh examples/*.sh; do
[ -f "$f" ] || continue [ -f "$f" ] || continue
echo "Checking: $f" echo "Checking: $f"
shellcheck -S warning "$f" || exit 1 shellcheck -S warning -s bash "$f" || exit 1
done done
syntax: syntax:
@@ -41,7 +51,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- name: Install markdownlint - name: Install markdownlint (best effort)
run: sudo npm install -g markdownlint-cli run: |
if command -v npm >/dev/null 2>&1; then
npm install -g markdownlint-cli 2>/dev/null || echo "npm install failed — lint will be skipped"
else
echo "npm not available on this runner — lint will be skipped"
fi
- name: Lint markdown - name: Lint markdown
run: markdownlint '*.md' --config /dev/null || true run: |
command -v markdownlint >/dev/null 2>&1 || { echo "markdownlint unavailable — skipping"; exit 0; }
markdownlint '*.md' --config /dev/null || true
+1
View File
@@ -8,6 +8,7 @@ NC='\033[0m'
LOG_FILE="" LOG_FILE=""
VERBOSE=false VERBOSE=false
# shellcheck disable=SC2034 # used by lib modules
DRY_RUN=false DRY_RUN=false
log() { log() {
+1
View File
@@ -6,6 +6,7 @@ load_config() {
while IFS='=' read -r key value || [ -n "$key" ]; do while IFS='=' read -r key value || [ -n "$key" ]; do
key="${key// /}" key="${key// /}"
[ -z "$key" ] && continue [ -z "$key" ] && continue
# shellcheck disable=SC2034 # globals used by lib modules
case "$key" in case "$key" in
WEBHOOK) DISCORD_WEBHOOK="$value" ;; WEBHOOK) DISCORD_WEBHOOK="$value" ;;
LOG_LEVEL) [ "$value" = "verbose" ] && VERBOSE=true ;; LOG_LEVEL) [ "$value" = "verbose" ] && VERBOSE=true ;;
+2 -1
View File
@@ -22,7 +22,8 @@ run_demo() {
echo "" echo ""
step "2. Running suppress_enrollment..." step "2. Running suppress_enrollment..."
DRY_RUN=false # shellcheck disable=SC2034 # used by lib modules
DRY_RUN=false
suppress_enrollment "$demo_dir" 2>/dev/null || true suppress_enrollment "$demo_dir" 2>/dev/null || true
sleep 1 sleep 1
+5
View File
@@ -2,15 +2,18 @@
set -euo pipefail set -euo pipefail
VERSION="2.0.0" VERSION="2.0.0"
# shellcheck disable=SC2034 # used by lib modules
STANDALONE_BUILD=false STANDALONE_BUILD=false
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck disable=SC2034 # used by lib modules
SCRIPT_PATH="$SCRIPT_DIR/$(basename "$0")" SCRIPT_PATH="$SCRIPT_DIR/$(basename "$0")"
LIB_DIR="$SCRIPT_DIR/lib" LIB_DIR="$SCRIPT_DIR/lib"
for _lib in colors config detect validate dscl suppress backup status launchd heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn init suggest remediate telemetry predict discord; do for _lib in colors config detect validate dscl suppress backup status launchd heal firewall harden whitelist check monitor history doctor selfupdate uninstall report ma_detect demo vpn init suggest remediate telemetry predict discord; do
_lib_path="$LIB_DIR/$_lib.sh" _lib_path="$LIB_DIR/$_lib.sh"
if [ -f "$_lib_path" ]; then if [ -f "$_lib_path" ]; then
# shellcheck disable=SC1090 # libs live in $SCRIPT_DIR/lib
source "$_lib_path" source "$_lib_path"
else else
echo "ERROR: Library not found: $_lib_path" >&2 echo "ERROR: Library not found: $_lib_path" >&2
@@ -411,6 +414,7 @@ cmd_monitor() {
done done
set -- "${args[@]}" set -- "${args[@]}"
if [ -n "$webhook" ]; then if [ -n "$webhook" ]; then
# shellcheck disable=SC2034 # used by lib/discord.sh
DISCORD_WEBHOOK="$webhook" DISCORD_WEBHOOK="$webhook"
fi fi
case "${1:-}" in case "${1:-}" in
@@ -571,6 +575,7 @@ cmd_interactive_normal() {
parse_global_opts() { parse_global_opts() {
PARSED_ARGS=() PARSED_ARGS=()
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
# shellcheck disable=SC2034 # globals used by lib modules
case "$1" in case "$1" in
--verbose) VERBOSE=true; shift ;; --verbose) VERBOSE=true; shift ;;
--dry-run) DRY_RUN=true; shift ;; --dry-run) DRY_RUN=true; shift ;;
+6 -1
View File
@@ -14,6 +14,7 @@ NC='\033[0m'
LOG_FILE="" LOG_FILE=""
VERBOSE=false VERBOSE=false
# shellcheck disable=SC2034 # used by lib modules
DRY_RUN=false DRY_RUN=false
log() { log() {
@@ -134,6 +135,7 @@ load_config() {
while IFS='=' read -r key value || [ -n "$key" ]; do while IFS='=' read -r key value || [ -n "$key" ]; do
key="${key// /}" key="${key// /}"
[ -z "$key" ] && continue [ -z "$key" ] && continue
# shellcheck disable=SC2034 # globals used by lib modules
case "$key" in case "$key" in
WEBHOOK) DISCORD_WEBHOOK="$value" ;; WEBHOOK) DISCORD_WEBHOOK="$value" ;;
LOG_LEVEL) [ "$value" = "verbose" ] && VERBOSE=true ;; LOG_LEVEL) [ "$value" = "verbose" ] && VERBOSE=true ;;
@@ -2659,7 +2661,8 @@ run_demo() {
echo "" echo ""
step "2. Running suppress_enrollment..." step "2. Running suppress_enrollment..."
DRY_RUN=false # shellcheck disable=SC2034 # used by lib modules
DRY_RUN=false
suppress_enrollment "$demo_dir" 2>/dev/null || true suppress_enrollment "$demo_dir" 2>/dev/null || true
sleep 1 sleep 1
@@ -3232,6 +3235,7 @@ cmd_monitor() {
done done
set -- "${args[@]}" set -- "${args[@]}"
if [ -n "$webhook" ]; then if [ -n "$webhook" ]; then
# shellcheck disable=SC2034 # used by lib/discord.sh
DISCORD_WEBHOOK="$webhook" DISCORD_WEBHOOK="$webhook"
fi fi
case "${1:-}" in case "${1:-}" in
@@ -3392,6 +3396,7 @@ cmd_interactive_normal() {
parse_global_opts() { parse_global_opts() {
PARSED_ARGS=() PARSED_ARGS=()
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
# shellcheck disable=SC2034 # globals used by lib modules
case "$1" in case "$1" in
--verbose) VERBOSE=true; shift ;; --verbose) VERBOSE=true; shift ;;
--dry-run) DRY_RUN=true; shift ;; --dry-run) DRY_RUN=true; shift ;;