Skip to content

Commit 8a423d8

Browse files
committed
Document environment variables
1 parent 7eadb50 commit 8a423d8

37 files changed

+193
-62
lines changed

COMMANDS.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Change into the [cypher](./cypher/) directory e.g. with `cd cypher` and then exe
115115
Change into the [scripts](./scripts/) directory e.g. with `cd scripts` and then execute the script [generateScriptReference.sh](./scripts/generateScriptReference.sh) with the following command:
116116
117117
```script
118-
./../scripts/generateScriptReference.sh
118+
./generateScriptReference.sh
119119
```
120120
121121
### Update Markdown Reference
@@ -125,11 +125,18 @@ Change into the [results](./results/) directory e.g. with `cd results` and then
125125
👉**Note:** This script is automatically triggered at the end of [copyReportsIntoResults.sh](./scripts/copyReportsIntoResults.sh)
126126
which is included in the pipeline [code-reports.yml](.github/workflows/code-reports.yml) and doesn't need to be executed manually normally.
127127

128-
129128
```script
130129
./../scripts/generateScriptReference.sh
131130
```
132131

132+
### Update Environment Variable Reference
133+
134+
Change into the [scripts](./scripts/) directory e.g. with `cd scripts` and then execute the script [generateEnvironmentVariablesReference.sh](./scripts/generateEnvironmentVariablesReference.sh) with the following command:
135+
136+
```script
137+
./generateEnvironmentVariablesReference.sh
138+
```
139+
133140
## Manual Setup
134141

135142
The manual setup is only documented for completeness. It isn't needed since the analysis also covers download, installation and configuration of all needed tools.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ The [Code Reports Pipeline](./.github/workflows/code-reports.yml) utilizes [GitH
9494

9595
[COMMANDS.md](./COMMANDS.md) contains further details on commands and how to do a manual setup.
9696

