Skip to content

Commit 1b75e41

Browse files
committed
Use shared analysis workflow for Java code analysis
1 parent b1df11a commit 1b75e41

File tree

4 files changed

+131
-93
lines changed

4 files changed

+131
-93
lines changed

.github/workflows/analyze-code-graph.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ on:
77
description: "The name of the project to analyze. E.g. MyProject-1.0.0"
88
required: true
99
type: string
10-
# TODO: Split upload into one for source code folders and one for artifacts like Java JARs
11-
uploaded-artifact-name:
12-
description: "The name of the artifact uploaded with 'actions/upload-artifact' containing the 'source' and 'artifacts' directory with the contents to analyze."
13-
required: true
10+
artifacts-upload-name:
11+
description: "The name of the artifacts uploaded with 'actions/upload-artifact' containing the content of the 'artifacts' directory for the analysis."
12+
required: false
13+
type: string
14+
sources-upload-name:
15+
description: "The name of the sources uploaded with 'actions/upload-artifact' containing the content of the 'source' directory for the analysis."
16+
required: false
1417
type: string
1518
outputs:
1619
uploaded-analysis-results:
@@ -30,6 +33,9 @@ jobs:
3033
python: 3.11
3134
miniforge: 24.9.0-0
3235
steps:
36+
- name: Assure that either artifacts-upload-name or sources-upload-name is set
37+
if: inputs.artifacts-upload-name == '' && inputs.sources-upload-name == ''
38+
run: echo "Please specify either the input parameter 'artifacts-upload-name' or 'sources-upload-name'."; exit 1
3339
- name: Checkout code-graph-analysis-pipeline
3440
uses: actions/checkout@v4
3541
with:
@@ -98,12 +104,18 @@ jobs:
98104
NEO4J_INITIAL_PASSWORD: ${{ steps.generate-neo4j-initial-password.outputs.neo4j-initial-password }}
99105
run: ./init.sh ${{ inputs.analysis-name }}
100106

101-
- name: (Code Analysis Setup) Download source code and artifacts for analysis
107+
- name: (Code Analysis Setup) Download sources for analysis
102108
uses: actions/download-artifact@v4
103109
with:
104-
name: ${{ inputs.uploaded-artifact-name }}
110+
name: ${{ inputs.sources-upload-name }}
105111
path: code-graph-analysis-pipeline/temp/${{ inputs.analysis-name }}/source/${{ inputs.analysis-name }}
106112

113+
- name: (Code Analysis Setup) Download artifacts for analysis
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: ${{ inputs.artifacts-upload-name }}
117+
path: code-graph-analysis-pipeline/temp/${{ inputs.analysis-name }}/artifacts
118+
107119
- name: (Code Analysis) Analyze ${{ inputs.analysis-name }}
108120
working-directory: code-graph-analysis-pipeline/temp/${{ inputs.analysis-name }}
109121
# Shell type can be skipped if jupyter notebook analysis-results (and therefore conda) aren't needed

.github/workflows/java-code-analysis.yml

Lines changed: 88 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: AxonFramework Java Code Structure Graph Analysis
1+
name: AxonFramework Code Graph Analysis (Java)
22

33
on:
44
push:
@@ -36,105 +36,117 @@ on:
3636
- '.github/workflows/typescript-code-analysis.yml'
3737
- '.github/workflows/*documentation.yml'
3838

39-
# Requires the secret NEO4J_INITIAL_PASSWORD to be configured
4039
jobs:
41-
analysis-results:
40+
prepare-code-to-analyze:
4241
runs-on: ubuntu-latest
43-
strategy:
44-
matrix:
45-
include:
46-
- os: ubuntu-latest
47-
java: 17
48-
python: 3.11
49-
miniforge: 24.9.0-0
42+
outputs:
43+
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
44+
sources-upload-name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
45+
artifacts-upload-name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
5046

5147
env:
52-
CI_COMMIT_MESSAGE: Automated code structure analysis analysis-results (CI)
53-
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
5448
PROJECT_NAME: AxonFramework
55-
# Version variable name matches renovate.json configuration entry
49+
# Version variable names matches renovate.json configuration entry
5650
AXON_FRAMEWORK_VERSION: 4.10.3
51+
# Java is in this example only used to download JARs for analysis using Maven
52+
JAVA_VERSION: 21
5753

