Skip to content

Commit d970292

Browse files
committed
Add input parameter for maven artifacts to public workflow
1 parent c0de13e commit d970292

File tree

4 files changed

+111
-3
lines changed

4 files changed

+111
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
4949
sources-upload-name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
5050
artifacts-upload-name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
51+
additional-maven-artifacts: ${{ steps.set-additional-maven-artifacts.outputs.additional-maven-artifacts }}
5152

5253
env:
5354
PROJECT_NAME: AxonFramework
@@ -94,6 +95,10 @@ jobs:
9495
id: set-artifacts-upload-name
9596
run: echo "artifacts-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-artifacts-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
9697

98+
- name: (Prepare Code to Analyze) Set output variable 'additional-maven-artifacts'
99+
id: set-additional-maven-artifacts
100+
run: echo "additional-maven-artifacts=org.axonframework:axon-messaging:${{ env.AXON_FRAMEWORK_VERSION }},org.axonframework:axon-modelling:${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
101+
97102
- name: (Prepare Code to Analyze) Upload sources to analyze
98103
if: success()
99104
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
@@ -120,6 +125,9 @@ jobs:
120125
uses: ./.github/workflows/public-analyze-code-graph.yml
121126
with:
122127
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
128+
# All necessary artifacts are contained in the uploaded artifacts:
123129
artifacts-upload-name: ${{ needs.prepare-code-to-analyze.outputs.artifacts-upload-name }}
130+
# Additional (duplicate) artifacts are not needed for analysis but only used here to test maven artifact download:
131+
maven-artifacts: ${{needs.prepare-code-to-analyze.outputs.additional-maven-artifacts}}
124132
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
125133
jupyter-pdf: "false"

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ on:
1818
required: false
1919
type: string
2020
default: ''
21+
maven-artifacts:
22+
description: >
23+
Comma-separated list of Maven coordinates (groupId:artifactId:version)
24+
to download from Maven Central for the analysis.
25+
Example: 'org.apache.commons:commons-lang3:3.12.0,com.google.guava:guava:31.1-jre'
26+
required: false
27+
type: string
28+
default: ''
2129
sources-upload-name:
2230
description: >
2331
The name of the sources uploaded with 'actions/upload-artifact'
@@ -87,9 +95,9 @@ jobs:
8795
python: 3.12
8896
miniforge: 24.9.0-0
8997
steps:
90-
- name: Assure that either artifacts-upload-name or sources-upload-name is set
91-
if: inputs.artifacts-upload-name == '' && inputs.sources-upload-name == ''
92-
run: echo "Please specify either the input parameter 'artifacts-upload-name' or 'sources-upload-name'."; exit 1
98+
- name: Assure that either artifacts-upload-name or maven-artifacts or sources-upload-name is set
99+
if: inputs.artifacts-upload-name == '' && inputs.maven-artifacts == '' && inputs.sources-upload-name == ''
100+
run: echo "Please specify either the input parameter 'artifacts-upload-name' or 'maven-artifacts' or 'sources-upload-name'."; exit 1
93101

94102
- name: Assemble ENVIRONMENT_INFO
95103
run: echo "ENVIRONMENT_INFO=java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}" >> $GITHUB_ENV
@@ -170,6 +178,11 @@ jobs:
170178
name: ${{ inputs.artifacts-upload-name }}
171179
path: temp/${{ inputs.analysis-name }}/artifacts
172180

181+
- name: (Code Analysis Setup) Download Maven artifacts for analysis
182+
if: inputs.maven-artifacts != ''
183+
working-directory: temp/${{ inputs.analysis-name }}
184+
run: ./../../scripts/downloadMavenArtifacts.sh "${{ inputs.maven-artifacts }}"
185+
173186
- name: (Debug) Log folder structure of temp directory
174187
if: runner.debug == '1'
175188
working-directory: temp

INTEGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The workflow parameters are as follows:
3333

