Skip to content

Commit ad5ec60

Browse files
authored
Merge pull request #477 from JohT/feature/add-public-workflow-inputs-for-maven-artifacts-and-source-repository
Add input parameter for maven artifacts and git source repository to public workflow
2 parents 8325012 + 3d9d1a6 commit ad5ec60

15 files changed

+684
-73
lines changed

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ jobs:
4646
runs-on: ubuntu-latest
4747
outputs:
4848
analysis-name: ${{ steps.set-analysis-name.outputs.analysis-name }}
49-
sources-upload-name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
5049
artifacts-upload-name: ${{ steps.set-artifacts-upload-name.outputs.artifacts-upload-name }}
50+
additional-maven-artifacts: ${{ steps.set-additional-maven-artifacts.outputs.additional-maven-artifacts }}
51+
source-repository-branch: ${{ steps.set-source-repository-branch.outputs.source-repository-branch }}
5152

5253
env:
5354
PROJECT_NAME: AxonFramework
@@ -58,10 +59,6 @@ jobs:
5859
- name: Checkout GIT Repository
5960
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
6061

61-
- name: Run script tests
62-
id: script-tests
63-
run: ./scripts/runTests.sh
64-
6562
- name: Set Set output variable 'analysis-name'
6663
id: set-analysis-name
6764
run: echo "analysis-name=${{ env.PROJECT_NAME }}-${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
@@ -75,7 +72,7 @@ jobs:
7572
mkdir -p ${{ steps.set-analysis-name.outputs.analysis-name }}
7673
cd ${{ steps.set-analysis-name.outputs.analysis-name }}
7774
echo "Working directory: $( pwd -P )"
78-
./../../scripts/downloader/downloadAxonFramework.sh ${{ env.AXON_FRAMEWORK_VERSION }}
75+
./../../scripts/downloader/downloadAxonFramework.sh ${{ env.AXON_FRAMEWORK_VERSION }} --skip-clone
7976
8077
- name: Debug folder structure in temp directory
8178
if: runner.debug == '1'
@@ -86,23 +83,17 @@ jobs:
8683
- name: (Prepare Code to Analyze) Generate ARTIFACT_UPLOAD_ID
8784
run: echo "ARTIFACT_UPLOAD_ID=$(LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 10)" >> $GITHUB_ENV
8885

89-
- name: (Prepare Code to Analyze) Set sources-upload-name
90-
id: set-sources-upload-name
91-
run: echo "sources-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-sources_input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
92-
9386
- name: (Prepare Code to Analyze) Set output variable 'artifacts-upload-name'
9487
id: set-artifacts-upload-name
9588
run: echo "artifacts-upload-name=${{ steps.set-analysis-name.outputs.analysis-name }}-analysis-artifacts-input-${{ env.ARTIFACT_UPLOAD_ID }}" >> "$GITHUB_OUTPUT"
9689

97-
- name: (Prepare Code to Analyze) Upload sources to analyze
98-
if: success()
99-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
100-
with:
101-
name: ${{ steps.set-sources-upload-name.outputs.sources-upload-name }}
102-
path: ./temp/${{ steps.set-analysis-name.outputs.analysis-name }}/source
103-
include-hidden-files: true
104-
if-no-files-found: error
105-
retention-days: 1
90+
- name: (Prepare Code to Analyze) Set output variable 'additional-maven-artifacts'
91+
id: set-additional-maven-artifacts
92+
run: echo "additional-maven-artifacts=org.axonframework:axon-messaging:${{ env.AXON_FRAMEWORK_VERSION }},org.axonframework:axon-modelling:${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
93+
94+
- name: (Prepare Code to Analyze) Set output variable 'source-repository-branch'
95+
id: set-source-repository-branch
96+
run: echo "source-repository-branch=axon-${{ env.AXON_FRAMEWORK_VERSION }}" >> "$GITHUB_OUTPUT"
10697

10798
- name: (Prepare Code to Analyze) Upload artifacts to analyze
10899
if: success()
@@ -120,6 +111,12 @@ jobs:
120111
uses: ./.github/workflows/public-analyze-code-graph.yml
121112
with:
122113
analysis-name: ${{ needs.prepare-code-to-analyze.outputs.analysis-name }}
114+
# All necessary artifacts are contained in the uploaded artifacts.
115+
# This could easily be replaced by maven-artifact parameter below, but remains here for testing purposes.
123116
artifacts-upload-name: ${{ needs.prepare-code-to-analyze.outputs.artifacts-upload-name }}
124-
sources-upload-name: ${{ needs.prepare-code-to-analyze.outputs.sources-upload-name }}
117+
# Additional (duplicate) artifacts are only used here to test maven-artifacts parameter.
118+
maven-artifacts: ${{needs.prepare-code-to-analyze.outputs.additional-maven-artifacts}}
119+
source-repository: https://github.com/AxonFramework/AxonFramework.git
120+
source-repository-branch: ${{ needs.prepare-code-to-analyze.outputs.source-repository-branch}}
121+
source-repository-history-only: true
125122
jupyter-pdf: "false"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# Only watch changes in scripts, json files containing test data and this workflow for push events
8+
paths:
9+
- '**/*.sh'
10+
- '**/test*.*'
11+
- '.github/workflows/internal-run-tests.yml'
12+
pull_request:
13+
branches:
14+
- main
15+
# Only watch changes in scripts, json files containing test data and this workflow for push events
16+
paths:
17+
- '**/*.sh'
18+
- '**/test*.*'
19+
- '.github/workflows/internal-run-tests.yml'
20+
21+
jobs:
22+
run-tests:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout GIT Repository
27+
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
28+
29+
- name: Run script tests
30+
id: script-tests
31+
run: ./scripts/runTests.sh

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

