Skip to content

Commit 8be147f

Browse files
committed
Add linting help scripts
Signed-off-by: ddimatos <dimatos@gmail.com>
1 parent 23e9cad commit 8be147f

2 files changed

Lines changed: 420 additions & 0 deletions

File tree

scripts/lint-all.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
# ############################################################################
3+
# Copyright IBM Corporation 2026
4+
#
5+
# lint-all.sh — Local equivalent of the ansible-lint GitHub Actions workflow.
6+
# Mirrors: .github/workflows/ansible-lint.yml
7+
#
8+
# Compatible with bash 3.2+ (macOS default shell).
9+
#
10+
# Usage:
11+
# bash scripts/lint-all.sh [output-file]
12+
#
13+
# output-file Optional path. When supplied, all stdout and stderr from this
14+
# script is written to that file (and the parent directory is
15+
# created if it does not exist). The console still shows
16+
# progress when a tty is attached; pass /dev/null to suppress.
17+
#
18+
# Examples:
19+
# bash scripts/lint-all.sh # output to terminal only
20+
# bash scripts/lint-all.sh /tmp/lint-all.txt # output to file only
21+
# bash scripts/lint-all.sh /logs/ci/lint.log # parent dir created if needed
22+
#
23+
# Prerequisites:
24+
# pip install ansible-lint
25+
# ansible-galaxy collection install -r collections/requirements.yml
26+
# ############################################################################
27+
28+
set -uo pipefail
29+
30+
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
31+
export ANSIBLE_LIBRARY="${REPO_DIR}/zos_subsystems/ims/ims_provisioning/library"
32+
33+
# ── optional output file ──────────────────────────────────────────────────────
34+
if [ "${1:-}" != "" ]; then
35+
OUTPUT_FILE="$1"
36+
# Create parent directory if it does not exist
37+
OUTPUT_DIR="$(dirname "$OUTPUT_FILE")"
38+
[ -d "$OUTPUT_DIR" ] || mkdir -p "$OUTPUT_DIR"
39+
# Redirect both stdout and stderr of the entire script to the file
40+
exec > "$OUTPUT_FILE" 2>&1
41+
fi
42+
43+
# ── run lint across every top-level directory ─────────────────────────────────
44+
failed="" # space-separated list of failed dir paths (no arrays needed)
45+
46+
for dir in "${REPO_DIR}"/*/; do
47+
[ -d "$dir" ] || continue
48+
49+
echo ""
50+
echo "==============================================="
51+
echo " Entering: $dir"
52+
echo "==============================================="
53+
echo ""
54+
55+
set +e
56+
(cd "$dir" && ansible-lint *)
57+
exit_code=$?
58+
set -e
59+
60+
if [ $exit_code -eq 0 ]; then
61+
echo "[PASS] $dir"
62+
else
63+
echo "[FAIL] $dir"
64+
failed="${failed} ${dir}"
65+
fi
66+
done
67+
68+
# ── summary ───────────────────────────────────────────────────────────────────
69+
if [ -n "$failed" ]; then
70+
echo ""
71+
echo "The following directories failed:"
72+
for d in $failed; do
73+
echo " - $d"
74+
done
75+
exit 1
76+
fi
77+
78+
echo ""
79+
echo "All directories passed."

0 commit comments

Comments
 (0)