added unity files
All checks were successful
Code Documentation / code-docs (push) Successful in 6s
Project Report / project-report (push) Successful in 4s
Validate Code / validate (push) Successful in 3s

This commit is contained in:
Frank Harris 2026-06-15 12:03:33 -05:00
parent 9042333f51
commit 28c15035a4
62 changed files with 3873 additions and 270 deletions

178
tools/validate-code.sh Executable file → Normal file
View file

@ -1,16 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
set -u -o pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
REPORT_DIR="$ROOT_DIR/reports"
ERROR_REPORT="$REPORT_DIR/errors.md"
GENERATED_REPORT="$REPORT_DIR/generated-files.md"
STATUS_FILE="$REPORT_DIR/customer-code-status.txt"
TMP_DIR=""
FILES_CHECKED=0
WARNINGS=0
ERRORS=0
DETAILS=()
GENERATED_FILES=()
EXCLUDES=(
".git"
@ -24,7 +28,27 @@ EXCLUDES=(
"bin"
)
mkdir -p "$REPORT_DIR"
cleanup() {
if [[ -n "$TMP_DIR" && -d "$TMP_DIR" ]]; then
rm -rf "$TMP_DIR"
fi
}
trap cleanup EXIT
record_generated_file() {
local file="$1"
local rel="${file#"$ROOT_DIR"/}"
local existing
for existing in "${GENERATED_FILES[@]}"; do
if [[ "$existing" == "$rel" ]]; then
return
fi
done
GENERATED_FILES+=("$rel")
}
escape_md() {
printf '%s' "$1" | sed 's/|/\\|/g'
@ -34,6 +58,13 @@ have_tool() {
command -v "$1" >/dev/null 2>&1
}
ensure_report_dir() {
mkdir -p "$REPORT_DIR" || {
printf 'Failed to create report directory: %s\n' "$REPORT_DIR" >&2
return 1
}
}
add_warning() {
local message="$1"
WARNINGS=$((WARNINGS + 1))
@ -62,7 +93,10 @@ join_by() {
shift || true
local first=1
local item
for item in "$@"; do
[[ -z "$item" ]] && continue
if [[ $first -eq 1 ]]; then
printf '%s' "$item"
first=0
@ -94,14 +128,22 @@ run_check() {
local file="$2"
shift 2
local stdout_file="$TMP_DIR/stdout.log"
local stderr_file="$TMP_DIR/stderr.log"
local stdout=""
local stderr=""
local combined=""
FILES_CHECKED=$((FILES_CHECKED + 1))
if "$@" >/tmp/runlevel-validate.out 2>/tmp/runlevel-validate.err; then
: >"$stdout_file"
: >"$stderr_file"
if "$@" >"$stdout_file" 2>"$stderr_file"; then
add_ok "$label passed: $(relative_path "$file")"
else
local stdout stderr combined
stdout="$(tr '\n' ' ' </tmp/runlevel-validate.out | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stderr="$(tr '\n' ' ' </tmp/runlevel-validate.err | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stdout="$(tr '\n' ' ' <"$stdout_file" | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stderr="$(tr '\n' ' ' <"$stderr_file" | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
combined="$(join_by ' | ' "${stdout:-}" "${stderr:-}")"
add_error "$label failed: $(relative_path "$file")${combined:+ | $combined}"
fi
@ -111,46 +153,48 @@ run_repo_build_checks() {
local sln_files=()
local csproj_files=()
local cmake_file="$ROOT_DIR/CMakeLists.txt"
local tmp_dir
local tmp_cmake_dir=""
while IFS= read -r -d '' file; do
sln_files+=("$file")
done < <(find "$ROOT_DIR" -path "$ROOT_DIR/.git" -prune -o -name '*.sln' -type f -print0)
done < <(find "$ROOT_DIR" -path "$ROOT_DIR/.git" -prune -o -path "$ROOT_DIR/.forgejo" -prune -o -name '*.sln' -type f -print0)
while IFS= read -r -d '' file; do
csproj_files+=("$file")
done < <(find "$ROOT_DIR" -path "$ROOT_DIR/.git" -prune -o -name '*.csproj' -type f -print0)
done < <(find "$ROOT_DIR" -path "$ROOT_DIR/.git" -prune -o -path "$ROOT_DIR/.forgejo" -prune -o -name '*.csproj' -type f -print0)
if ((${#sln_files[@]} > 0 || ${#csproj_files[@]} > 0)); then
if have_tool dotnet; then
if ((${#sln_files[@]} > 0)); then
local file
for file in "${sln_files[@]}"; do
run_check "dotnet build" "$file" dotnet build "$file" --nologo --verbosity minimal
done
else
local file
for file in "${csproj_files[@]}"; do
run_check "dotnet build" "$file" dotnet build "$file" --nologo --verbosity minimal
done
fi
else
add_warning "dotnet not installed; skipping C# validation."
add_warning "dotnet not installed; skipping C# project validation."
fi
fi
if [[ -f "$cmake_file" ]]; then
if have_tool cmake; then
FILES_CHECKED=$((FILES_CHECKED + 1))
tmp_dir="$(mktemp -d)"
if cmake -S "$ROOT_DIR" -B "$tmp_dir" >/tmp/runlevel-validate.out 2>/tmp/runlevel-validate.err; then
tmp_cmake_dir="$(mktemp -d)"
if cmake -S "$ROOT_DIR" -B "$tmp_cmake_dir" >"$TMP_DIR/stdout.log" 2>"$TMP_DIR/stderr.log"; then
add_ok "cmake configure passed: CMakeLists.txt"
else
local stdout stderr combined
stdout="$(tr '\n' ' ' </tmp/runlevel-validate.out | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stderr="$(tr '\n' ' ' </tmp/runlevel-validate.err | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stdout="$(tr '\n' ' ' <"$TMP_DIR/stdout.log" | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
stderr="$(tr '\n' ' ' <"$TMP_DIR/stderr.log" | sed 's/[[:space:]]\+/ /g; s/^ //; s/ $//')"
combined="$(join_by ' | ' "${stdout:-}" "${stderr:-}")"
add_error "cmake configure failed: CMakeLists.txt${combined:+ | $combined}"
fi
rm -rf "$tmp_dir"
rm -rf "$tmp_cmake_dir"
else
add_warning "cmake not installed; skipping C/C++ validation."
fi
@ -236,29 +280,93 @@ validate_file() {
esac
}
while IFS= read -r -d '' file; do
validate_file "$file"
done < <(collect_files)
write_generated_files_report() {
{
printf '# Generated Files\n\n'
if ((${#GENERATED_FILES[@]} == 0)); then
printf 'No report files were generated.\n'
else
local file
for file in "${GENERATED_FILES[@]}"; do
printf -- '- %s\n' "$file"
done
fi
} >"$GENERATED_REPORT" || return 1
run_repo_build_checks
record_generated_file "$GENERATED_REPORT"
}
{
printf '# Validation Summary\n\n'
printf -- '- Files Checked: %s\n' "$FILES_CHECKED"
printf -- '- Warnings: %s\n' "$WARNINGS"
printf -- '- Errors: %s\n\n' "$ERRORS"
printf '## Detailed Results\n\n'
if ((${#DETAILS[@]} == 0)); then
printf 'No validation steps were run.\n'
else
printf '%s\n' "${DETAILS[@]}"
write_status_file() {
local status_line="NO CUSTOMER CODE ERRORS FOUND"
if ((ERRORS > 0)); then
status_line="CUSTOMER CODE ERRORS FOUND"
fi
} >"$ERROR_REPORT"
rm -f /tmp/runlevel-validate.out /tmp/runlevel-validate.err
printf '%s\n' "$status_line" >"$STATUS_FILE" || return 1
record_generated_file "$STATUS_FILE"
}
if ((ERRORS > 0)); then
exit 1
fi
write_error_report() {
local status_line="NO CUSTOMER CODE ERRORS FOUND"
if ((ERRORS > 0)); then
status_line="CUSTOMER CODE ERRORS FOUND"
fi
exit 0
{
printf '# Validation Summary\n\n'
printf '%s\n\n' "$status_line"
printf -- '- Files Checked: %s\n' "$FILES_CHECKED"
printf -- '- Warnings: %s\n' "$WARNINGS"
printf -- '- Errors: %s\n\n' "$ERRORS"
printf '## Detailed Results\n\n'
if ((${#DETAILS[@]} == 0)); then
printf 'No validation steps were run.\n'
else
printf '%s\n' "${DETAILS[@]}"
fi
} >"$ERROR_REPORT" || return 1
record_generated_file "$ERROR_REPORT"
}
print_terminal_summary() {
local status_line="NO CUSTOMER CODE ERRORS FOUND"
if ((ERRORS > 0)); then
status_line="CUSTOMER CODE ERRORS FOUND"
fi
printf '===== VALIDATION SUMMARY =====\n'
printf '%s\n' "$status_line"
printf 'Files checked: %s\n' "$FILES_CHECKED"
printf 'Warnings: %s\n' "$WARNINGS"
printf 'Errors: %s\n' "$ERRORS"
printf 'Reports written:\n'
local file
for file in "${GENERATED_FILES[@]}"; do
printf -- '- %s\n' "$file"
done
}
main() {
ensure_report_dir || return 1
TMP_DIR="$(mktemp -d)" || {
printf 'Failed to create temporary directory.\n' >&2
return 1
}
while IFS= read -r -d '' file; do
validate_file "$file"
done < <(collect_files)
run_repo_build_checks
write_status_file || return 1
write_error_report || return 1
write_generated_files_report || return 1
print_terminal_summary
return 0
}
main "$@"