3434
- **analysis-name**: The name of the project to analyze. Example: MyProject-1.0.0. This parameter is required and should be a string.
3535
- **artifacts-upload-name**: The name of the artifacts uploaded with [actions/upload-artifact](https://github.com/actions/upload-artifact/tree/65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08) containing the content of the 'artifacts' directory for the analysis. This is used to analyze Java JARs, WARs, EARs, etc. This parameter is optional and defaults to an empty string.
36+
- **maven-artifacts**: Comma separated list of Maven artifact coordinates (groupId:artifactId:version) to download from Maven Central for the analysis. This is used to analyze Java artifacts without having to upload them as build artifacts. This parameter is optional and defaults to an empty string.
3637
- **sources-upload-name**: The name of the sources uploaded with [actions/upload-artifact](https://github.com/actions/upload-artifact/tree/65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08) containing the content of the 'source' directory for the analysis. It also supports sub-folders for multiple source code bases. This parameter is optional and defaults to an empty string.
3738
Please use 'include-hidden-files: true' if you also want to upload the git history.
3839
- **ref**: The branch, tag, or SHA of the code-graph-analysis-pipeline to checkout. This parameter is optional and defaults to "main".

scripts/downloadMavenArtifacts.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
# Uses Maven to download specified Maven artifacts from Maven Central.
4+
# The artifacts are specified in the first argument as comma separated Maven coordinates.
5+
# Details on the Maven coordinates format: https://maven.apache.org/guides/mini/guide-naming-conventions.html
6+
# The downloaded files are written into the "artifacts" directory of the current analysis directory.
7+
8+
# This script is used inside .github/workflows/public-analyze-code-graph.yml (November 2025)
9+
10+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
11+
set -o errexit -o pipefail
12+
13+
# Overrideable Constants (defaults also defined in sub scripts)
14+
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"}
15+
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"}
16+
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"}
17+
18+
# Local constants
19+
SCRIPT_NAME=$(basename "${0}")
20+
21+
fail() {
22+
local ERROR_COLOR='\033[0;31m' # red
23+
local DEFAULT_COLOR='\033[0m'
24+
local errorMessage="${1}"
25+
echo -e "${ERROR_COLOR}${SCRIPT_NAME}: Error: ${errorMessage}${DEFAULT_COLOR}" >&2
26+
exit 1
27+
}
28+
29+
maven_artifacts=""
30+
dry_run=false
31+
32+
# Input Arguments: Parse the command-line arguments
33+
while [[ $# -gt 0 ]]; do
34+
arg="$1"
35+
case $arg in
36+
--dry-run)
37+
dry_run=true
38+
shift
39+
;;
40+
*)
41+
if [ -z "${maven_artifacts}" ]; then
42+
# The first unnamed input argument contains the comma separated Maven artifact coordinates to download
43+
maven_artifacts="${arg}"
44+
#echo "${SCRIPT_NAME}: maven_artifacts: ${maven_artifacts}"
45+
else
46+
fail "Unknown argument: ${arg}"
47+
fi
48+
shift
49+
;;
50+
esac
51+
done
52+
53+
if [ -z "${maven_artifacts}" ]; then
54+
fail "No Maven artifacts specified to download. Please provide a comma-separated list of Maven coordinates (groupId:artifactId:version)."
55+
fi
56+
57+
if [ ! -d "./${ARTIFACTS_DIRECTORY}" ]; then
58+
fail "This script needs to run inside the analysis directory with an already existing artifacts directory in it. Change into that directory or use ./init.sh to set up an analysis."
59+
fi
60+
61+
if ! command -v "mvn" &> /dev/null ; then
62+
fail "Command mvn (Maven) not found. It's needed to download Maven artifacts from Maven Central."
63+
fi
64+
65+
dry_run_info=""
66+
if [ "${dry_run}" = true ] ; then
67+
echo "${SCRIPT_NAME}: Info: Dry run mode enabled."
68+
dry_run_info=" (dry run)"
69+
fi
70+
71+
# Process each Maven artifact coordinate
72+
echo "${maven_artifacts}" | tr ',' '\n' | while read -r maven_artifact; do
73+
maven_artifact=$(echo "$maven_artifact" | xargs)
74+
75+
# Check if the maven artifact "coordinate" contains exactly two colons
76+
colon_count=$(echo "${maven_artifact}" | tr -cd ':' | wc -c)
77+
if [ "${colon_count}" -ne 2 ]; then
78+
fail "Invalid Maven artifact coordinates: '${maven_artifact}'. It should be in the format 'groupId:artifactId:version'."
79+
fi
80+
81+
echo "${LOG_GROUP_START}Downloading Maven artifact ${maven_artifact}${dry_run_info}"
82+
if [ "${dry_run}" = false ] ; then
83+
mvn --quiet dependency:copy -Dartifact="${maven_artifact}" -DoutputDirectory="./${ARTIFACTS_DIRECTORY}" -Dtransitive=false -Dsilent=true
84+
fi
85+
echo "${LOG_GROUP_END}"
86+
done

0 commit comments

Comments
 (0)