5854
steps:
59-
- name: Checkout GIT Repository
55+
- name: (Prepare Code to Analyze) Checkout AxonFramework repository
6056
uses: actions/checkout@v4
6157
with:
62-
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
58+
repository: AxonFramework/AxonFramework
59+
ref: axon-${{ env.AXON_FRAMEWORK_VERSION }}
60+
path: ./source
6361

64-
- name: (Code Analysis Setup) Set ANALYSIS_NAME
65-
run: echo "ANALYSIS_NAME=${{ env.PROJECT_NAME }}-${{ env.AXON_FRAMEWORK_VERSION }}" >> $GITHUB_ENV
66-
67-
- name: Setup Code Analysis
68-
uses: ./.github/actions/setup-code-analysis
62+
- name: (Prepare Code to Analyze) Setup Java Development Kit for Maven JARs downloading (JDK) ${{ env.JAVA_VERSION}}
63+
uses: actions/setup-java@v4
6964
with:
70-
java-version: ${{ matrix.java }}
71-
python-version: ${{ matrix.python }}
72-
miniforge-version: ${{ matrix.miniforge }}
73-
analysis-name: ${{ env.ANALYSIS_NAME }}
74-
neo4j-password: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
75-
76-
- name: (Code Analysis) Download ${{ env.ANALYSIS_NAME }}
77-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
78-
run: |
79-
./../../scripts/downloader/downloadAxonFramework.sh ${{ env.AXON_FRAMEWORK_VERSION }}
80-
81-
- name: (Code Analysis) Analyze ${{ env.ANALYSIS_NAME }}
82-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
83-
# Shell type can be skipped if jupyter notebook analysis-results (and therefore conda) aren't needed
84-
shell: bash -el {0}
85-
env:
86-
NEO4J_INITIAL_PASSWORD: ${{ secrets.NEO4J_INITIAL_PASSWORD }}
87-
ENABLE_JUPYTER_NOTEBOOK_PDF_GENERATION: "true"
88-
IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT: "" # Options: "none", "aggregated", "full". default = "plugin" or ""
89-
run: |
90-
./../../scripts/analysis/analyze.sh --profile Neo4jv5-low-memory
91-
92-
- name: (Code Analysis) Collect analysis results
93-
working-directory: code-graph-analysis-pipeline/temp/${{ env.ANALYSIS_NAME }}
65+
distribution: "temurin"
66+
java-version: ${{ env.JAVA_VERSION}}
67+
68+
- name: (Prepare Code to Analyze) Download AxonFramework JARs for analysis
9469
run: |
95-
mkdir -p ./../../../analysis-results/${{ env.ANALYSIS_NAME }}
96-
cp -Rp reports ./../../../analysis-results/${{ env.ANALYSIS_NAME }}
97-
98-
# Upload logs and unfinished analysis-results in case of an error for troubleshooting
99-
- name: Archive failed run with logs and unfinished analysis-results
100-
if: failure()
70+
mvn dependency:copy -Dartifact=org.axonframework:axon-configuration:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
71+
mvn dependency:copy -Dartifact=org.axonframework:axon-disruptor:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
72+
mvn dependency:copy -Dartifact=org.axonframework:axon-eventsourcing:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
73+
mvn dependency:copy -Dartifact=org.axonframework:axon-messaging:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
74+
mvn dependency:copy -Dartifact=org.axonframework:axon-modelling:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
75+
mvn dependency:copy -Dartifact=org.axonframework:axon-test:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
76+
mvn dependency:copy -Dartifact=org.axonframework:axon-server-connector:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
77+
mvn dependency:copy -Dartifact=org.axonframework:axon-spring-boot-autoconfigure:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
78+
mvn dependency:copy -Dartifact=org.axonframework:axon-tracing-opentelemetry:${{ env.AXON_FRAMEWORK_VERSION }} -DoutputDirectory=./artifacts
79+
80+
- name: (Prepare Code to Analyze) Set analysis-name
81+
id: set-analysis-name
82+
run: echo "analysis-name=${{ env.PROJECT_NAME }}-${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
83+
84+
- name: (Prepare Code to Analyze) Generate ARTIFACT_UPLOAD_ID
85+
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
86+
87+
- name: (Prepare Code to Analyze) Set sources-upload-name
88+
id: set-sources-upload-name
89+
run: echo "sources-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-sources_input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
90+
91+
- name: (Prepare Code to Analyze) Assemble ARTIFACTS_UPLOAD_NAME
92+
id: set-artifacts-upload-name
93+
run: echo "artifacts-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-artifacts-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
94+
95+
- name: (Prepare Code to Analyze) Upload sources to analyze
96+
if: success()
10197
uses: actions/upload-artifact@v4
10298
with:
103-
name: java-code-analysis-logs-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
104-
path: |
105-
./code-graph-analysis-pipeline/temp/**/runtime/*
106-
./code-graph-analysis-pipeline/temp/**/reports/*
99+
name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
100+
path: ./source
101+
if-no-files-found: error
107102
retention-days: 5
108103

109-
# Upload successful analysis-results in case they are needed for troubleshooting
110-
- name: Archive successful analysis-results
104+
- name: (Prepare Code to Analyze) Upload artifacts to analyze
111105
if: success()
112106
uses: actions/upload-artifact@v4
113107
with:
114-
name: java-code-analysis-analysis-results-java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
115-
path: ./analysis-results/${{ env.ANALYSIS_NAME }}/*
108+
name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
109+
path: ./artifacts
116110
if-no-files-found: error
117111
retention-days: 5
118112

119-
# Upload Database Export
120-
# Only possible after an export with "./../../scripts/analysis/analyze.sh --report DatabaseCsvExport"
121-
# Won't be done here because of performance and security concerns
122-
#- name: Archive exported database
123-
# uses: actions/upload-artifact@v3
124-
# with:
125-
# name: java-code-analysis-database-export-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}
126-
# path: ./code-graph-analysis-pipeline/temp/**/import
127-
# if-no-files-found: error
128-
# retention-days: 5
113+
114+
analyze-code-graph:
115+
needs: [prepare-code-to-analyze]
116+
uses: ./.github/workflows/analyze-code-graph.yml
117+
with:
118+
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
119+
artifacts-upload-name: ${{ needs.prepare-code-to-analyze.outputs.artifacts-upload-name }}
120+
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
121+
122+
123+
analysis-results:
124+
needs: [prepare-code-to-analyze, analyze-code-graph]
125+
runs-on: ubuntu-latest
126+
127+
env:
128+
CI_COMMIT_MESSAGE: Automated code structure analysis analysis-results (CI)
129+
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Continuous Integration
130+
131+
steps:
132+
- name: Checkout GIT Repository
133+
uses: actions/checkout@v4
134+
with:
135+
token: ${{ secrets.WORKFLOW_GIT_ACCESS_TOKEN }}
136+
137+
- name: (Code Analysis Setup) Download source code and artifacts for analysis
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: ${{ needs.analyze-code-graph.outputs.uploaded-analysis-results }}
141+
path: analysis-results/${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
129142

130143
# Commit and push the native image agent analysis-results
131144
- name: Display environment variable "github.event_name"
132145
run: echo "github.event_name=${{ github.event_name }}"
133-
- name: Commit changes in the "analysis-results" directory
146+
- name: Display changes in the "analysis-results" directory and prepare commit
134147
# Only run when a pull request gets merged or a commit is pushed to the main branch
135148
# git add parameters need to match paths-ignore parameters above
136149
# Git pull before add/commit/push to reduce race conditions on parallel builds
137-
if: github.event_name == 'push'
138150
run: |
139151
git config --global user.name '${{ env.CI_COMMIT_AUTHOR }}'
140152
git config --global user.email "[email protected]"
@@ -143,6 +155,12 @@ jobs:
143155
git status
144156
git add analysis-results
145157
git status
158+
- name: Commit and push changes in the "analysis-results" directory
159+
# Only run when a pull request gets merged or a commit is pushed to the main branch
160+
# git add parameters need to match paths-ignore parameters above
161+
# Git pull before add/commit/push to reduce race conditions on parallel builds
162+
if: github.event_name == 'push'
163+
run: |
146164
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
147165
git status
148166
git rebase --strategy-option=theirs origin/main --verbose

.github/workflows/typescript-code-analysis.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
runs-on: ubuntu-latest
4242
outputs:
4343
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
44-
uploaded-artifact-name: ${{ steps.set-uploaded-artifact-name.outputs.uploaded-artifact-name }}
44+
sources-upload-name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
4545

4646
env:
4747
PROJECT_NAME: react-router
@@ -61,41 +61,34 @@ jobs:
6161
- name: (Prepare Code to Analyze) Install dependencies with pnpm
6262
run: pnpm install --frozen-lockfile --strict-peer-dependencies
6363

64-
- name: (Prepare Code to Analyze) Assemble ANALYSIS_NAME
65-
run: echo "ANALYSIS_NAME=${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}" >> $GITHUB_ENV
64+
- name: (Prepare Code to Analyze) Set analysis-name
65+
id: set-analysis-name
66+
run: echo "analysis-name=${{ env.PROJECT_NAME }}-${{ env.REACT_ROUTER_VERSION }}" >> "$GITHUB_OUTPUT"
6667

6768
- name: (Prepare Code to Analyze) Generate ARTIFACT_UPLOAD_ID
6869
shell: bash
6970
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
7071

71-
- name: (Prepare Code to Analyze) Assemble ARTIFACT_NAME
72-
shell: bash
73-
run: echo "ARTIFACT_NAME=${{ env.ANALYSIS_NAME }}-analysis-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> $GITHUB_ENV
74-
72+
- name: (Prepare Code to Analyze) Set sources-upload-name
73+
id: set-sources-upload-name
74+
run: echo "sources-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-sources_input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
75+
7576
- name: (Prepare Code to Analyze) Upload code to analyze
7677
if: success()
7778
uses: actions/upload-artifact@v4
7879
with:
79-
name: ${{ env.ARTIFACT_NAME }}
80+
name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
8081
path: .
8182
if-no-files-found: error
8283
retention-days: 5
8384

84-
- name: (Prepare Code to Analyze) Set output variable analysis-name
85-
id: set-analysis-name
86-
run: echo "analysis-name=${{ env.ANALYSIS_NAME }}" >> "$GITHUB_OUTPUT"
87-
88-
- name: (Prepare Code to Analyze) Set output variable uploaded-artifact-name
89-
id: set-uploaded-artifact-name
90-
run: echo "uploaded-artifact-name=${{ env.ARTIFACT_NAME }}" >> "$GITHUB_OUTPUT"
91-
9285

9386
analyze-code-graph:
9487
needs: [prepare-code-to-analyze]
9588
uses: ./.github/workflows/analyze-code-graph.yml
9689
with:
9790
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
98-
uploaded-artifact-name: ${{ needs.prepare-code-to-analyze.outputs.uploaded-artifact-name }}
91+
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
9992

10093

10194
analysis-results:

renovate.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@
7575
"npx\\s+--yes\\s+(--package\\s+)?(-p\\s+)?(?<depName>@?[^@]+)@(?<currentValue>.*?)($|\\s+)"
7676
],
7777
"datasourceTemplate": "npm"
78+
},
79+
{
80+
"description": "Update java version in GitHub Action environment variable",
81+
"customType": "regex",
82+
"datasourceTemplate": "java-version",
83+
"depNameTemplate": "java",
84+
"packageNameTemplate": "",
85+
"fileMatch": [
86+
"^(workflow-templates|\\.github/workflows)\\/[^/]+\\.ya?ml$",
87+
"(^|\\/)action\\.ya?ml$]"
88+
],
89+
"matchStrings": [
90+
"JAVA_VERSION:\\s+?(?<currentValue>.*?)\\s+"
91+
],
92+
"extractVersionTemplate": "^(?<version>\\d+).*$"
7893
}
7994
]
8095
}

0 commit comments

Comments
 (0)