|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Runs all Markdown report scripts (no Chromium required, no Python required). |
| 4 | +# It only considers scripts in the "reports" and "domains" directories and their sub directories (overridable with REPORTS_SCRIPT_DIR and DOMAINS_DIRECTORY). |
| 5 | + |
| 6 | +# Requires reports/*.sh |
| 7 | + |
| 8 | +# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands) |
| 9 | +set -o errexit -o pipefail |
| 10 | + |
| 11 | +# Overrideable Constants (defaults also defined in sub scripts) |
| 12 | +LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command. |
| 13 | +LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command. |
| 14 | + |
| 15 | +## Get this "scripts/reports/compilations" directory if not already set. |
| 16 | +# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution. |
| 17 | +# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes. |
| 18 | +# This way non-standard tools like readlink aren't needed. |
| 19 | +REPORT_COMPILATIONS_SCRIPT_DIR=${REPORT_COMPILATIONS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} |
| 20 | +echo "MarkdownReports: REPORT_COMPILATIONS_SCRIPT_DIR=${REPORT_COMPILATIONS_SCRIPT_DIR}" |
| 21 | + |
| 22 | +REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$(dirname -- "${REPORT_COMPILATIONS_SCRIPT_DIR}")} |
| 23 | +echo "MarkdownReports: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}" |
| 24 | + |
| 25 | +SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${REPORTS_SCRIPT_DIR}")} |
| 26 | +echo "MarkdownReports: SCRIPTS_DIR=${SCRIPTS_DIR}" |
| 27 | + |
| 28 | +# Get the "domains" directory that contains analysis and report scripts by functionality. |
| 29 | +DOMAINS_DIRECTORY=${DOMAINS_DIRECTORY:-"${REPORTS_SCRIPT_DIR}/../../domains"} |
| 30 | +echo "MarkdownReports: DOMAINS_DIRECTORY=${DOMAINS_DIRECTORY}" |
| 31 | + |
| 32 | +# Run all Markdown report scripts (filename ending with Markdown.sh or Summary.sh) in the REPORTS_SCRIPT_DIR and DOMAINS_DIRECTORY directories. |
| 33 | +for directory in "${REPORTS_SCRIPT_DIR}" "${DOMAINS_DIRECTORY}"; do |
| 34 | + if [ ! -d "${directory}" ]; then |
| 35 | + echo "MarkdownReports: Error: Directory ${directory} does not exist. Please check your REPORTS_SCRIPT_DIR and DOMAIN_DIRECTORY settings." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + |
| 39 | + # Run all Python report scripts for the selected directory. |
| 40 | + find "${directory}" -type f \( -name "*Markdown.sh" -o -name "*Summary.sh" \) | sort | while read -r report_script_file; do |
| 41 | + report_script_filename=$(basename -- "${report_script_file}"); |
| 42 | + report_script_filename="${report_script_filename%.*}" # Remove file extension |
| 43 | + |
| 44 | + echo "${LOG_GROUP_START}Create Markdown Report ${report_script_filename}"; |
| 45 | + echo "MarkdownReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Starting ${report_script_filename}..."; |
| 46 | + |
| 47 | + source "${report_script_file}" |
| 48 | + |
| 49 | + echo "MarkdownReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Finished ${report_script_filename}"; |
| 50 | + echo "${LOG_GROUP_END}"; |
| 51 | + done |
| 52 | +done |
0 commit comments