Lines changed: 49 additions & 4 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'
@@ -27,6 +35,28 @@ on:
2735
required: false
2836
type: string
2937
default: ''
38+
source-repository:
39+
description: >
40+
The URL of the source repository to analyze. For now, only GitHub repositories are supported.
41+
This can be used instead of 'sources-upload-name' to directly analyze a repository without uploading artifacts first.
42+
It can also be used in addition to 'sources-upload-name' to analyze both uploaded sources and a repository.
43+
required: false
44+
type: string
45+
default: ''
46+
source-repository-branch:
47+
description: >
48+
The branch, tag or SHA of the source repository to checkout.
49+
Default: default branch of the repository
50+
required: false
51+
type: string
52+
default: ''
53+
source-repository-history-only:
54+
description: >
55+
Whether to clone the source repository as a bare repository ("true") or not ("false", default).
56+
Bare repositories do not have a working directory and are useful for git history analysis when the sources are not needed.
57+
required: false
58+
type: string
59+
default: 'false'
3060
ref:
3161
description: >
3262
The branch, tag or SHA of the code-graph-analysis-pipeline to checkout.
@@ -87,10 +117,15 @@ jobs:
87117
python: 3.12
88118
miniforge: 24.9.0-0
89119
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
93-
120+
- name: Assure that either artifacts-upload-name or maven-artifacts or sources-upload-name or source-repository is set
121+
if: inputs.artifacts-upload-name == '' && inputs.maven-artifacts == '' && inputs.sources-upload-name == '' && inputs.source-repository == ''
122+
run: echo "Please specify either the input parameter 'artifacts-upload-name' or 'maven-artifacts' or 'sources-upload-name' or 'source-repository'."; exit 1
123+
- name: Verify analysis-name only consists of characters safe for folder names
124+
run: |
125+
if [[ ! "${{ inputs.analysis-name }}" =~ ^[A-Za-z0-9._-]+$ ]]; then
126+
echo "The analysis-name '${{ inputs.analysis-name }}' contains invalid characters. Only alphanumeric characters, dots (.), underscores (_) and hyphens (-) are allowed."
127+
exit 1
128+
fi
94129
- name: Assemble ENVIRONMENT_INFO
95130
run: echo "ENVIRONMENT_INFO=java-${{ matrix.java }}-python-${{ matrix.python }}-miniforge-${{ matrix.miniforge }}" >> $GITHUB_ENV
96131

@@ -163,13 +198,23 @@ jobs:
163198
name: ${{ inputs.sources-upload-name }}
164199
path: temp/${{ inputs.analysis-name }}/source/${{ inputs.analysis-name }}
165200

201+
- name: (Code Analysis Setup) Clone source repository for analysis
202+
if: inputs.source-repository != ''
203+
working-directory: temp/${{ inputs.analysis-name }}
204+
run: ./../../scripts/cloneGitRepository.sh --url "${{ inputs.source-repository }}" --branch "${{ inputs.source-repository-branch }}" --history-only "${{ inputs.source-repository-history-only }}" --target "source/${{ inputs.analysis-name }}"
205+
166206
- name: (Code Analysis Setup) Download artifacts for analysis
167207
if: inputs.artifacts-upload-name != ''
168208
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
169209
with:
170210
name: ${{ inputs.artifacts-upload-name }}
171211
path: temp/${{ inputs.analysis-name }}/artifacts
172212

213+
- name: (Code Analysis Setup) Download Maven artifacts for analysis
214+
if: inputs.maven-artifacts != ''
215+
working-directory: temp/${{ inputs.analysis-name }}
216+
run: ./../../scripts/downloadMavenArtifacts.sh "${{ inputs.maven-artifacts }}"
217+
173218
- name: (Debug) Log folder structure of temp directory
174219
if: runner.debug == '1'
175220
working-directory: temp

