Skip to content

Commit 78881e7

Browse files
committed
Add pipeline for Typescript code analysis
1 parent 3f21695 commit 78881e7

File tree

6 files changed

+251
-8
lines changed

6 files changed

+251
-8
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Typescript Code Structure Graph Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# Ignore changes in documentation, general configuration and reports for push events
8+
paths-ignore:
9+
- 'results/**'
10+
- '**/*.md'
11+
- '**/*.txt'
12+
- '**/*.css'
13+
- '**/*.html'
14+
- '**/*.js'
15+
- '.gitignore'
16+
- '.gitattributes'
17+
- 'renovate.json'
18+
- 'changelogTemplate.mustache'
19+
- '**.code-workspace'
20+
pull_request:
21+
branches:
22+
- main
23+
# Ignore changes in documentation, general configuration and reports for pull request events
24+
paths-ignore:
25+
- 'results/**'
26+
- '**/*.md'
27+
- '**/*.txt'
28+
- '**/*.css'
29+
- '**/*.html'
30+
- '**/*.js'
31+
- '.gitignore'
32+
- '.gitattributes'
33+
- 'renovate.json'
34+
- 'changelogTemplate.mustache'
35+
- '**.code-workspace'
36+
37+
# Requires the secret NEO4J_INITIAL_PASSWORD to be configured
38+
jobs:
39+
reports:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
include:
44+
- os: ubuntu-latest
45+
java: 17
46+
python: 3.11
47+
mambaforge: 24.3.0-0
48+
node: 18
49+
50+
env:
51+
CI_COMMIT_MESSAGE: Automated code structure analysis reports (CI)
52+
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
53+
PROJECT_NAME: react-router
54+
# Version variable name matches renovate.json configuration entry
55+
REACT_ROUTER_VERSION: 6.22.0
56+
57+
steps:
58+
- name: Checkout GIT Repository
59+
uses: actions/checkout@v4
60+
with:
61+
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
62+
63+
- name: Setup Java JDK ${{ matrix.java }}
64+
uses: actions/setup-java@v4
65+
with:
66+
distribution: 'adopt'
67+
java-version: ${{ matrix.java }}
68+
69+
- name: Setup node.js ${{ matrix.node }} for Graph Visualization
70+
uses: actions/setup-node@v4
71+
with:
72+
node-version: ${{ matrix.node }}
73+
74+
- name: Install nodes packages for Graph Visualization
75+
working-directory: graph-visualization
76+
run: npm ci
77+
78+
- name: Setup Cache for Conda package manager Mambaforge
79+
uses: actions/cache@v4
80+
env:
81+
# Increase this value to reset cache if etc/example-environment.yml has not changed
82+
# Reference: https://github.com/conda-incubator/setup-miniconda#caching
83+
CACHE_NUMBER: 0
84+
with:
85+
path: ~/conda_pkgs_dir
86+
key:
87+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-environments-${{hashFiles('**/environment.yml', '.github/workflows/*.yml') }}
88+
89+
# "Setup Python" can be skipped if jupyter notebook reports aren't needed
90+
- name: Setup Python ${{ matrix.python }} with Conda package manager Mambaforge
91+
uses: conda-incubator/setup-miniconda@v3
92+
with:
93+
python-version: ${{ matrix.python }}
94+
miniforge-variant: Mambaforge
95+
miniforge-version: ${{ matrix.mambaforge }}
96+
use-mamba: true
97+
activate-environment: codegraph
98+
environment-file: ./jupyter/environment.yml
99+
auto-activate-base: false
100+
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
101+
102+
- name: Conda environment info
103+
shell: bash -el {0}
104+
run: conda info
105+
106+
- name: Setup temp directory if missing
107+
run: mkdir -p ./temp
108+
109+
- name: Setup Cache for "temp/downloads" folder
110+
uses: actions/cache@v4
111+
with:
112+
path: ./temp/downloads
113+
key:
114+
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
115+
116+
- name: Download ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
117+
working-directory: temp
118+
run: |
119+
mkdir -p ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
120+
cd ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
121+
echo "Working directory: $( pwd -P )"
122+
./../../scripts/downloader/downloadReactRouter.sh ${{ env.REACT_ROUTER_VERSION }}
123+
124+
- name: Analyze ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
125+
working-directory: temp/${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
126+
# Shell type can be skipped if jupyter notebook reports (and therefore conda) aren't needed
127+
shell: bash -el {0}
128+
env:
129+
NEO4J_INITIAL_PASSWORD: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
130+
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
131+
run: |
132+
./../../scripts/analysis/analyze.sh
133+
134+
- name: Move reports from the temp to the results directory preserving their surrounding directory
135+
working-directory: temp
136+
run: ./../scripts/copyReportsIntoResults.sh
137+
138+
# Upload logs and unfinished reports in case of an error for troubleshooting
139+
- name: Archive failed run with logs and unfinished results
140+
if: failure()
141+
uses: actions/upload-artifact@v4
142+
with:
143+
name: code-analysis-logs-java-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
144+
path: |
145+
./temp/**/runtime/*
146+
./temp/**/reports/*
147+
retention-days: 5
148+
149+
# Upload successful results in case they are needed for troubleshooting
150+
- name: Archive successful results
151+
if: success()
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: code-report-results-java-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
155+
path: ./results
156+
if-no-files-found: error
157+
retention-days: 5
158+
159+
# Upload Database Export
160+
# Only possible after an export with "./../../scripts/analysis/analyze.sh --report DatabaseCsvExport"
161+
# Won't be done here because of performance and security concerns
162+
#- name: Archive exported database
163+
# uses: actions/upload-artifact@v3
164+
# with:
165+
# name: code-report-database-export-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
166+
# path: ./temp/**/import
167+
# if-no-files-found: error
168+
# retention-days: 5
169+
170+
# Commit and push the native image agent results
171+
- name: Display environment variable "github.event_name"
172+
run: echo "github.event_name=${{ github.event_name }}"
173+
- name: Commit "results" directory containing the reports
174+
# Only run when a pull request gets merged or a commit is pushed to the main branch
175+
# git add parameters need to match paths-ignore parameters above
176+
# Git pull before add/commit/push to reduce race conditions on parallel builds
177+
if: github.event_name == 'push'
178+
run: |
179+
git config --global user.name '${{ env.CI_COMMIT_AUTHOR }}'
180+
git config --global user.email '[email protected]'
181+
git config --local http.postBuffer 524288000
182+
git pull
183+
git add results
184+
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
185+
git push

COMMANDS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To run all analysis steps simple execute the following command:
99
```
1010

1111
👉 See [scripts/examples/analyzeAxonFramework.sh](./scripts/examples/analyzeAxonFramework.sh) as an example script that combines all the above steps.
12-
👉 See [Code Structure Analysis Pipeline](./.github/workflows/code-structure-analysis.yml) on how to do this within a GitHub Actions Workflow.
12+
👉 See [Code Structure Analysis Pipeline](./.github/workflows/java-code-analysis.yml) on how to do this within a GitHub Actions Workflow.
1313

1414
### Command Line Options
1515

@@ -87,7 +87,7 @@ Change into the [scripts](./scripts/) directory e.g. with `cd scripts` and then
8787
Change into the [results](./results/) directory e.g. with `cd results` and then execute the script [generateCsvReportReference.sh](./scripts/documentation/generateCsvReportReference.sh) with the following command:
8888

8989
👉**Note:** This script is automatically triggered at the end of [copyReportsIntoResults.sh](./scripts/copyReportsIntoResults.sh)
90-
which is included in the pipeline [code-structure-analysis.yml](.github/workflows/code-structure-analysis.yml) and doesn't need to be executed manually normally.
90+
which is included in the pipeline [java-code-analysis.yml](.github/workflows/java-code-analysis.yml) and doesn't need to be executed manually normally.
9191

9292
```script
9393
./../scripts/documentation/generateCsvReportReference.sh
@@ -98,7 +98,7 @@ which is included in the pipeline [code-structure-analysis.yml](.github/workflow
9898
Change into the [results](./results/) directory e.g. with `cd results` and then execute the script [generateJupyterReportReference.sh](./scripts/documentation/generateJupyterReportReference.sh) with the following command:
9999

100100
👉**Note:** This script is automatically triggered at the end of [copyReportsIntoResults.sh](./scripts/copyReportsIntoResults.sh)
101-
which is included in the pipeline [code-structure-analysis.yml](.github/workflows/code-structure-analysis.yml) and doesn't need to be executed manually normally.
101+
which is included in the pipeline [java-code-analysis.yml](.github/workflows/java-code-analysis.yml) and doesn't need to be executed manually normally.
102102

103103
```script
104104
./../scripts/documentation/generateJupyterReportReference.sh
@@ -109,7 +109,7 @@ which is included in the pipeline [code-structure-analysis.yml](.github/workflow
109109
Change into the [results](./results/) directory e.g. with `cd results` and then execute the script [generateImageReference.sh](./scripts/documentation/generateImageReference.sh) with the following command:
110110

111111
👉**Note:** This script is automatically triggered at the end of [copyReportsIntoResults.sh](./scripts/copyReportsIntoResults.sh)
112-
which is included in the pipeline [code-structure-analysis.yml](.github/workflows/code-structure-analysis.yml) and doesn't need to be executed manually normally.
112+
which is included in the pipeline [java-code-analysis.yml](.github/workflows/java-code-analysis.yml) and doesn't need to be executed manually normally.
113113

114114
```script
115115
./../scripts/documentation/generateImageReference.sh

GETTING_STARTED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ Please read through the [Prerequisites](./README.md#🛠-prerequisites) in the [
8181
Then open your browser and login to your [local Neo4j Web UI](http://localhost:7474/browser) with "neo4j" as user and the initial password you've chosen.
8282
8383
👉 See [scripts/examples/analyzeAxonFramework.sh](./scripts/examples/analyzeAxonFramework.sh) as an example script that combines all the above steps.
84-
👉 See [Code Structure Analysis Pipeline](./.github/workflows/code-structure-analysis.yml) on how to do this within a GitHub Actions Workflow.
84+
👉 See [Code Structure Analysis Pipeline](./.github/workflows/java-code-analysis.yml) on how to do this within a GitHub Actions Workflow.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Contained within this repository is a comprehensive and automated code graph ana
1010

1111
- Analyze static code structure as a graph
1212
- **🌟New🌟:** Also supports Typescript
13-
- Fully automated [pipeline](./.github/workflows/java-code-analysis.yml) from tool installation to report generation
13+
- Fully automated [pipeline for Java](./.github/workflows/java-code-analysis.yml) from tool installation to report generation
14+
- Fully automated [pipeline for Typescript](./.github/workflows/typescript-code-analysis.yml) from tool installation to report generation
15+
- Fully automated [local run](./GETTING_STARTED.md)
1416
- More than 130 CSV reports for dependencies, metrics, cycles, annotations, algorithms and many more
1517
- Jupyter notebook reports for dependencies, metrics, visibility and many more
1618
- Graph structure visualization
@@ -97,7 +99,7 @@ See [GETTING_STARTED.md](./GETTING_STARTED.md) on how to get started on your loc
9799

98100
## 🏗 Pipeline and Tools
99101

100-
The [Code Structure Analysis Pipeline](./.github/workflows/code-structure-analysis.yml) utilizes [GitHub Actions](https://docs.github.com/de/actions) to automate the whole analysis process:
102+
The [Code Structure Analysis Pipeline](./.github/workflows/java-code-analysis.yml) utilizes [GitHub Actions](https://docs.github.com/de/actions) to automate the whole analysis process:
101103

102104
- Use [GitHub Actions](https://docs.github.com/de/actions) Linux Runner
103105
- [Checkout GIT Repository](https://github.com/actions/checkout)
@@ -175,7 +177,7 @@ The [Code Structure Analysis Pipeline](./.github/workflows/code-structure-analys
175177

176178
- How can i add another code basis to be analyzed automatically?
177179
👉 Create a new artifacts download script in the [scripts/downloader](./scripts/downloader/) directory. Take for example [downloadAxonFramework.sh](./scripts/downloader/downloadAxonFramework.sh) as a reference.
178-
👉 Run the script separately before executing [analyze.sh](./scripts/analysis/analyze.sh) also in the [pipeline](./.github/workflows/code-structure-analysis.yml).
180+
👉 Run the script separately before executing [analyze.sh](./scripts/analysis/analyze.sh) also in the [pipeline](./.github/workflows/java-code-analysis.yml).
179181

180182
- How can i trigger a full rescan of all artifacts?
181183
👉 Delete the file `artifactsChangeDetectionHash.txt` in the `artifacts` directory.

renovate.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
"datasourceTemplate": "github-releases",
2121
"extractVersionTemplate": "^axon-?(?<version>.*?)$"
2222
},
23+
{
24+
"fileMatch": [
25+
"^(workflow-templates|\\.github\/workflows)\\/[^/]+\\.ya?ml$",
26+
"(^|\\/)action\\.ya?ml$]"
27+
],
28+
"matchStrings": [
29+
"REACT_ROUTER_VERSION:\\s+?(?<currentValue>.*?)\\s+"
30+
],
31+
"depNameTemplate": "remix-run/react-router",
32+
"datasourceTemplate": "github-releases",
33+
"extractVersionTemplate": "^react-router@?(?<version>.*?)$"
34+
},
2335
{
2436
"fileMatch": [
2537
"README.md"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
# Downloads react-router (https://github.com/remix-run/react-router) from GitHub using git clone.
4+
# The source files are written into the "source" directory of the current analysis directory.
5+
# After scanning it with jQAssistant Typescript Plugin the resulting JSON will be moved into the "artifacts" directory.
6+
7+
# Note: The #-framed blocks are those that are specific to this download.
8+
# The other parts of the script can be reused/copied as a reference to write other download scripts.
9+
10+
# Note: This script is meant to be started within the temporary analysis directory (e.g. "temp/AnalysisName/")
11+
12+
# Requires downloadMavenArtifact.sh
13+
14+
# Get the analysis name from the middle part of the current file name (without prefix "download" and without extension)
15+
SCRIPT_FILE_NAME="$(basename -- "${BASH_SOURCE[0]}")"
16+
SCRIPT_FILE_NAME_WITHOUT_EXTENSION="${SCRIPT_FILE_NAME%%.*}"
17+
SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION="${SCRIPT_FILE_NAME_WITHOUT_EXTENSION##download}"
18+
ANALYSIS_NAME="${SCRIPT_FILE_NAME_WITHOUT_PREFIX_AND_EXTENSION}"
19+
20+
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME=${SCRIPT_FILE_NAME}"
21+
echo "download${ANALYSIS_NAME}: SCRIPT_FILE_NAME_WITHOUT_EXTENSION=${SCRIPT_FILE_NAME_WITHOUT_EXTENSION}"
22+
echo "download${ANALYSIS_NAME}: ANALYSIS_NAME=${ANALYSIS_NAME}"
23+
24+
# Read the first input argument containing the version(s) of the artifact(s)
25+
if [ "$#" -ne 1 ]; then
26+
echo "Error (download${ANALYSIS_NAME}): Usage: $0 <version>" >&2
27+
exit 1
28+
fi
29+
PROJECT_VERSION=$1
30+
echo "download${ANALYSIS_NAME}: PROJECT_VERSION=${PROJECT_VERSION}"
31+
32+
################################################################
33+
# Download react-router source files to be analyzed
34+
################################################################
35+
git clone https://github.com/remix-run/react-router.git source
36+
(
37+
cd source || exit
38+
git checkout "react-router@${PROJECT_VERSION}"
39+
yarn install || yarn
40+
npx --yes @jqassistant/ts-lce >jqassostant-typescript-scan.log
41+
)
42+
mkdir -p artifacts
43+
mv -nv "source/.reports/jqa/ts-output.json" "artifacts/ts-react-router-${PROJECT_VERSION}.json"
44+
################################################################

0 commit comments

Comments
 (0)