Skip to content

Commit 89347a5

Browse files
committed
Add pipeline for Typescript code analysis
1 parent 903a18b commit 89347a5

File tree

2 files changed

+228
-0
lines changed

2 files changed

+228
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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+
REACT_ROUTER_VERSION: 6.22.0
55+
56+
steps:
57+
- name: Checkout GIT Repository
58+
uses: actions/checkout@v4
59+
with:
60+
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
61+
62+
- name: Setup Java JDK ${{ matrix.java }}
63+
uses: actions/setup-java@v4
64+
with:
65+
distribution: 'adopt'
66+
java-version: ${{ matrix.java }}
67+
68+
- name: Setup node.js ${{ matrix.node }} for Graph Visualization
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: ${{ matrix.node }}
72+
73+
- name: Install nodes packages for Graph Visualization
74+
working-directory: graph-visualization
75+
run: npm ci
76+
77+
- name: Setup Cache for Conda package manager Mambaforge
78+
uses: actions/cache@v4
79+
env:
80+
# Increase this value to reset cache if etc/example-environment.yml has not changed
81+
# Reference: https://github.com/conda-incubator/setup-miniconda#caching
82+
CACHE_NUMBER: 0
83+
with:
84+
path: ~/conda_pkgs_dir
85+
key:
86+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-environments-${{hashFiles('**/environment.yml', '.github/workflows/*.yml') }}
87+
88+
# "Setup Python" can be skipped if jupyter notebook reports aren't needed
89+
- name: Setup Python ${{ matrix.python }} with Conda package manager Mambaforge
90+
uses: conda-incubator/setup-miniconda@v3
91+
with:
92+
python-version: ${{ matrix.python }}
93+
miniforge-variant: Mambaforge
94+
miniforge-version: ${{ matrix.mambaforge }}
95+
use-mamba: true
96+
activate-environment: codegraph
97+
environment-file: ./jupyter/environment.yml
98+
auto-activate-base: false
99+
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
100+
101+
- name: Conda environment info
102+
shell: bash -el {0}
103+
run: conda info
104+
105+
- name: Setup temp directory if missing
106+
run: mkdir -p ./temp
107+
108+
- name: Setup Cache for "temp/downloads" folder
109+
uses: actions/cache@v4
110+
with:
111+
path: ./temp/downloads
112+
key:
113+
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
114+
115+
- name: Download ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
116+
working-directory: temp
117+
run: |
118+
mkdir -p ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
119+
cd ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
120+
echo "Working directory: $( pwd -P )"
121+
./../../scripts/downloader/downloadReactRouter.sh ${{ env.REACT_ROUTER_VERSION }}
122+
123+
- name: Analyze ${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
124+
working-directory: temp/${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}
125+
# Shell type can be skipped if jupyter notebook reports (and therefore conda) aren't needed
126+
shell: bash -el {0}
127+
env:
128+
NEO4J_INITIAL_PASSWORD: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
129+
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
130+
run: |
131+
./../../scripts/analysis/analyze.sh
132+
133+
- name: Move reports from the temp to the results directory preserving their surrounding directory
134+
working-directory: temp
135+
run: ./../scripts/copyReportsIntoResults.sh
136+
137+
# Upload logs and unfinished reports in case of an error for troubleshooting
138+
- name: Archive failed run with logs and unfinished results
139+
if: failure()
140+
uses: actions/upload-artifact@v4
141+
with:
142+
name: code-analysis-logs-java-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
143+
path: |
144+
./temp/**/runtime/*
145+
./temp/**/reports/*
146+
retention-days: 5
147+
148+
# Upload successful results in case they are needed for troubleshooting
149+
- name: Archive successful results
150+
if: success()
151+
uses: actions/upload-artifact@v4
152+
with:
153+
name: code-report-results-java-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
154+
path: ./results
155+
if-no-files-found: error
156+
retention-days: 5
157+
158+
# Upload Database Export
159+
# Only possible after an export with "./../../scripts/analysis/analyze.sh --report DatabaseCsvExport"
160+
# Won't be done here because of performance and security concerns
161+
#- name: Archive exported database
162+
# uses: actions/upload-artifact@v3
163+
# with:
164+
# name: code-report-database-export-${{ matrix.java }}-python-${{ matrix.python }}-mambaforge-${{ matrix.mambaforge }}
165+
# path: ./temp/**/import
166+
# if-no-files-found: error
167+
# retention-days: 5
168+
169+
# Commit and push the native image agent results
170+
- name: Display environment variable "github.event_name"
171+
run: echo "github.event_name=${{ github.event_name }}"
172+
- name: Commit "results" directory containing the reports
173+
# Only run when a pull request gets merged or a commit is pushed to the main branch
174+
# git add parameters need to match paths-ignore parameters above
175+
# Git pull before add/commit/push to reduce race conditions on parallel builds
176+
if: github.event_name == 'push'
177+
run: |
178+
git config --global user.name '${{ env.CI_COMMIT_AUTHOR }}'
179+
git config --global user.email '[email protected]'
180+
git config --local http.postBuffer 524288000
181+
git pull
182+
git add results
183+
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
184+
git push
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)