@@ -27,25 +27,66 @@ source ${scriptDir}/common.sh
27
27
mkdir -p ${HOME} /.m2
28
28
cp settings.xml ${HOME} /.m2
29
29
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
+
30
61
function assign_modules_to_job() {
31
62
modules=$( mvn help:evaluate -Dexpression=project.modules | grep ' <.*>.*</.*>' | sed -e ' s/<.*>\(.*\)<\/.*>/\1/g' )
32
- module_list =()
63
+ maven_module_list =()
33
64
num=0
34
65
for module in $modules
35
66
do
36
67
# Add 1 as JOB_NUMBER is 1-indexed instead of 0-indexed
37
68
mod_num=$(( num % NUM_JOBS + 1 ))
38
69
if [[ ! " ${excluded_modules[*]} " =~ $module ]] && [[ $mod_num -eq $JOB_NUMBER ]]; then
39
- module_list +=($module )
70
+ maven_module_list +=($module )
40
71
fi
41
72
num=$(( num + 1 ))
42
73
done
43
- module_list=$( IFS=, ; echo " ${module_list [*]} " )
74
+ module_list=$( IFS=, ; echo " ${maven_module_list [*]} " )
44
75
}
45
76
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
+ }
47
85
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} " \
49
90
-ntp \
50
91
-DtrimStackTrace=false \
51
92
-Dclirr.skip=true \
70
111
RETURN_CODE=0
71
112
72
113
case ${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
- ;;
85
114
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
132
117
printf " Running Integration Tests for:\n%s\n" " ${module_list} "
133
118
mvn -B ${INTEGRATION_TEST_ARGS} \
134
119
-pl " ${module_list} " \
@@ -232,10 +217,6 @@ case ${JOB_TYPE} in
232
217
echo " no sample pom.xml found - skipping sample tests"
233
218
fi
234
219
;;
235
- clirr)
236
- mvn -B -ntp -Denforcer.skip=true clirr:check
237
- RETURN_CODE=$?
238
- ;;
239
220
* )
240
221
;;
241
222
esac
0 commit comments