3
3
# This script generates a maven command to test unit and integration tests for
4
4
# the repo. The outputted maven command will be in the rough following format
5
5
# `mvn verify ... -D{dependency.name}.version={dependency.version]`. The variables
6
- # ${dependency.name} and ${dependency.version} come from the upper-bound dependencies
7
- # file called `dependencies.txt` located in the root of sdk-platform-java.
6
+ # ${dependency.name} and ${dependency.version} are parsed from the input to the script.
8
7
#
9
- # The upper-bound dependencies file will be in the format of:
8
+ # There are two inputs to the script:
9
+ # 1. -f {file}: File for the upper-bound dependencies to test
10
+ # 2. -l {deps_list}: Comma-separated list of dependencies to test
11
+ # If both inputs are supplied, the deps_list has precedence. For Github Actions workflow,
12
+ # the default run will run with the upper-bounds file. A `workflow_dispatch` option takes in
13
+ # an input for the deps_list to manually run a subset of dependencies
14
+ #
15
+ # The default upper-bound dependencies file is `dependencies.txt` located in the root
16
+ # of sdk-platform-java. The upper-bound dependencies file will be in the format of:
10
17
# ${dependency.name}=${dependency.version}
18
+ #
19
+ # The deps_list is in the format of `dep1=1.0,dep2=2.0`
11
20
12
21
set -ex
13
22
14
- file=' '
15
- dependency_list=' '
16
-
17
23
function print_help() {
18
24
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)"
25
+ echo " Use -f {file} for the directory of the upper-bound dependencies file."
26
+ echo " Use -l {deps_list} for a comma-separated list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
21
27
}
22
28
29
+ # Default to the upper bounds file in the root of the repo
30
+ file=' dependencies.txt'
31
+ dependency_list=' '
32
+
33
+ # The colon (:) after the letter means that there is an input associated with the flag
23
34
while getopts ' f:l:' flag; do
24
35
case " ${flag} " in
25
36
f) file=" ${OPTARG} " ;;
@@ -28,6 +39,7 @@ while getopts 'f:l:' flag; do
28
39
esac
29
40
done
30
41
42
+ # Error if both the file and deps_list inputs is empty
31
43
if [[ -z " ${file} " && -z " ${dependency_list} " ]]; then
32
44
print_help && exit 1
33
45
fi
@@ -40,13 +52,13 @@ if [ -z "${dependency_list}" ]; then
40
52
UPPER_BOUND_DEPENDENCY_FILE=$file
41
53
42
54
if [ ! -e " ${UPPER_BOUND_DEPENDENCY_FILE} " ]; then
43
- echo " The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE} ' does not exist "
55
+ echo " The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE} ' cannot be found "
44
56
exit 1
45
57
fi
46
58
47
59
# Read the file line by line
48
60
while IFS= read -r line; do
49
- # Ignore comments and blank lines
61
+ # Ignore any comments and blank lines
50
62
if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
51
63
continue
52
64
fi
@@ -60,7 +72,7 @@ if [ -z "${dependency_list}" ]; then
60
72
# Append the formatted property to the Maven command
61
73
MAVEN_COMMAND+= " -D${dependency} =${version} "
62
74
done < " ${UPPER_BOUND_DEPENDENCY_FILE} "
63
- else # List of dependencies was inputted
75
+ else # This else block means that a list of dependencies was inputted
64
76
# Set the Internal Field Separator (IFS) to a comma.
65
77
# This tells 'read' to split the string by commas into an array named DEPS.
66
78
# The 'read -ra' command reads the input into an array.
@@ -69,7 +81,7 @@ else # List of dependencies was inputted
69
81
# Loop through each item in the DEPS array.
70
82
for DEP_PAIR in " ${DEPS[@]} " ; do
71
83
# Skip any empty items that might result from trailing commas.
72
- if [ -z " $DEP_PAIR " ]; then
84
+ if [ -z " ${ DEP_PAIR} " ]; then
73
85
continue
74
86
fi
75
87
0 commit comments