33# This script generates a maven command to test unit and integration tests for
44# the repo. The outputted maven command will be in the rough following format
55# `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.
87#
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:
1017# ${dependency.name}=${dependency.version}
18+ #
19+ # The deps_list is in the format of `dep1=1.0,dep2=2.0`
1120
1221set -ex
1322
14- file=' '
15- dependency_list=' '
16-
1723function print_help() {
1824 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)"
2127}
2228
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
2334while getopts ' f:l:' flag; do
2435 case " ${flag} " in
2536 f) file=" ${OPTARG} " ;;
@@ -28,6 +39,7 @@ while getopts 'f:l:' flag; do
2839 esac
2940done
3041
42+ # Error if both the file and deps_list inputs is empty
3143if [[ -z " ${file} " && -z " ${dependency_list} " ]]; then
3244 print_help && exit 1
3345fi
@@ -40,13 +52,13 @@ if [ -z "${dependency_list}" ]; then
4052 UPPER_BOUND_DEPENDENCY_FILE=$file
4153
4254 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 "
4456 exit 1
4557 fi
4658
4759 # Read the file line by line
4860 while IFS= read -r line; do
49- # Ignore comments and blank lines
61+ # Ignore any comments and blank lines
5062 if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
5163 continue
5264 fi
@@ -60,7 +72,7 @@ if [ -z "${dependency_list}" ]; then
6072 # Append the formatted property to the Maven command
6173 MAVEN_COMMAND+= " -D${dependency} =${version} "
6274 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
6476 # Set the Internal Field Separator (IFS) to a comma.
6577 # This tells 'read' to split the string by commas into an array named DEPS.
6678 # The 'read -ra' command reads the input into an array.
@@ -69,7 +81,7 @@ else # List of dependencies was inputted
6981 # Loop through each item in the DEPS array.
7082 for DEP_PAIR in " ${DEPS[@]} " ; do
7183 # Skip any empty items that might result from trailing commas.
72- if [ -z " $DEP_PAIR " ]; then
84+ if [ -z " ${ DEP_PAIR} " ]; then
7385 continue
7486 fi
7587
0 commit comments