Skip to content

Commit 277c271

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

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

.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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
# Read the first unnamed input argument containing the Maven artifacts to download
22+
maven_artifacts=$1
23+
24+
fail() {
25+
local ERROR_COLOR='\033[0;31m' # red
26+
local DEFAULT_COLOR='\033[0m'
27+
local errorMessage="${1}"
28+
echo -e "${ERROR_COLOR}${SCRIPT_NAME}: Error: ${errorMessage}${DEFAULT_COLOR}" >&2
29+
exit 1
30+
}
31+
32+
if [ -z "${maven_artifacts}" ]; then
33+
fail "No Maven artifacts specified to download. Please provide a comma-separated list of Maven coordinates (groupId:artifactId:version)."
34+
fi
35+
36+
if [ ! -d "./${ARTIFACTS_DIRECTORY}" ]; then
37+
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."
38+
fi
39+
40+
if ! command -v "mvn" &> /dev/null ; then
41+
fail "Command mvn (Maven) not found. It's needed to download Maven artifacts from Maven Central."
42+
fi
43+
44+
# Process each Maven artifact coordinate
45+
echo "${maven_artifacts}" | tr ',' '\n' | while read -r maven_artifact; do
46+
maven_artifact=$(echo "$maven_artifact" | xargs)
47+
48+
# Check if the maven artifact "coordinate" contains exactly two colons
49+
colon_count=$(echo "${maven_artifact}" | tr -cd ':' | wc -c)
50+
if [ "${colon_count}" -ne 2 ]; then
51+
fail "Invalid Maven artifact coordinates: '${maven_artifact}'. It should be in the format 'groupId:artifactId:version'."
52+
fi
53+
54+
echo "${LOG_GROUP_START}Downloading Maven artifact ${maven_artifact}"
55+
mvn --quiet dependency:copy -Dartifact="${maven_artifact}" -DoutputDirectory="./${ARTIFACTS_DIRECTORY}" -Dtransitive=false -Dsilent=true
56+
echo "${LOG_GROUP_END}"
57+
done

0 commit comments

Comments
 (0)