Skip to content

Commit 9da7f45

Browse files
committed
ci: Add Github CI input for a list of dependencies
1 parent f3ed61c commit 9da7f45

File tree

2 files changed

+73
-24
lines changed

2 files changed

+73
-24
lines changed

.github/scripts/test_dependency_compatibility.sh

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,78 @@
1111

1212
set -ex
1313

14-
# Check if a filename was provided as an argument
15-
if [ -z "$1" ]; then
16-
echo "Usage: $0 <dependency_file>"
17-
exit 1
18-
fi
14+
file=''
15+
dependency_list=''
1916

20-
UPPER_BOUND_DEPENDENCY_FILE="$1"
17+
function print_help() {
18+
echo "Unexpected input argument for this script."
19+
echo "Use -f for the directory of the upper-bound dependencies file."
20+
echo "Use -l for a comma-separate list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
21+
}
2122

22-
if [ ! -e "${UPPER_BOUND_DEPENDENCY_FILE}" ]; then
23-
echo "The inputted upper-bound dependency file '$FILE' does not exist"
24-
exit 1
23+
while getopts 'f:l:' flag; do
24+
case "${flag}" in
25+
f) file="${OPTARG}" ;;
26+
l) dependency_list="${OPTARG}" ;;
27+
*) print_help && exit 1
28+
esac
29+
done
30+
31+
if [[ -z "${file}" && -z "${dependency_list}" ]]; then
32+
print_help && exit 1
2533
fi
2634

2735
MAVEN_COMMAND="mvn verify -Penable-integration-tests -Dclirr.skip -Dcheckstyle.skip -Dfmt.skip "
2836

29-
# Read the file line by line
30-
while IFS= read -r line; do
31-
# Ignore comments and blank lines
32-
if [[ "${line}" =~ ^[[:space:]]*# ]] || [[ -z "${line}" ]]; then
33-
continue
37+
# Check if a list of dependencies was provided as an argument. If the list of dependency inputted
38+
# is empty, then run with the upper-bound dependencies file
39+
if [ -z "${dependency_list}" ]; then
40+
UPPER_BOUND_DEPENDENCY_FILE=$file
41+
42+
if [ ! -e "${UPPER_BOUND_DEPENDENCY_FILE}" ]; then
43+
echo "The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE}' does not exist"
44+
exit 1
3445
fi
3546

36-
# Extract the dependency name and version
37-
# We use 'cut' to split the line by '=' and trim whitespace
38-
# The sed command is used to remove potential trailing whitespace from the version number
39-
dependency=$(echo "${line}" | cut -d'=' -f1 | tr -d '[:space:]')
40-
version=$(echo "${line}" | cut -d'=' -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
47+
# Read the file line by line
48+
while IFS= read -r line; do
49+
# Ignore comments and blank lines
50+
if [[ "${line}" =~ ^[[:space:]]*# ]] || [[ -z "${line}" ]]; then
51+
continue
52+
fi
4153

42-
# Append the formatted property to the Maven command
43-
MAVEN_COMMAND+=" -D${dependency}=${version}"
44-
done < "${UPPER_BOUND_DEPENDENCY_FILE}"
54+
# Extract the dependency name and version
55+
# We use 'cut' to split the line by '=' and trim whitespace
56+
# The sed command is used to remove potential trailing whitespace from the version number
57+
dependency=$(echo "${line}" | cut -d'=' -f1 | tr -d '[:space:]')
58+
version=$(echo "${line}" | cut -d'=' -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
59+
60+
# Append the formatted property to the Maven command
61+
MAVEN_COMMAND+=" -D${dependency}=${version}"
62+
done < "${UPPER_BOUND_DEPENDENCY_FILE}"
63+
else # List of dependencies was inputted
64+
# Set the Internal Field Separator (IFS) to a comma.
65+
# This tells 'read' to split the string by commas into an array named DEPS.
66+
# The 'read -ra' command reads the input into an array.
67+
IFS=',' read -ra DEPS <<< "${dependency_list}"
68+
69+
# Loop through each item in the DEPS array.
70+
for DEP_PAIR in "${DEPS[@]}"; do
71+
# Skip any empty items that might result from trailing commas.
72+
if [ -z "$DEP_PAIR" ]; then
73+
continue
74+
fi
75+
76+
# Extract the dependency name and version
77+
# We use 'cut' to split the line by '=' and trim whitespace
78+
# The sed command is used to remove potential trailing whitespace from the version number
79+
dependency=$(echo "${DEP_PAIR}" | cut -d'=' -f1 | tr -d '[:space:]')
80+
version=$(echo "${DEP_PAIR}" | cut -d'=' -f2 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
81+
82+
# Append the formatted property to the PROPERTIES string.
83+
MAVEN_COMMAND+=" -D${dependency}.version=${version}"
84+
done
85+
fi
4586

4687
# Run the generated maven command to test with the dependency versions
4788
$MAVEN_COMMAND

.github/workflows/dependency_compatibility_test.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
branches:
66
- 'main'
77
workflow_dispatch:
8+
inputs:
9+
dependencies-list:
10+
description: 'Comma-separated list of dependencies to test (Format: dep1=1.0,dep2=2.0)'
11+
required: false
812
schedule:
913
- cron: '0 1 * * *' # Nightly at 1am
1014

@@ -27,7 +31,9 @@ jobs:
2731

2832
# Run in the root module which should test for everything barring showcase
2933
- name: Perform Dependency Compatibility Testing
30-
run: ./.github/scripts/test_dependency_compatibility.sh dependencies.txt
34+
# Unless specifically inputted by the user, the `-l` argument will be empty
35+
# and the workflow will run with the default upper-bounds dependencies file
36+
run: ./.github/scripts/test_dependency_compatibility.sh -f dependencies.txt -l ${{ github.event.inputs.dependencies-list }}
3137

3238
# Set up local showcase server
3339
- name: Parse showcase version
@@ -44,5 +50,7 @@ jobs:
4450
cd -
4551
# Run for the Showcase tests
4652
- name: Perform Dependency Compatibility Testing (Showcase)
47-
run: ../.github/scripts/test_dependency_compatibility.sh ../dependencies.txt
53+
# Unless specifically inputted by the user, the `-l` argument will be empty
54+
# and the workflow will run with the default upper-bounds dependencies file
55+
run: ../.github/scripts/test_dependency_compatibility.sh -f ../dependencies.txt -l ${{ github.event.inputs.dependencies-list }}
4856
working-directory: java-showcase

0 commit comments

Comments
 (0)