Skip to content

Commit 13489ad

Browse files
committed
Separate artifacts & their download from analysis
1 parent d3a5b96 commit 13489ad

File tree

7 files changed

+119
-94
lines changed

7 files changed

+119
-94
lines changed

.github/workflows/code-reports.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ jobs:
9797
key:
9898
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
9999

100+
- name: Download AxonFramework artifacts
101+
working-directory: temp
102+
run: |
103+
mkdir -p "./AxonFramework-${{ env.AXON_FRAMEWORK_VERSION }}"
104+
cd "./AxonFramework-${{ env.AXON_FRAMEWORK_VERSION }}"
105+
./../../scripts/downloader/downloadAxonFramework.sh ${{ env.AXON_FRAMEWORK_VERSION }}
106+
100107
- name: Analyze AxonFramework
101108
working-directory: temp
102109
# Shell type can be skipped if jupyter notebook reports (and therefore conda) aren't needed
103110
shell: bash -el {0}
104-
run: ./../scripts/analysis/analyze.sh --name AxonFramework --version ${{ env.AXON_FRAMEWORK_VERSION }} --report All --profile Neo4jv5
105111
env:
106112
NEO4J_INITIAL_PASSWORD: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
113+
run: |
114+
./../scripts/analysis/analyze.sh --report All --profile Neo4jv5
107115
108116
- name: Move reports from the temp to the results directory preserving their surrounding directory
109117
working-directory: temp

COMMANDS.md

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,62 @@
22

33
## Start an analysis
44

5-
Use the following commands in the root directory of this repository to start an analysis manually e.g. for [AxonFramework](./scripts/artifacts/downloadAxonFramework.sh).
5+
1. Create a directory for all analysis projects
66

7-
```shell
8-
export NEO4J_INITIAL_PASSWORD=theinitialpasswordthatihavechosenforneo4j
9-
mkdir -p ./temp
10-
cd temp
11-
./../scripts/analysis/analyze.sh --name AxonFramework --version 4.8.0
12-
```
7+
```shell
8+
mkdir temp
9+
cd temp
10+
```
11+
12+
1. Create a working directory for your specific analysis
13+
14+
```shell
15+
mkdir MyFirstAnalysis
16+
cd MyFirstAnalysis
17+
```
18+
19+
1. Choose an initial password for Neo4j
20+
21+
```shell
22+
export NEO4J_INITIAL_PASSWORD=theinitialpasswordthatihavechosenforneo4j
23+
```
24+
25+
1. Create the `artifacts` directory for the code to be analyzed (without `cd` afterwards)
26+
27+
```shell
28+
mkdir artifacts
29+
```
1330

14-
Add the command line argument `--report Csv` to only run the CSV reports when you don't have Python set up
15-
or want to skip Jupyter Notebooks.
31+
1. Move the artifacts you want to analyze into the `artifacts` directory
1632

