Improve /scripts/* with libraries, testing tools, and documentation #13
@@ -219,6 +219,38 @@ INFO: Smoke tests completed successfully
|
|||||||
INFO: =========================================
|
INFO: =========================================
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `validate_all.sh`
|
||||||
|
Runs all validation scripts and provides a comprehensive report:
|
||||||
|
- Executes all required validation checks
|
||||||
|
- Executes all optional validation checks
|
||||||
|
- Provides colored output with pass/fail indicators
|
||||||
|
- Returns summary with counts
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
```bash
|
||||||
|
./scripts/run/validate_all.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Example output:
|
||||||
|
```
|
||||||
|
=== Repository Validation Suite ===
|
||||||
|
INFO: Running all validation checks...
|
||||||
|
|
||||||
|
=== Required Checks ===
|
||||||
|
[SUCCESS] ✓ manifest
|
||||||
|
[SUCCESS] ✓ xml_wellformed
|
||||||
|
|
||||||
|
=== Optional Checks ===
|
||||||
|
[SUCCESS] ✓ no_secrets
|
||||||
|
[SUCCESS] ✓ php_syntax
|
||||||
|
WARN: ✗ tabs (warnings/issues found)
|
||||||
|
|
||||||
|
=== Validation Summary ===
|
||||||
|
Required checks passed: 2/2
|
||||||
|
Optional checks passed: 2/8
|
||||||
|
[SUCCESS] SUCCESS: All required checks passed
|
||||||
|
```
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
### Writing New Scripts
|
### Writing New Scripts
|
||||||
@@ -256,7 +288,12 @@ INFO: =========================================
|
|||||||
|
|
||||||
### Testing Scripts Locally
|
### Testing Scripts Locally
|
||||||
|
|
||||||
Run validation scripts before committing:
|
Run all validation scripts:
|
||||||
|
```bash
|
||||||
|
./scripts/run/validate_all.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Run individual validation scripts:
|
||||||
```bash
|
```bash
|
||||||
./scripts/validate/manifest.sh
|
./scripts/validate/manifest.sh
|
||||||
./scripts/validate/php_syntax.sh
|
./scripts/validate/php_syntax.sh
|
||||||
|
|||||||
@@ -35,8 +35,14 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Resolve script directory properly
|
# Resolve script directory properly - works when sourced
|
||||||
SCRIPT_LIB_DIR="$(cd "$(dirname "$0")" && pwd)"
|
if [ -n "${SCRIPT_DIR:-}" ]; then
|
||||||
|
# Already set by caller
|
||||||
|
SCRIPT_LIB_DIR="${SCRIPT_DIR}/lib"
|
||||||
|
else
|
||||||
|
# Determine from this file's location
|
||||||
|
SCRIPT_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Shared utilities
|
# Shared utilities
|
||||||
. "${SCRIPT_LIB_DIR}/common.sh"
|
. "${SCRIPT_LIB_DIR}/common.sh"
|
||||||
|
|||||||
141
scripts/run/validate_all.sh
Executable file
141
scripts/run/validate_all.sh
Executable file
@@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
||||||
|
#
|
||||||
|
# This file is part of a Moko Consulting project.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program (./LICENSE.md).
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# FILE INFORMATION
|
||||||
|
# ============================================================================
|
||||||
|
# DEFGROUP: Script.Run
|
||||||
|
# INGROUP: Repository.Validation
|
||||||
|
# REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
|
||||||
|
# PATH: /scripts/run/validate_all.sh
|
||||||
|
# VERSION: 01.00.00
|
||||||
|
# BRIEF: Run all validation scripts and report results
|
||||||
|
# NOTE: Helpful for developers to run all checks before committing
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
. "${SCRIPT_DIR}/lib/common.sh"
|
||||||
|
. "${SCRIPT_DIR}/lib/logging.sh"
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Configuration
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
REQUIRED_CHECKS=(
|
||||||
|
"manifest"
|
||||||
|
"xml_wellformed"
|
||||||
|
)
|
||||||
|
|
||||||
|
OPTIONAL_CHECKS=(
|
||||||
|
"changelog"
|
||||||
|
"language_structure"
|
||||||
|
"license_headers"
|
||||||
|
"no_secrets"
|
||||||
|
"paths"
|
||||||
|
"php_syntax"
|
||||||
|
"tabs"
|
||||||
|
"version_alignment"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Run validations
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
log_section "Repository Validation Suite"
|
||||||
|
log_info "Running all validation checks..."
|
||||||
|
log_separator
|
||||||
|
|
||||||
|
required_passed=0
|
||||||
|
required_failed=0
|
||||||
|
optional_passed=0
|
||||||
|
optional_failed=0
|
||||||
|
|
||||||
|
# Required checks
|
||||||
|
log_section "Required Checks"
|
||||||
|
for check in "${REQUIRED_CHECKS[@]}"; do
|
||||||
|
script="${SCRIPT_DIR}/validate/${check}.sh"
|
||||||
|
if [ ! -f "${script}" ]; then
|
||||||
|
log_error "Script not found: ${script}"
|
||||||
|
required_failed=$((required_failed + 1))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_step "Running: ${check}"
|
||||||
|
if "${script}" >/dev/null 2>&1; then
|
||||||
|
log_success "✓ ${check}"
|
||||||
|
required_passed=$((required_passed + 1))
|
||||||
|
else
|
||||||
|
log_error "✗ ${check} (FAILED)"
|
||||||
|
required_failed=$((required_failed + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Optional checks
|
||||||
|
log_section "Optional Checks"
|
||||||
|
for check in "${OPTIONAL_CHECKS[@]}"; do
|
||||||
|
script="${SCRIPT_DIR}/validate/${check}.sh"
|
||||||
|
if [ ! -f "${script}" ]; then
|
||||||
|
log_warn "Script not found: ${script}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_step "Running: ${check}"
|
||||||
|
if "${script}" >/dev/null 2>&1; then
|
||||||
|
log_success "✓ ${check}"
|
||||||
|
optional_passed=$((optional_passed + 1))
|
||||||
|
else
|
||||||
|
log_warn "✗ ${check} (warnings/issues found)"
|
||||||
|
optional_failed=$((optional_failed + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Summary
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
log_separator
|
||||||
|
log_section "Validation Summary"
|
||||||
|
log_separator
|
||||||
|
|
||||||
|
log_kv "Required checks passed" "${required_passed}/${#REQUIRED_CHECKS[@]}"
|
||||||
|
log_kv "Required checks failed" "${required_failed}"
|
||||||
|
log_kv "Optional checks passed" "${optional_passed}/${#OPTIONAL_CHECKS[@]}"
|
||||||
|
log_kv "Optional checks with issues" "${optional_failed}"
|
||||||
|
|
||||||
|
log_separator
|
||||||
|
|
||||||
|
if [ "${required_failed}" -gt 0 ]; then
|
||||||
|
log_error "FAILED: ${required_failed} required check(s) failed"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
log_success "SUCCESS: All required checks passed"
|
||||||
|
if [ "${optional_failed}" -gt 0 ]; then
|
||||||
|
log_warn "Note: ${optional_failed} optional check(s) found issues"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user