Skip to content

Commit 155a487

Browse files
committed
Provide public reuseable workflow for code graph analysis
1 parent 47f9df1 commit 155a487

10 files changed

+349
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: Java 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+
- '.github/workflows/typescript-code-analysis.yml'
21+
- '.github/workflows/*documentation.yml'
22+
pull_request:
23+
branches:
24+
- main
25+
# Ignore changes in documentation, general configuration and reports for pull request events
26+
paths-ignore:
27+
- 'results/**'
28+
- '**/*.md'
29+
- '**/*.txt'
30+
- '**/*.css'
31+
- '**/*.html'
32+
- '**/*.js'
33+
- '.gitignore'
34+
- '.gitattributes'
35+
- 'renovate.json'
36+
- 'changelogTemplate.mustache'
37+
- '**.code-workspace'
38+
- '.github/workflows/typescript-code-analysis.yml'
39+
- '.github/workflows/*documentation.yml'
40+
41+
# Requires the secret NEO4J_INITIAL_PASSWORD to be configured
42+
jobs:
43+
prepare-code-to-analyze:
44+
runs-on: ubuntu-latest
45+
outputs:
46+
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
47+
sources-upload-name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
48+
artifacts-upload-name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
49+
50+
env:
51+
PROJECT_NAME: AxonFramework
52+
# Version variable names matches renovate.json configuration entry
53+
AXON_FRAMEWORK_VERSION: 4.10.3
54+
55+
steps:
56+
- name: Checkout GIT Repository
57+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
58+
59+
- name: Set Set output variable 'analysis-name'
60+
id: set-analysis-name
61+
run: echo "analysis-name=${{ env.PROJECT_NAME }}-${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
62+
63+
- name: Setup temp directory if missing
64+
run: mkdir -p ./temp
65+
66+
- name: Download ${{ steps.set-analysis-name.outputs.analysis-name }}
67+
working-directory: temp
68+
run: |
69+
mkdir -p ${{ steps.set-analysis-name.outputs.analysis-name }}
70+
cd ${{ steps.set-analysis-name.outputs.analysis-name }}
71+
echo "Working directory: $( pwd -P )"
72+
./../../scripts/downloader/downloadAxonFramework.sh ${{ env.AXON_FRAMEWORK_VERSION }}
73+
74+
- name: Debug folder structure in temp directory
75+
working-directory: temp
76+
run: |
77+
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
78+
79+
- name: (Prepare Code to Analyze) Generate ARTIFACT_UPLOAD_ID
80+
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
81+
82+
- name: (Prepare Code to Analyze) Set sources-upload-name
83+
id: set-sources-upload-name
84+
run: echo "sources-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-sources_input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
85+
86+
- name: (Prepare Code to Analyze) Set output variable 'artifacts-upload-name'
87+
id: set-artifacts-upload-name
88+
run: echo "artifacts-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-artifacts-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
89+
90+
- name: (Prepare Code to Analyze) Upload sources to analyze
91+
if: success()
92+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
93+
with:
94+
name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
95+
path: ./temp/${{ steps.set-analysis-name.outputs.analysis-name }}/source
96+
include-hidden-files: true
97+
if-no-files-found: error
98+
retention-days: 1
99+
100+
- name: (Prepare Code to Analyze) Upload artifacts to analyze
101+
if: success()
102+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
103+
with:
104+
name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
105+
path: ./temp/${{ steps.set-analysis-name.outputs.analysis-name }}/artifacts
106+
if-no-files-found: error
107+
retention-days: 1
108+
109+
110+
111+
analyze-code-graph:
112+
needs: [prepare-code-to-analyze]
113+
uses: ./.github/workflows/public-analyze-code-graph.yml
114+
with:
115+
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
116+
artifacts-upload-name: ${{ needs.prepare-code-to-analyze.outputs.artifacts-upload-name }}
117+
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
118+
119+
120+
121+
analysis-results:
122+
needs: [prepare-code-to-analyze, analyze-code-graph]
123+
runs-on: ubuntu-latest
124+
125+
env:
126+
CI_COMMIT_MESSAGE: Automated code structure analysis analysis-results (CI)
127+
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
128+
129+
steps:
130+
- name: Checkout GIT Repository
131+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
132+
with:
133+
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
134+
135+
- name: (Code Analysis Setup) Download source code and artifacts for analysis
136+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
137+
with:
138+
name: ${{ needs.analyze-code-graph.outputs.uploaded-analysis-results }}
139+
path: analysis-results/${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
140+
141+
# Commit and push the native image agent analysis-results
142+
- name: Display environment variable "github.event_name"
143+
run: echo "github.event_name=${{ github.event_name }}"
144+
- name: Display changes in the "analysis-results" directory and prepare commit
145+
# Only run when a pull request gets merged or a commit is pushed to the main branch
146+
# git add parameters need to match paths-ignore parameters above
147+
# Git pull before add/commit/push to reduce race conditions on parallel builds
148+
run: |
149+
git config --global user.name '${{ env.CI_COMMIT_AUTHOR }}'
150+
git config --global user.email "[email protected]"
151+
git config --local http.postBuffer 524288000
152+
git fetch origin
153+
git status
154+
git add analysis-results
155+
git status
156+
- name: Commit and push changes in the "analysis-results" directory
157+
# Only run when a pull request gets merged or a commit is pushed to the main branch
158+
# git add parameters need to match paths-ignore parameters above
159+
# Git pull before add/commit/push to reduce race conditions on parallel builds
160+
if: github.event_name == 'push'
161+
run: |
162+
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
163+
git status
164+
git rebase --strategy-option=theirs origin/main --verbose
165+
git status
166+
git push --verbose
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# This is the public version of the code graph analysis workflow that can be used by other projects.
2+
name: Code Graph Analysis
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
analysis-name:
8+
description: >
9+
The name of the project to analyze.
10+
Example: MyProject-1.0.0
11+
required: true
12+
type: string
13+
artifacts-upload-name:
14+
description: >
15+
The name of the artifacts uploaded with 'actions/upload-artifact'
16+
containing the content of the 'artifacts' directory for the analysis.
17+
Use it to analyze Java JARs, WARs, EARs, etc.
18+
required: false
19+
type: string
20+
default: ''
21+
sources-upload-name:
22+
description: >
23+
The name of the sources uploaded with 'actions/upload-artifact'
24+
containing the content of the 'source' directory for the analysis.
25+
Also supports sub-folders for multiple source code bases.
26+
required: false
27+
type: string
28+
default: ''
29+
ref:
30+
description: >
31+
The branch, tag or SHA of the code-graph-analysis-pipeline to checkout.
32+
Default: "main"
33+
required: false
34+
type: string
35+
default: main
36+
analysis-arguments:
37+
description: >
38+
The arguments to pass to the analysis script.
39+
Default: '--profile Neo4jv5-low-memory'
40+
required: false
41+
type: string
42+
default: '--profile Neo4jv5-low-memory'
43+
typescript-scan-heap-memory:
44+
description: >
45+
The heap memory size in MB to use for the TypeScript code scans (default=4096).
46+
This value is only used for the TypeScript code scans and is ignored for other scans.
47+
required: false
48+
type: string
49+
default: '4096'
50+
outputs:
51+
uploaded-analysis-results:
52+
description: >
53+
The name of the artifact uploaded with 'actions/upload-artifact'
54+
containing all analysis results.
55+
value: ${{ jobs.analyze-code-graph.outputs.uploaded-analysis-results-artifact-name }}
56+
57+
jobs:
58+
analyze-code-graph:
59+
runs-on: ubuntu-22.04
60+
outputs:
61+
uploaded-analysis-results-artifact-name: ${{ steps.set-analysis-results-artifact-name.outputs.uploaded-analysis-results-artifact-name }}
62+
strategy:
63+
matrix:
64+
include:
65+
- os: ubuntu-22.04
66+
java: 17
67+
python: 3.11
68+
miniforge: 24.9.0-0
69+
steps:
70+
- name: Assure that either artifacts-upload-name or sources-upload-name is set
71+
if: inputs.artifacts-upload-name == '' && inputs.sources-upload-name == ''
72+
run: echo "Please specify either the input parameter 'artifacts-upload-name' or 'sources-upload-name'."; exit 1
73+
74+
- name: Checkout code-graph-analysis-pipeline
75+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
76+
with:
77+
repository: JohT/code-graph-analysis-pipeline
78+
ref: ${{ inputs.ref }}
79+
persist-credentials: false
80+
81+
- name: (Java Setup) Java Development Kit (JDK) ${{ matrix.java }}
82+
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4
83+
with:
84+
distribution: "temurin"
85+
java-version: ${{ matrix.java }}
86+
87+
# "Setup Python" can be skipped if jupyter notebook analysis-results aren't needed
88+
- name: (Python Setup) Setup Cache for Conda package manager Miniforge
89+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4
90+
env:
91+
# Increase this value to reset cache if etc/example-environment.yml has not changed
92+
# Reference: https://github.com/conda-incubator/setup-miniconda#caching
93+
CACHE_NUMBER: 0
94+
with:
95+
path: ~/conda_pkgs_dir
96+
key:
97+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-environments-${{hashFiles('**/environment.yml', '.github/workflows/*.yml') }}
98+
99+
- name: (Python Setup) Use version ${{ matrix.python }} with Conda package manager Miniforge
100+
uses: conda-incubator/setup-miniconda@d2e6a045a86077fb6cad6f5adf368e9076ddaa8d # v3
101+
with:
102+
python-version: ${{ matrix.python }}
103+
miniforge-version: ${{ matrix.miniforge }}
104+
activate-environment: codegraph
105+
environment-file: ./jupyter/environment.yml
106+
auto-activate-base: false
107+
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
108+
- name: (Python Setup) Conda environment info
109+
shell: bash -el {0}
110+
run: conda info
111+
112+
- name: (Code Analysis Setup) Setup Cache Analysis Downloads
113+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4
114+
with:
115+
path: ./temp/downloads
116+
key:
117+
${{ runner.os }}-${{ hashFiles('**/*.sh') }}
118+
119+
- name: (Code Analysis Setup) Generate Neo4j Initial Password
120+
id: generate-neo4j-initial-password
121+
run: |
122+
generated_password=$( LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c 12; echo )
123+
echo "::add-mask::$generated_password"
124+
echo "neo4j-initial-password=$generated_password" >> "$GITHUB_OUTPUT"
125+
126+
- name: (Code Analysis Setup) Initialize Analysis
127+
env:
128+
NEO4J_INITIAL_PASSWORD: ${{ steps.generate-neo4j-initial-password.outputs.neo4j-initial-password }}
129+
run: ./init.sh ${{ inputs.analysis-name }}
130+
131+
- name: (Code Analysis Setup) Download sources for analysis
132+
if: inputs.sources-upload-name != ''
133+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
134+
with:
135+
name: ${{ inputs.sources-upload-name }}
136+
path: temp/${{ inputs.analysis-name }}/source/${{ inputs.analysis-name }}
137+
138+
- name: (Code Analysis Setup) Download artifacts for analysis
139+
if: inputs.artifacts-upload-name != ''
140+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
141+
with:
142+
name: ${{ inputs.artifacts-upload-name }}
143+
path: temp/${{ inputs.analysis-name }}/artifacts
144+
145+
- name: (Code Analysis) Analyze ${{ inputs.analysis-name }}
146+
working-directory: temp/${{ inputs.analysis-name }}
147+
# Shell type can be skipped if jupyter notebook analysis-results (and therefore conda) aren't needed
148+
shell: bash -el {0}
149+
env:
150+
NEO4J_INITIAL_PASSWORD: ${{ steps.generate-neo4j-initial-password.outputs.neo4j-initial-password }}
151+
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
152+
IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT: "" # Options: "none", "aggregated", "full". default = "plugin" or ""
153+
run: |
154+
TYPESCRIPT_SCAN_HEAP_MEMORY=${{ inputs.typescript-scan-heap-memory }} ./../../scripts/analysis/analyze.sh ${{ inputs.analysis-arguments }}
155+
156+
- name: Assemble ENVIRONMENT_INFO
157+
run: echo "ENVIRONMENT_INFO=-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}" >> $GITHUB_ENV
158+
159+
- name: Set artifact name for uploaded analysis results
160+
id: set-analysis-results-artifact-name
161+
run: echo "uploaded-analysis-results-artifact-name=code-analysis-results-${{ env.ENVIRONMENT_INFO }}" >> $GITHUB_OUTPUT
162+
163+
# Upload successful analysis-results in case they are needed for troubleshooting
164+
- name: (Code Analysis Results) Archive successful analysis-results
165+
if: success()
166+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
167+
with:
168+
name: ${{ steps.set-analysis-results-artifact-name.outputs.uploaded-analysis-results-artifact-name }}
169+
path: ./temp/${{ inputs.analysis-name }}/reports/*
170+
if-no-files-found: error
171+
retention-days: 5
172+
173+
174+
# Upload logs and unfinished analysis-results in case of an error for troubleshooting
175+
- name: (Code Analysis Results) Archive failed run with logs and unfinished analysis-results
176+
if: failure()
177+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
178+
with:
179+
name: code-analysis-logs-${{ env.ENVIRONMENT_INFO }}
180+
path: |
181+
./temp/**/runtime/*
182+
./temp/**/reports/*
183+
retention-days: 5

0 commit comments

Comments
 (0)