17-
Add the command line argument `--profile Neo4jv4` if you want to use the older long term support (june 2023)
18-
version v4.4.x of Neo4j and compatible versions of plugins and JQAssistant.
33+
1. Optionally run a predefined script to download artifacts
34+
35+
```shell
36+
./../../scripts/downloader/downloadAxonFramework.sh <version>
37+
```
38+
39+
1. Optionally use a script to download artifacts from Maven ([details](#download-maven-artifacts-to-analyze))
40+
41+
1. Start the analysis
42+
43+
```shell
44+
./../../scripts/analysis/analyze.sh
45+
```
46+
47+
<span style="font-size:1.8em;">&#128214;</span>
48+
See [scripts/examples/analyzeAxonFramework.sh](./scripts/examples/analyzeAxonFramework.sh) as an example for all the above steps. See [code-reports Pipeline](./.github/workflows/code-reports.yml) on how to do this within a GitHub Actions Workflow.
49+
50+
<span style="font-size:1.6em;">&#9432;</span>
51+
Add the command line argument `--report Csv` of [analyze.sh](./scripts/analysis/analyze.sh) to only generate CSV reports. This speeds up the report generation and doesn't depend on Python, Jupyter Notebook or any other related dependencies.
52+
53+
<span style="font-size:1.6em;">&#9432;</span>
54+
Add the command line argument `--profile Neo4jv4` of [analyze.sh](./scripts/analysis/analyze.sh) if you want to use the older long term support (june 2023) version v4.4.x of Neo4j and compatible versions of plugins and JQAssistant.
1955
2056
### Notes
2157
22-
- Be sure to use Java 11 (Mai 2023 Neo4j v4 requirement) or Java 17 (June 2023 Neo4j v5 and jQAssistant CLI v2)
58+
- Be sure to use Java 17 for Neo4j v5 and Java 11 for Neo4j v4
2359
- Use your own initial Neo4j password
2460
- For more details have a look at the script [analyze.sh](./scripts/analysis/analyze.sh)
25-
- The script file names (without the prefix "download" and without the file extension) in the directory [scripts/artifacts](./scripts/artifacts) provide all analysis names that are available.
26-
2761
2862
Have a look at [code-reports.yml](./.github/workflows/code-reports.yml) for all details about setup steps and full automation.
2963

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ The [Code Reports Pipeline](./.github/workflows/code-reports.yml) utilizes [GitH
5858
- [Checkout GIT Repository](https://github.com/actions/checkout)
5959
- [Setup Java](https://github.com/actions/setup-java)
6060
- [Setup Python with Conda](https://github.com/conda-incubator/setup-miniconda) package manager [Mambaforge](https://github.com/conda-forge/miniforge#mambaforge)
61+
- Download artifacts that contain the code to be analyzed [scripts/artifacts](./scripts/downloader/)
6162
- Setup [Neo4j](https://neo4j.com) Graph Database ([analysis.sh](./scripts/analysis/analyze.sh))
6263
- Setup [jQAssistant](https://jqassistant.org/get-started) for Java Analysis ([analysis.sh](./scripts/analysis/analyze.sh))
6364
- Start [Neo4j](https://neo4j.com) Graph Database ([analysis.sh](./scripts/analysis/analyze.sh))
64-
- Trigger Artifacts download that contain the code to be analyzed [scripts/artifacts](./scripts/artifacts/)
6565
- Generate CSV Reports [scripts/reports](./scripts/reports) using the command line JSON parser [jq](https://jqlang.github.io/jq)
6666
- Generate [Jupyter Notebook](https://jupyter.org) reports using these libraries specified in the [environment.yml](./jupyter/environment.yml):
6767
- [Python](https://www.python.org)
@@ -97,7 +97,7 @@ The [Code Reports Pipeline](./.github/workflows/code-reports.yml) utilizes [GitH
9797
## 🤔 Questions & Answers
9898

9999
- How can i run an analysis locally?
100-
👉 See [start-an-analysis](./COMMANDS.md#start-an-analysis) in the [Commands Reference](./COMMANDS.md).
100+
👉 See [Start an analysis](./COMMANDS.md#start-an-analysis) in the [Commands Reference](./COMMANDS.md).
101101

102102
- How can i add an CSV report to the pipeline?
103103
👉 Put your new cypher query into the [cypher](./cypher) directory or a suitable (new) sub directory.
@@ -109,12 +109,12 @@ The [Code Reports Pipeline](./.github/workflows/code-reports.yml) utilizes [GitH
109109
👉 Create a new Jupyter report script in the [scripts/reports](./scripts/reports/) directory. Take [OverviewJupyter.sh](./scripts/reports/OverviewJupyter.sh) as a reference for example.
110110
👉 The script will automatically be included because of the directory and its name ending with "Jupyter.sh".
111111

112-
- How can i add another code base to analyze?
113-
👉 Create an new artifacts download script in the [scripts/artifacts](./scripts/artifacts) directory. Take [downloadAxonFramework.](./scripts/artifacts/downloadAxonFramework.sh) as a reference for example.
114-
👉 The script will be triggered when the [analyze](./scripts/analysis/analyze.sh) command
112+
- How can i add another code basis to be analyzed automatically?
113+
👉 Create a new artifacts download script in the [scripts/artifacts](./scripts/artifacts) directory. Take for example [downloadAxonFramework.sh](./scripts/downloader/downloadAxonFramework.sh) as a reference.
114+
👉 Run the script separately before executing [analyze.sh](./scripts/analysis/analyze.sh) also in the [pipeline](./.github/workflows/code-reports.yml).
115115

116116
- How can i trigger a full rescan of all artifacts?
117-
👉 Delete the file `artifactsChangeDetectionHash.txt` in the temporary `artifacts` directory.
117+
👉 Delete the file `artifactsChangeDetectionHash.txt` in the `artifacts` directory.
118118

119119
- How can PDF generation be skipped to speed up report generation and not depend on chromium?
120120
👉 Set environment variable `SKIP_JUPYTER_NOTEBOOK_PDF_GENERATION` to anything except an empty string. Example:

scripts/SCRIPTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ It provides a table listing each script file and its corresponding description f
66
Script | Directory | Description
77
-------|-----------|------------
88
| [analyze.sh](./analysis/analyze.sh) | analysis | Coordinates the end-to-end analysis process, encompassing tool installation, graph generation, and report generation. |
9-
| [downloadAxonFramework.sh](./artifacts/downloadAxonFramework.sh) | artifacts | Downloads AxonFramework (https://developer.axoniq.io/axon-framework) artifacts from Maven Central. |
109
| [copyReportsIntoResults.sh](./copyReportsIntoResults.sh) | | Copies the results from the temp directory to the results directory grouped by the analysis name. |
1110
| [detectChangedArtifacts.sh](./detectChangedArtifacts.sh) | | Detect changed files in the artifacts directory with a text file containing the last hash code of the contents. |
1211
| [downloadMavenArtifact.sh](./downloadMavenArtifact.sh) | | Downloads an artifact from Maven Central (https://mvnrepository.com/repos/central) |
12+
| [downloadAxonFramework.sh](./downloader/downloadAxonFramework.sh) | downloader | Downloads AxonFramework (https://developer.axoniq.io/axon-framework) artifacts from Maven Central. |
1313
| [executeJupyterNotebook.sh](./executeJupyterNotebook.sh) | | Executes all steps in the given Jupyter Notebook (ipynb), stores it and converts it to Markdown (md) and PDF. |
1414
| [executeQuery.sh](./executeQuery.sh) | | Utilizes Neo4j's HTTP API to execute a Cypher query from an input file and provides the results in CSV format. |
1515
| [executeQueryFunctions.sh](./executeQueryFunctions.sh) | | Provides functions to execute Cypher queries using either "executeQuery.sh" or Neo4j's "cypher-shell". |

scripts/analysis/analyze.sh

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
# Coordinates the end-to-end analysis process, encompassing tool installation, graph generation, and report generation.
44
# - Download and setup Neo4j and JQAssistant
5-
# - Trigger artifacts download
6-
# - Scan and analyze the artifacts to create the graph
5+
# - Scan and analyze the contents of the artifacts directory to create the graph
76
# - Trigger all requested reports
87

9-
# Note: Everything is done in the current directory.
10-
# It is recommended to create an empty directory (preferrable "temp")
8+
# Note: Everything is done in the current (=working) directory and one directory above (shared downloads).
9+
# It is recommended to create an empty directory (preferrable "temp") and
10+
# within that another one for the analysis (e.g. "MyCodebaseName-Version")
1111
# and change into it prior to starting this script.
1212

13-
# Note: The argument "--name" is requried. It is used to create the working directory
14-
# as well as to find the script "scripts/artifacts/download<name>.sh" to download the artifacts.
15-
16-
# Note: The argument "--version" is also required.
17-
# It is appended to the working directory to further distinguish the results.
18-
# The version is passed to the artifacts download script as an argument.
19-
2013
# Note: The argument "--report" is optional. The default value is "All".
2114
# It selects the report compilation, a named group of reports. Besides the default "All" there are e.g. "Csv" and "Jupyter".
2215
# This makes it possible to run only a subset of the reports. For example "Csv" won't need python to be set up and runs therefore much faster.
@@ -29,17 +22,16 @@
2922

3023
# Note: The script and its sub scripts are designed to be as efficient as possible
3124
# when it comes to subsequent executions.
32-
# Existing downloads, installations, artifacts, scans and processes will be detected.
25+
# Existing downloads, installations, scans and processes will be detected.
3326

3427
# Overrideable variables with directory names
35-
ARTIFACT_SCRIPTS_DIRECTORY=${ARTIFACT_SCRIPTS_DIRECTORY:-"artifacts"}
3628
REPORTS_SCRIPTS_DIRECTORY=${REPORTS_SCRIPTS_DIRECTORY:-"reports"}
3729
REPORT_COMPILATIONS_SCRIPTS_DIRECTORY=${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY:-"compilations"}
3830
SETTINGS_PROFILE_SCRIPTS_DIRECTORY=${SETTINGS_PROFILE_SCRIPTS_DIRECTORY:-"profiles"}
3931

4032
# Function to display script usage
4133
usage() {
42-
echo "Usage: $0 --name <name> --version <version> [--report <All (default), Csv, Jupyter,...>] [--profile <Default, Neo4jv5, Neo4jv4,...>]"
34+
echo "Usage: $0 [--report <All (default), Csv, Jupyter,...>] [--profile <Default, Neo4jv5, Neo4jv4,...>]"
4335
exit 1
4436
}
4537

@@ -51,14 +43,6 @@ settingsProfile="Default"
5143
while [[ $# -gt 0 ]]; do
5244
key="$1"
5345
case $key in
54-
--name)
55-
analysisName="${2}"
56-
shift
57-
;;
58-
--version)
59-
analysisVersion="$2"
60-
shift
61-
;;
6246
--report)
6347
analysisReportCompilation="$2"
6448
shift
@@ -75,33 +59,15 @@ while [[ $# -gt 0 ]]; do
7559
shift
7660
done
7761

78-
# Check if the name is provided
79-
if [[ -z ${analysisName} ]]; then
80-
echo "analyze ${analysisName}: Error: Name is required."
81-
usage
82-
fi
83-
84-
# Check if the version is provided
85-
if [[ -z ${analysisVersion} ]]; then
86-
echo "analyze ${analysisName}: Error: Version is required."
87-
usage
88-
fi
89-
90-
# Assure that the analysis name only consists of letters and numbers
91-
if ! [[ ${analysisName} =~ ^[[:alnum:]]+$ ]]; then
92-
echo "analyze ${analysisName}: Error: Name can only contain letters and numbers."
93-
exit 1
94-
fi
95-
9662
# Assure that the analysis report compilation only consists of letters and numbers
9763
if ! [[ ${analysisReportCompilation} =~ ^[[:alnum:]]+$ ]]; then
98-
echo "analyze ${analysisName}: Report can only contain letters and numbers."
64+
echo "analyze: Report can only contain letters and numbers."
9965
exit 1
10066
fi
10167

10268
# Assure that the settings profile only consists of letters and numbers
10369
if ! [[ ${settingsProfile} =~ ^[[:alnum:]]+$ ]]; then
104-
echo "analyze ${analysisName}: Error: Settings profile can only contain letters and numbers."
70+
echo "analyze: Error: Settings profile can only contain letters and numbers."
10571
exit 1
10672
fi
10773

@@ -110,66 +76,46 @@ fi
11076
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
11177
# This way non-standard tools like readlink aren't needed.
11278
ANALYSIS_SCRIPT_DIR=${ANALYSIS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
113-
echo "analyze ${analysisName}: ANALYSIS_SCRIPT_DIR=${ANALYSIS_SCRIPT_DIR}"
79+
echo "analyze: ANALYSIS_SCRIPT_DIR=${ANALYSIS_SCRIPT_DIR}"
11480

11581
# Get the "scripts" directory by taking the path of this script and going one directory up.
11682
SCRIPTS_DIR=${SCRIPTS_DIR:-$(dirname -- "${ANALYSIS_SCRIPT_DIR}")}
117-
echo "analyze ${analysisName}: SCRIPTS_DIR=${SCRIPTS_DIR}"
118-
119-
# Assure that there is a download script for the given analysis name argument.
120-
DOWNLOAD_SCRIPT="${SCRIPTS_DIR}/${ARTIFACT_SCRIPTS_DIRECTORY}/download${analysisName}.sh"
121-
if [ ! -f "${DOWNLOAD_SCRIPT}" ] ; then
122-
echo "analyze ${analysisName}: Error: No download${analysisName}.sh script in the directory ${SCRIPTS_DIR}/${ARTIFACT_SCRIPTS_DIRECTORY} for analysis name ${analysisName}."
123-
exit 1
124-
fi
83+
echo "analyze: SCRIPTS_DIR=${SCRIPTS_DIR}"
12584

12685
# Assure that there is a report compilation script for the given report argument.
12786
REPORT_COMPILATION_SCRIPT="${SCRIPTS_DIR}/${REPORTS_SCRIPTS_DIRECTORY}/${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY}/${analysisReportCompilation}Reports.sh"
12887
if [ ! -f "${REPORT_COMPILATION_SCRIPT}" ] ; then
129-
echo "analyze ${analysisName}: Error: No ${analysisReportCompilation}Reports.sh script in the directory ${SCRIPTS_DIR}/${REPORTS_SCRIPTS_DIRECTORY}/${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY} for report name ${analysisReportCompilation}."
88+
echo "analyze: Error: No ${analysisReportCompilation}Reports.sh script in the directory ${SCRIPTS_DIR}/${REPORTS_SCRIPTS_DIRECTORY}/${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY} for report name ${analysisReportCompilation}."
13089
exit 1
13190
fi
13291

13392
# Assure that there is a script file for the given settings profile name.
13493
SETTINGS_PROFILE_SCRIPT="${SCRIPTS_DIR}/${SETTINGS_PROFILE_SCRIPTS_DIRECTORY}/${settingsProfile}.sh"
13594
if [ ! -f "${SETTINGS_PROFILE_SCRIPT}" ] ; then
136-
echo "analyze ${analysisName}: Error: No ${settingsProfile}.sh script in the directory ${SCRIPTS_DIR}/${SETTINGS_PROFILE_SCRIPTS_DIRECTORY} for settings profile ${settingsProfile}."
95+
echo "analyze: Error: No ${settingsProfile}.sh script in the directory ${SCRIPTS_DIR}/${SETTINGS_PROFILE_SCRIPTS_DIRECTORY} for settings profile ${settingsProfile}."
13796
exit 1
13897
fi
13998

14099
# Execute the settings profile script that sets all the neccessary settings variables (overrideable by environment variables).
141-
echo "analyze ${analysisName}: Using analysis settings profile script ${SETTINGS_PROFILE_SCRIPT}"
142-
source "${SETTINGS_PROFILE_SCRIPT}" || exit 1
143-
144-
# Create working directory if it hadn't been created yet
145-
workingDirectory="${analysisName}-${analysisVersion}"
146-
mkdir -p "${workingDirectory}" || exit 2 # Create the working directory only if it doesn't exist
147-
pushd "${workingDirectory}" || exit 2 # Change into the working directory and remember the previous directory
148-
echo "analyze ${analysisName}: Working Directory: $( pwd -P )"
100+
echo "analyze: Using analysis settings profile script ${SETTINGS_PROFILE_SCRIPT}"
101+
source "${SETTINGS_PROFILE_SCRIPT}" || exit 2
149102

150103
# Setup Tools
151104
source "${SCRIPTS_DIR}/setupNeo4j.sh" || exit 3
152105
source "${SCRIPTS_DIR}/setupJQAssistant.sh" || exit 3
153106
source "${SCRIPTS_DIR}/startNeo4j.sh" || exit 3
154107

155-
# Execute the script "scripts/artifacts/download<analysisName" to download the artifacts that should be analyzed
156-
echo "Downloading artifacts with ${DOWNLOAD_SCRIPT} ..."
157-
source "${DOWNLOAD_SCRIPT}" "${analysisVersion}" || exit 4
158-
159108
# Scan and analyze artifacts when they were changed
160-
source "${SCRIPTS_DIR}/resetAndScanChanged.sh" || exit 5
109+
source "${SCRIPTS_DIR}/resetAndScanChanged.sh" || exit 4
161110

162111
# Prepare and validate graph database before analyzing and creating reports
163-
source "${SCRIPTS_DIR}/prepareAnalysis.sh" || exit 6
112+
source "${SCRIPTS_DIR}/prepareAnalysis.sh" || exit 5
164113

165114
#########################
166115
# Create Reports
167116
#########################
168117
echo "Creating Reports with ${REPORT_COMPILATION_SCRIPT} ..."
169-
source "${REPORT_COMPILATION_SCRIPT}" || exit 7
118+
source "${REPORT_COMPILATION_SCRIPT}" || exit 6
170119

171120
# Stop Neo4j at the end
172-
source "${SCRIPTS_DIR}/stopNeo4j.sh"
173-
174-
# Change back to the previous directory where the script was started
175-
popd || exit 8
121+
source "${SCRIPTS_DIR}/stopNeo4j.sh"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# This is an example for an analysis of AxonFramework
4+
# including the creation of the temporary directory, the working directory, the artifacts download and the analysis itself.
5+
6+
# Note: The first (and only) parameter is the version of AxonFramework to analyze.
7+
# Note: This script is meant to be started in the root directory of this repository.
8+
9+
# Read the first input argument containing the version of the artifacts
10+
if [ "$#" -ne 1 ]; then
11+
echo "analyzeAxonFramework Error: Usage: $0 <version>" >&2
12+
exit 1
13+
fi
14+
artifactsVersion=$1
15+
16+
# Check if environment variable is set
17+
if [ -z "${NEO4J_INITIAL_PASSWORD}" ]; then
18+
echo "analyzeAxonFramework: Error: Requires environment variable NEO4J_INITIAL_PASSWORD to be set first. Use 'export NEO4J_INITIAL_PASSWORD=<your-own-password>'."
19+
exit 1
20+
fi
21+
22+
# Create the temporary directory for all analysis projects.
23+
mkdir -p ./temp || exit 1
24+
cd ./temp || exit 1
25+
26+
# Create the working directory for this specific analysis.
27+
mkdir -p "./AxonFramework-${artifactsVersion}" || exit 2
28+
cd "./AxonFramework-${artifactsVersion}" || exit 2
29+
30+
# Create the artifacts directory that will contain the code to be analyzed.
31+
mkdir -p ./artifacts
32+
33+
# Download AxonFramework artifacts (jar files) from Maven
34+
./../../scripts/downloader/downloadAxonFramework.sh "${artifactsVersion}"
35+
36+
# Start the analysis
37+
./../../scripts/analysis/analyze.sh

0 commit comments

Comments
 (0)