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