-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPythonReports.sh
More file actions
executable file
·73 lines (57 loc) · 3.98 KB
/
PythonReports.sh
File metadata and controls
executable file
·73 lines (57 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# Runs all Python report scripts (no Chromium required).
# It only considers scripts in the "reports" and "domains" directories and their sub directories (overridable with REPORTS_SCRIPT_DIR and DOMAINS_DIRECTORY).
# Requires activateCondaEnvironment.sh, activatePythonEnvironment.sh, reports/*.sh
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
# Overrideable Constants (defaults also defined in sub scripts)
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command.
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command.
# Local constants
SCRIPT_NAME=$(basename "${0}")
## Get this "scripts/reports/compilations" directory if not already set.
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
# This way non-standard tools like readlink aren't needed.
REPORT_COMPILATIONS_SCRIPT_DIR=${REPORT_COMPILATIONS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$(dirname -- "${REPORT_COMPILATIONS_SCRIPT_DIR}")}
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${REPORTS_SCRIPT_DIR}")}
# Get the "domains" directory that contains analysis and report scripts by functionality.
DOMAINS_DIRECTORY=${DOMAINS_DIRECTORY:-"${REPORTS_SCRIPT_DIR}/../../domains"}
echo "${LOG_GROUP_START}$(date +'%Y-%m-%dT%H:%M:%S') Initialize Python Reports";
echo "${SCRIPT_NAME}: REPORT_COMPILATIONS_SCRIPT_DIR=${REPORT_COMPILATIONS_SCRIPT_DIR}"
echo "${SCRIPT_NAME}: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
echo "${SCRIPT_NAME}: SCRIPTS_DIR=${SCRIPTS_DIR}"
echo "${SCRIPT_NAME}: DOMAINS_DIRECTORY=${DOMAINS_DIRECTORY}"
echo "${SCRIPT_NAME}: ANALYSIS_DOMAIN=${ANALYSIS_DOMAIN}"
# Create and activate (if necessary) a virtual environment (Conda or venv).
# For Conda, the environment name is taken from the environment variable CODEGRAPH_CONDA_ENVIRONMENT (default "codegraph")
# and the dependencies are listed in the root directory file "conda-environment.yml".
# For venv, the dependencies are listed in the root directory file "requirements.txt".
time source "${SCRIPTS_DIR}/activateCondaEnvironment.sh"
time source "${SCRIPTS_DIR}/activatePythonEnvironment.sh"
echo "${LOG_GROUP_END}";
# Run all Python report scripts (filename ending with Csv.sh) in the REPORTS_SCRIPT_DIR and DOMAINS_DIRECTORY directories.
# When a specific analysis domain is selected, only run reports for that domain's directory.
# Otherwise, run reports from both the general reports directory and all domains.
if [ -n "${ANALYSIS_DOMAIN}" ]; then
analysisReportScriptDirectories=( "${DOMAINS_DIRECTORY}/${ANALYSIS_DOMAIN}" )
else
analysisReportScriptDirectories=( "${REPORTS_SCRIPT_DIR}" "${DOMAINS_DIRECTORY}" )
fi
for directory in "${analysisReportScriptDirectories[@]}"; do
if [ ! -d "${directory}" ]; then
echo "${SCRIPT_NAME}: Error: Directory ${directory} does not exist. Please check your REPORTS_SCRIPT_DIR and DOMAIN_DIRECTORY settings."
exit 1
fi
# Run all Python report scripts for the selected directory.
find "${directory}" -type f \( -name "*Python.sh" -o -name "*Python.py" \) | sort | while read -r report_script_file; do
report_script_filename=$(basename -- "${report_script_file}");
report_script_filename="${report_script_filename%.*}" # Remove file extension
echo "${LOG_GROUP_START}$(date +'%Y-%m-%dT%H:%M:%S') Create Python Report ${report_script_filename}";
echo "${SCRIPT_NAME}: $(date +'%Y-%m-%dT%H:%M:%S') Starting ${report_script_filename}...";
source "${report_script_file}"
echo "${SCRIPT_NAME}: $(date +'%Y-%m-%dT%H:%M:%S') Finished ${report_script_filename}";
echo "${LOG_GROUP_END}";
done
done