@@ -27,25 +27,66 @@ source ${scriptDir}/common.sh
2727mkdir -p ${HOME} /.m2
2828cp settings.xml ${HOME} /.m2
2929
30+ excluded_modules=(' CoverageAggregator' ' google-cloud-gapic-bom' )
31+
32+ function generate_modified_modules_list() {
33+ # Find the files changed from when the PR branched to the last commit
34+ # Filter for java modules and get all the unique elements
35+ # grep returns 1 (error code) and exits the pipeline if there is no match
36+ # If there is no match, it will return true so the rest of the commands can run
37+ modified_files=$( git diff --name-only $KOKORO_GITHUB_PULL_REQUEST_COMMIT $KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH )
38+ printf " Modified files:\n%s\n" " ${modified_files} "
39+
40+ # If root pom.xml is touched, run ITs on all the modules
41+ root_pom_modified=$( echo " ${modified_files} " | grep -e ' ^pom.xml$' || true)
42+ if [[ -n $root_pom_modified ]]; then
43+ module_list=$excluded_modules_string
44+ echo " Testing the entire monorepo"
45+ else
46+ directories=$( echo " ${modified_files} " | grep -e ' java-.*' || true)
47+ printf " Files in java modules:\n%s\n" " ${directories} "
48+ if [[ -n $directories ]]; then
49+ directories=$( echo " ${directories} " | cut -d ' /' -f1 | sort -u)
50+ for directory in $directories
51+ do
52+ dir_list+=($directory )
53+ done
54+ # Combine each entry with a comma
55+ module_list=$( IFS=, ; echo " ${dir_list[*]} " )
56+ printf " Module List:\n%s\n" " ${module_list} "
57+ fi
58+ fi
59+ }
60+
3061function assign_modules_to_job() {
3162 modules=$( mvn help:evaluate -Dexpression=project.modules | grep ' <.*>.*</.*>' | sed -e ' s/<.*>\(.*\)<\/.*>/\1/g' )
32- module_list =()
63+ maven_module_list =()
3364 num=0
3465 for module in $modules
3566 do
3667 # Add 1 as JOB_NUMBER is 1-indexed instead of 0-indexed
3768 mod_num=$(( num % NUM_JOBS + 1 ))
3869 if [[ ! " ${excluded_modules[*]} " =~ $module ]] && [[ $mod_num -eq $JOB_NUMBER ]]; then
39- module_list +=($module )
70+ maven_module_list +=($module )
4071 fi
4172 num=$(( num + 1 ))
4273 done
43- module_list=$( IFS=, ; echo " ${module_list [*]} " )
74+ module_list=$( IFS=, ; echo " ${maven_module_list [*]} " )
4475}
4576
46- excluded_modules=(' CoverageAggregator' ' google-cloud-gapic-bom' )
77+ function generate_excluded_module_string() {
78+ excluded_modules_list=()
79+ for excluded_module in " ${excluded_modules[@]} "
80+ do
81+ excluded_modules_list+=(" !${excluded_module} " )
82+ done
83+ excluded_modules_string=$( IFS=, ; echo " ${excluded_modules_list[*]} " )
84+ }
4785
48- mvn -B -pl " !google-cloud-gapic-bom,!CoverageAggregator" \
86+ # Generate excluded_modules_string
87+ generate_excluded_module_string
88+
89+ mvn -B -pl " ${excluded_modules_string} " \
4990 -ntp \
5091 -DtrimStackTrace=false \
5192 -Dclirr.skip=true \
70111RETURN_CODE=0
71112
72113case ${JOB_TYPE} in
73- test)
74- mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true
75- RETURN_CODE=$?
76- ;;
77- lint)
78- mvn com.coveo:fmt-maven-plugin:check -B -ntp
79- RETURN_CODE=$?
80- ;;
81- javadoc)
82- mvn javadoc:javadoc javadoc:test-javadoc -B -ntp
83- RETURN_CODE=$?
84- ;;
85114 integration)
86- TEST_ALL=false
87- # Find the files changed from when the PR branched to the last commit
88- # Filter for java modules and get all the unique elements
89- # grep returns 1 (error code) and exits the pipeline if there is no match
90- # If there is no match, it will return true so the rest of the commands can run
91- modified_files=$( git diff --name-only $KOKORO_GITHUB_PULL_REQUEST_COMMIT $KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH )
92- printf " Modified files:\n%s\n" " ${modified_files} "
93-
94- # If root pom.xml is touched, run ITs on all the modules
95- root_pom_modified=$( echo " ${modified_files} " | grep -e ' ^pom.xml$' || true)
96- if [[ -n $root_pom_modified ]]; then
97- TEST_ALL=true
98- echo " Testing the entire monorepo"
99- else
100- directories=$( echo " ${modified_files} " | grep -e ' java-.*' || true)
101- printf " Files in java modules:\n%s\n" " ${directories} "
102- if [[ -n $directories ]]; then
103- directories=$( echo " ${directories} " | cut -d ' /' -f1 | sort -u)
104- dir_list=()
105- for directory in $directories
106- do
107- dir_list+=($directory )
108- done
109- # Combine each entry with a comma
110- module_list=$( IFS=, ; echo " ${dir_list[*]} " )
111- fi
112- printf " Module List:\n%s\n" " ${module_list} "
113- fi
114-
115- if [ ${TEST_ALL} ]; then
116- mvn -B ${INTEGRATION_TEST_ARGS} \
117- -ntp \
118- -Penable-integration-tests \
119- -DtrimStackTrace=false \
120- -Dclirr.skip=true \
121- -Denforcer.skip=true \
122- -Dcheckstyle.skip=true \
123- -Dflatten.skip=true \
124- -Danimal.sniffer.skip=true \
125- -Djacoco.skip=true \
126- -DskipUnitTests=true \
127- -fae \
128- -T 1C \
129- verify
130- RETURN_CODE=$?
131- elif [[ -n $module_list ]]; then
115+ generate_modified_modules_list
116+ if [[ -n $module_list ]]; then
132117 printf " Running Integration Tests for:\n%s\n" " ${module_list} "
133118 mvn -B ${INTEGRATION_TEST_ARGS} \
134119 -pl " ${module_list} " \
@@ -232,10 +217,6 @@ case ${JOB_TYPE} in
232217 echo " no sample pom.xml found - skipping sample tests"
233218 fi
234219 ;;
235- clirr)
236- mvn -B -ntp -Denforcer.skip=true clirr:check
237- RETURN_CODE=$?
238- ;;
239220 * )
240221 ;;
241222esac
0 commit comments