|
1 | | -#/bin/bash |
2 | | -ARGS="" |
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Enable recursive globbing for ** patterns |
| 5 | +shopt -s globstar nullglob |
3 | 6 |
|
| 7 | +ARGS="" |
4 | 8 | [[ $INPUT_FAIL_ON_WARN == "true" ]] && ARGS+=" --fail-on-warn" |
5 | 9 |
|
6 | | -/zed validate $ARGS $INPUT_VALIDATIONFILE |
| 10 | +# Collect all files to validate |
| 11 | +FILES=() |
| 12 | +HAD_INPUT=0 |
| 13 | + |
| 14 | +# Handle single file input (backward compatibility) |
| 15 | +if [[ -n "$INPUT_VALIDATIONFILE" ]]; then |
| 16 | + HAD_INPUT=1 |
| 17 | + FILES+=("$INPUT_VALIDATIONFILE") |
| 18 | +fi |
| 19 | + |
| 20 | +# Handle multiple files input |
| 21 | +if [[ -n "$INPUT_VALIDATIONFILES" ]]; then |
| 22 | + HAD_INPUT=1 |
| 23 | + # Replace commas with newlines and process each entry |
| 24 | + # Use printf instead of echo to avoid option interpretation |
| 25 | + while IFS= read -r entry; do |
| 26 | + # Trim leading/trailing whitespace without breaking spaces in paths |
| 27 | + entry="${entry#"${entry%%[![:space:]]*}"}" |
| 28 | + entry="${entry%"${entry##*[![:space:]]}"}" |
| 29 | + [[ -z "$entry" ]] && continue |
| 30 | + |
| 31 | + # Check if entry contains glob pattern characters |
| 32 | + if [[ "$entry" == *"*"* || "$entry" == *"?"* || "$entry" == *"["* ]]; then |
| 33 | + # Expand glob pattern safely without eval (globstar enabled for ** support) |
| 34 | + # Use an array assignment for safe glob expansion |
| 35 | + expanded=() |
| 36 | + # shellcheck disable=SC2206 |
| 37 | + expanded=($entry) |
| 38 | + for file in "${expanded[@]}"; do |
| 39 | + [[ -f "$file" ]] && FILES+=("$file") |
| 40 | + done |
| 41 | + else |
| 42 | + FILES+=("$entry") |
| 43 | + fi |
| 44 | + done <<< "$(printf '%s\n' "$INPUT_VALIDATIONFILES" | tr ',' '\n')" |
| 45 | +fi |
| 46 | + |
| 47 | +# Check if we have any files to validate |
| 48 | +if [[ $HAD_INPUT -eq 0 ]]; then |
| 49 | + echo "Error: No validation files provided. Set either 'validationfile' or 'validationfiles' input." |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +if [[ ${#FILES[@]} -eq 0 ]]; then |
| 54 | + echo "Error: No files matched the provided patterns." |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +# Validate each file |
| 59 | +FAILED=0 |
| 60 | +for file in "${FILES[@]}"; do |
| 61 | + echo "Validating $file..." |
| 62 | + # ARGS is intentionally unquoted for word splitting (may be empty or --fail-on-warn) |
| 63 | + # shellcheck disable=SC2086 |
| 64 | + if ! /zed validate $ARGS "$file"; then |
| 65 | + FAILED=1 |
| 66 | + fi |
| 67 | +done |
| 68 | + |
| 69 | +exit $FAILED |
0 commit comments