97+
## 🛠 Environment Variable Reference
98+
99+
[ENVIRONMENT_VARIABLES.md](./scripts/ENVIRONMENT_VARIABLES.md) contains all environment variables that are used in the scripts including default values and description. It can updated as described in [Update Environment Variable Reference](./COMMANDS.md#update-environment-variable-reference) of the [Commands Reference](./COMMANDS.md).
100+
97101
## 🤔 Questions & Answers
98102

99103
- How can i run an analysis locally?

scripts/ENVIRONMENT_VARIABLES.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Environment Variables Reference
2+
3+
This document serves as a reference for all environment variables that are supported by the script files.
4+
It provides a table listing each environment variable, its default value and its corresponding description provided as a inline comment.
5+
6+
| Environment Variable Name | Default | Description |
7+
| ----------------------------------- | ----------------------------------- | ------------------------------------------------------ |
8+
REPORTS_SCRIPTS_DIRECTORY | reports | Working directory containing the generated reports |
9+
REPORT_COMPILATIONS_SCRIPTS_DIRECTORY | compilations | Repository directory that contains scripts that execute selected report generation scripts |
10+
SETTINGS_PROFILE_SCRIPTS_DIRECTORY | profiles | Repository directory that contains scripts containing settings |
11+
ARTIFACTS_DIRECTORY | artifacts | Working directory containing the artifacts to be analyzed |
12+
RESULTS_DIRECTORY | results | Repository directory containing the final analysis report results |
13+
REPORTS_DIRECTORY | reports | Working directory where the analysis reports are written to |
14+
ARTIFACTS_CHANGE_DETECTION_HASH_FILE | artifactsChangeDetectionHash.txt | Name of the file that contains the hash code of the file list for change detection |
15+
SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION | | Skip PDF generation for Jupyter Notebooks if set to a non empty value e.g. "true" |
16+
JUPYTER_OUTPUT_FILE_POSTFIX | | e.g. "" (no postfix), ".nbconvert" or ".output" |
17+
CODEGRAPH_CONDA_ENVIRONMENT | codegraph | Name of the conda environment to use for code graph analysis |
18+
NEO4J_HTTP_PORT | 7474 | Neo4j HTTP API port for executing queries |
19+
NEO4J_HTTP_TRANSACTION_ENDPOINT | db/neo4j/tx/commit | Neo4j v5: "db/<name>/tx/commit", Neo4j v4: "db/data/transaction/commit" |
20+
CYPHER_DIR | ${SCRIPTS_DIR}/../cypher | Repository directory containing the cypher queries |
21+
NEO4J_VERSION | 4.4.20 | Version 4.4.x is the current long term support (LTS) version (may 2023) |
22+
NEO4J_HTTPS_PORT | 7473 | Neo4j HTTPS port for encrypted querying |
23+
NEO4J_BOLT_PORT | 7687 | Neo4j's own "Bolt Protocol" port |
24+
NEO4J_APOC_PLUGIN_VERSION | 4.4.0.15 | Version number matches Neo4j version |
25+
NEO4J_APOC_PLUGIN_EDITION | all | Since Neo4j v5 only the core edition is maintained |
26+
NEO4J_APOC_PLUGIN_GITHUB | neo4j-contrib/neo4j-apoc-procedures | Location for the old plugins compatible to Neo4j v4 |
27+
NEO4J_GDS_PLUGIN_VERSION | 2.3.4 | Graph Data Science Plugin Version 2.3.x is compatible with Neo4j 4.4.x |
28+
NEO4J_GDS_PLUGIN_EDITION | full | Graph Data Science Plugin Edition: "open" for OpenGDS, "full" for the full version with Neo4j license |
29+
JQASSISTANT_CLI_VERSION | 1.12.2 | Version 1.12.2 is the newest version (may 2023) compatible with Neo4j v4 |
30+
JQASSISTANT_CLI_ARTIFACT | jqassistant-commandline-neo4jv3 | For Neo4j v3 & 4: "jqassistant-commandline-neo4jv3" |
31+
JQASSISTANT_CLI_DISTRIBUTION | distribution.zip | Neo4j v3 & 4: "distribution.zip" |
32+
JQASSISTANT_CONFIG_TEMPLATE | template-neo4jv4-jqassistant.yaml | Name of the template file for the jqassistant configuration |
33+
NEO4J_OPEN_GDS_PLUGIN_VERSION | 2.4.3 | Graph Data Science Plugin Version 2.4.x of is compatible with Neo4j 5.x |
34+
SCRIPTS_DIR | ${REPORTS_SCRIPT_DIR}/.. | Repository directory containing the shell scripts |
35+
JUPYTER_NOTEBOOK_DIRECTORY | ${SCRIPTS_DIR}/../jupyter | Repository directory containing the Jupyter Notebooks |
36+
NEO4J_EDITION | community | Choose "community" or "enterprise" |
37+
NEO4J_BOLT_URI | bolt://localhost:${NEO4J_BOLT_PORT} | Neo4j's own "Bolt Protocol" address |
38+
NEO4J_USER | neo4j | Neo4j login user |
39+
NEO4J_INITIAL_PASSWORD | | Neo4j login password that was set to replace the temporary initial password |
40+
TOOLS_DIRECTORY | tools | Get the tools directory (defaults to "tools") |
41+
JQASSISTANT_CLI_DOWNLOAD_URL | https://repo1.maven.org/maven2/com/buschmais/jqassistant/cli | Download URL for the jQAssistant CLI |
42+
NEO4J_DATA_PATH | $( pwd -P )/data | Path where Neo4j writes its data to (outside tools dir) |
43+
NEO4J_RUNTIME_PATH | $( pwd -P )/runtime | Path where Neo4j puts runtime data to (e.g. logs) (outside tools dir) |

scripts/analysis/analyze.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
# Requires setupNeo4j.sh,setupJQAssistant.sh,startNeo4j.sh,resetAndScanChanged.sh,prepareAnalysis.sh,stopNeo4j.sh,comilations/*.sh,profiles/*.sh
3232

3333
# Overrideable variables with directory names
34-
REPORTS_SCRIPTS_DIRECTORY=${REPORTS_SCRIPTS_DIRECTORY:-"reports"}
35-
REPORT_COMPILATIONS_SCRIPTS_DIRECTORY=${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY:-"compilations"}
36-
SETTINGS_PROFILE_SCRIPTS_DIRECTORY=${SETTINGS_PROFILE_SCRIPTS_DIRECTORY:-"profiles"}
37-
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
34+
REPORTS_SCRIPTS_DIRECTORY=${REPORTS_SCRIPTS_DIRECTORY:-"reports"} # Working directory containing the generated reports
35+
REPORT_COMPILATIONS_SCRIPTS_DIRECTORY=${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY:-"compilations"} # Repository directory that contains scripts that execute selected report generation scripts
36+
SETTINGS_PROFILE_SCRIPTS_DIRECTORY=${SETTINGS_PROFILE_SCRIPTS_DIRECTORY:-"profiles"} # Repository directory that contains scripts containing settings
37+
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"} # Working directory containing the artifacts to be analyzed
3838

3939
# Function to display script usage
4040
usage() {
@@ -97,7 +97,7 @@ ANALYSIS_SCRIPT_DIR=${ANALYSIS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BA
9797
echo "analyze: ANALYSIS_SCRIPT_DIR=${ANALYSIS_SCRIPT_DIR}"
9898

9999
# Get the "scripts" directory by taking the path of this script and going one directory up.
100-
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${ANALYSIS_SCRIPT_DIR}")}
100+
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${ANALYSIS_SCRIPT_DIR}")} # Repository directory containing the shell scripts
101101
echo "analyze: SCRIPTS_DIR=${SCRIPTS_DIR}"
102102

103103
# Assure that there is a report compilation script for the given report argument.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
# Extracts the environment variable declarations including default values from a script file and appends it to a markdown file as table columns.
4+
5+
# Markdown file name
6+
markdownFile="ENVIRONMENT_VARIABLES.md"
7+
8+
# Get the file to search for environment variables from the first (and only) command line option
9+
filePath="$1"
10+
11+
# Check if the given file exists
12+
if [ -z "${filePath}" ] ; then
13+
echo "findEnvironmentVariables: Please provide a file name."
14+
exit 0
15+
fi
16+
17+
# Check if the given file exists
18+
if [ ! -f "./${filePath}" ] ; then
19+
echo "findEnvironmentVariables: File ${filePath} doesn't exist."
20+
exit 0
21+
fi
22+
23+
# Create the markdown file if it doesn't exist with the header of the table
24+
if [ ! -f "./${markdownFile}" ] ; then
25+
echo "findEnvironmentVariables: Creating ${markdownFile}..."
26+
{
27+
echo "# Environment Variables Reference"
28+
echo ""
29+
echo "This document serves as a reference for all environment variables that are supported by the script files."
30+
echo "It provides a table listing each environment variable, its default value and its corresponding description provided as a inline comment."
31+
echo ""
32+
echo "| Environment Variable Name | Default | Description |"
33+
echo "| ----------------------------------- | ----------------------------------- | ------------------------------------------------------ |"
34+
} > ${markdownFile}
35+
fi
36+
37+
# Regular expression that extracts the environment variable name (1st group), its default value (2nd group) and its description (3rd group)
38+
regular_expression='^[[:space:]]*([A-Za-z_][A-Za-z0-9_]*)=\${[A-Za-z_][A-Za-z0-9_]*:-"([^"]*)"}[[:space:]]*#*[[:space:]]*(.*)'
39+
40+
environmentVariables=$(\
41+
# Use grep to find lines with the pattern you specified
42+
grep -E "${regular_expression}" "$filePath" |
43+
# Use sed to extract the variable name and default value
44+
sed -E "s/${regular_expression}/\1;\2;\3/" |
45+
# Use awk to format the output as requested
46+
awk -F ';' '{ printf "%-37s | %-35s | %s |\n", $1, $2, $3 }'\
47+
)
48+
49+
# Iterate over each environment variable line by line
50+
while IFS= read -r environmentVariable; do
51+
# Extract the name of the environment variable out of the markdown table line format.
52+
environmentVariableName=$(echo -n "${environmentVariable}" | tr -s " " | cut -d "|" -f 1)
53+
# Check if the environment variable is already in the output markdown file.
54+
if ! grep -q "${environmentVariableName}" "$markdownFile"; then
55+
# Append the previously found environment variable to the markdown file since it isn't in there yet.
56+
echo "${environmentVariable}" >> ${markdownFile}
57+
fi
58+
done <<< "$environmentVariables"

scripts/copyReportsIntoResults.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1313
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
1414
# This way non-standard tools like readlink aren't needed.
15-
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
15+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
1616
echo "copyReportsIntoResults: SCRIPTS_DIR=$SCRIPTS_DIR"
1717

18-
RESULTS_DIRECTORY=${RESULTS_DIRECTORY:-"results"}
18+
RESULTS_DIRECTORY=${RESULTS_DIRECTORY:-"results"} # Repository directory containing the final analysis report results
1919
echo "copyReportsIntoResults: RESULTS_DIRECTORY=${RESULTS_DIRECTORY}"
2020

21-
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
21+
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"} # Working directory where the analysis reports are written to
2222
echo "copyReportsIntoResults: REPORTS_DIRECTORY=${REPORTS_DIRECTORY}"
2323

2424
FULL_RESULTS_DIRECTORY="./../${RESULTS_DIRECTORY}"

scripts/detectChangedArtifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# A change is detected when the current hash and the stored one differ.
66

77
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
8-
ARTIFACTS_CHANGE_DETECTION_HASH_FILE=${ARTIFACTS_CHANGE_DETECTION_HASH_FILE:-"artifactsChangeDetectionHash.txt"}
8+
ARTIFACTS_CHANGE_DETECTION_HASH_FILE=${ARTIFACTS_CHANGE_DETECTION_HASH_FILE:-"artifactsChangeDetectionHash.txt"} # Name of the file that contains the hash code of the file list for change detection
99
ARTIFACTS_CHANGE_DETECTION_HASH_FILE_PATH="./${ARTIFACTS_DIRECTORY}/$ARTIFACTS_CHANGE_DETECTION_HASH_FILE"
1010

1111
# Check if the artifacts directory exists

scripts/downloadMavenArtifact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fi
5757
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
5858
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
5959
# This way non-standard tools like readlink aren't needed.
60-
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
60+
SCRIPTS_DIR=${SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )} # Repository directory containing the shell scripts
6161

6262
# Internal constants
6363
BASE_URL="https://repo1.maven.org/maven2"

scripts/downloader/downloadAxonFramework.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR:-$( CDPATH=. cd -- "$(dirname --
3636
echo "download${ANALYSIS_NAME}: DOWNLOADER_SCRIPTS_DIR=${DOWNLOADER_SCRIPTS_DIR}"
3737

3838
# Get the "scripts" directory by taking the path of this script and going one directory up.
39-
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${DOWNLOADER_SCRIPTS_DIR}")}
39+
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${DOWNLOADER_SCRIPTS_DIR}")} # Repository directory containing the shell scripts
4040
echo "download${ANALYSIS_NAME}: SCRIPTS_DIR=${SCRIPTS_DIR}"
4141

4242
################################################################

scripts/executeJupyterNotebook.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Requires juypter nbconvert
2323

24-
SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION=${SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION:-""}
24+
SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION=${SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION:-""} # Skip PDF generation for Jupyter Notebooks if set to a non empty value e.g. "true"
2525

2626
# Check if environment variable is set
2727
if [ -z "${NEO4J_INITIAL_PASSWORD}" ]; then
@@ -77,7 +77,7 @@ if [ ! -f "${jupyter_notebook_file_path}/.env" ] ; then
7777
fi
7878

7979
# Define conda environment to use for code structure analysis. Default "codegraph"
80-
CODEGRAPH_CONDA_ENVIRONMENT=${CODEGRAPH_CONDA_ENVIRONMENT:-"codegraph"}
80+
CODEGRAPH_CONDA_ENVIRONMENT=${CODEGRAPH_CONDA_ENVIRONMENT:-"codegraph"} # Name of the conda environment to use for code graph analysis
8181
echo "executeJupyterNotebook: CODEGRAPH_CONDA_ENVIRONMENT=$CODEGRAPH_CONDA_ENVIRONMENT"
8282

8383
# Determine the path to "conda"

0 commit comments

Comments
 (0)