INTEGRATION.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ 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".
40+
- **source-repository**: The URL of the source code repository to analyze. This parameter is optional and defaults to an empty string. If provided, it will be used to clone the repository for analysis instead of using the uploaded source code artifact. Currently. only public GitHub repositories are supported.
41+
- **source-repository-branch**: The branch of the source code repository to analyze. This parameter is optional and defaults to "main". It is only used if the 'source-repository' parameter is provided.
42+
- **source-repository-history-only**: If set to 'true', only the git history of the source code repository will be cloned for analysis. This parameter is optional and defaults to 'false'. It is only used if the 'source-repository' parameter is provided.
3943
- **analysis-arguments**: The arguments to pass to the analysis script. This parameter is optional and defaults to '--profile Neo4j-latest-low-memory'. You can find all available options in section [Command Line Options of COMMANDS.md/](./COMMANDS.md#command-line-options).
4044
- **typescript-scan-heap-memory**: The heap memory size in MB to use for the TypeScript code scans. This value is only used for the TypeScript code scans and is ignored for other scans. This parameter is optional and defaults to '4096'. It will set the environment variable `TYPESCRIPT_SCAN_HEAP_MEMORY` which leads to `NODE_OPTIONS` set to `--max-old-space-size=4096` for TypeScript scans. See [Questions and Answers of README.md](./README.md#thinking-questions--answers) for more information.
4145

scripts/cloneGitRepository.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env bash
2+
3+
# Provides safe-guarded (security checked parameters) git repository cloning.
4+
5+
# Note: This script needs the path to target directory to clone the git repository to. It defaults to SOURCE_DIRECTORY ("source").
6+
# Note: This script needs git to be installed.
7+
8+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
9+
set -o errexit -o pipefail
10+
11+
# Overrideable Defaults
12+
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"} # Get the source repository directory (defaults to "source")
13+
14+
# Local constants
15+
SCRIPT_NAME=$(basename "${0}")
16+
17+
fail() {
18+
local ERROR_COLOR='\033[0;31m' # red
19+
local DEFAULT_COLOR='\033[0m'
20+
local errorMessage="${1}"
21+
echo -e "${ERROR_COLOR}${SCRIPT_NAME}: Error: ${errorMessage}${DEFAULT_COLOR}" >&2
22+
exit 1
23+
}
24+
25+
# Default and initial values for command line options
26+
url=""
27+
branch="main"
28+
history_only="false"
29+
target="${SOURCE_DIRECTORY}"
30+
dry_run="false"
31+
32+
# Read command line options
33+
USAGE="${SCRIPT_NAME}: Usage: $0 --url <github-repository-url> --branch <branch-name> [--history-only <true|false>] [--target <clone directory>(default=source)]"
34+
35+
while [ "$#" -gt "0" ]; do
36+
key="$1"
37+
case ${key} in
38+
--url)
39+
url="$2"
40+
shift
41+
;;
42+
--branch)
43+
branch="$2"
44+
shift
45+
;;
46+
--history-only)
47+
history_only="$2"
48+
shift
49+
;;
50+
--target)
51+
target="$2"
52+
shift
53+
;;
54+
--dry-run)
55+
dry_run="true"
56+
;;
57+
*)
58+
fail "Unknown option: ${key}"
59+
echo "${USAGE}" >&2
60+
exit 1
61+
esac
62+
shift
63+
done
64+
65+
# --- Validate URL (mandatory)
66+
if [ -z "${url}" ] ; then
67+
fail "The git repository URL (--url) must be provided."
68+
echo "${USAGE}" >&2
69+
exit 1
70+
fi
71+
case "${url}" in
72+
https://github.com/*/*|https://github.com/*/*.git)
73+
;;
74+
*)
75+
fail "The source repository (--url) must be a valid GitHub repository URL."
76+
;;
77+
esac
78+
79+
# --- Validate branch (mandatory, defaults to "main")
80+
if [ -z "${branch}" ] ; then
81+
fail "The git repository branch (--branch) must be provided."
82+
echo "${USAGE}" >&2
83+
exit 1
84+
fi
85+
case "${branch}" in
86+
*[\ ~^:?*[\]\\]*)
87+
fail "The source repository branch contains invalid characters."
88+
;;
89+
esac
90+
91+
# --- Validate history-only (mandatory, defaults to "false")
92+
case "${history_only}" in
93+
true|false)
94+
;;
95+
*)
96+
fail "The source repository history-only option must be either 'true' or 'false'."
97+
echo "${USAGE}" >&2
98+
;;
99+
esac
100+
101+
# --- Validate target directory (mandatory, defaults to SOURCE_DIRECTORY)
102+
if [ -z "${target}" ] ; then
103+
fail "The target directory (--target) ${target} must be provided." >&2
104+
echo "${USAGE}" >&2
105+
exit 1
106+
else
107+
mkdir -p "${target}"
108+
fi
109+
110+
if [ ${dry_run} = "true" ] ; then
111+
echo "Dry run mode enabled. The following command(s) would be executed:" >&2
112+
fi
113+
114+
# --- Clone the git repository
115+
bare_option=""
116+
bare_folder=""
117+
if [ "${history_only}" = "true" ]; then
118+
bare_option="--bare"
119+
bare_folder="/.git" # bare clones need the .git folder to be used as target
120+
fi
121+
122+
if [ ${dry_run} = "true" ] ; then
123+
echo "git clone ${bare_option} --single-branch ${url} --branch ${branch} ${target}${bare_folder}"
124+
exit 0
125+
else
126+
git clone ${bare_option} --single-branch "${url}" --branch "${branch}" "${target}${bare_folder}"
127+
fi

0 commit comments

Comments
 (0)