10
10
# #L%
11
11
# ##
12
12
13
+ set -o pipefail
13
14
echo -e " \n\n **** TESTING ARCHETYPE GENERATION **** \n\n"
14
15
15
16
if [ $# -ne 1 ]; then
21
22
mkdir -p target/temp
22
23
cd target/temp
23
24
25
+ # ---
26
+ # # Replacement for `sed -i` that formats the command correctly for MacOS and Linux
27
+ # #
28
+ # # @args: $1 and $2 are passed in unchanged to `sed`
29
+ # ---
30
+ function sub {
31
+ if [[ $OSTYPE == " darwin" * ]]; then
32
+ sed -i ' ' " $1 " " $2 " || exit 1
33
+ else
34
+ sed -i " $1 " " $2 " || exit 1
35
+ fi
36
+ }
37
+
38
+ # ---
39
+ # # Escapes the contents of a stdin for use with a `sed` substitution command. Namely ensures dollar signs, new lines
40
+ # # and backslashes are escaped.
41
+ # #
42
+ # # @stdin: the content to escape
43
+ # # @stdout: the input with '$', '\', and '\n' escaped
44
+ # ---
45
+ function esc {
46
+ # sed is used for a straightforward substitution of \ and $
47
+ # awk is used to escape newlines. Essentially, replaces the newlines between lines of input with a backslash and newline.
48
+ # Hence ORS (output record sep) is `\\\n`. However, because trailing newlines are always chomped in pipes, the last
49
+ # newline in the input must not be escaped. Therfore, input is buffered by one line in the `last` var so we can turn set
50
+ # the ORS to blank for the final line.
51
+ sed ' s/\([\/\$]\)/\\\1/g' | awk ' NR > 1 {ORS="\\\n"} END {ORS=""; print last} {print last} {last=$0}' ORS=' '
52
+ }
53
+
24
54
function updatePomBasedOnChildDirs {
25
55
# The 'TODO' text line that we're going to replace in the file
26
56
# should be passed in as the first param to this method. i.e.
27
57
# updatePomBasedOnChildDirs '<!-- TODO: this is where manual actions go -->'
28
58
todoText=$1
29
-
30
- modules=" "
59
+ modules=" "
31
60
for d in * / ; do
32
61
if [ $d != " target/" ]; then
33
62
# Drop / from the end of the directory
34
63
d=" ${d/ \/ / } "
35
- modules+=" <module>$d </module>"
64
+ modules+=" <module>$d </module>" $' \n '
36
65
fi
37
66
done
38
67
39
68
echo -e " \nINFO: Adding \n\t$modules \n\tto $PWD /pom.xml\n"
40
- fileContents=` cat pom.xml`
41
- fileContents=" ${fileContents/ $todoText / $modules } "
69
+ # command substitution trims trailing newlines so add it back
70
+ sub " s/$todoText /$( esc <<< " $modules" ) /" pom.xml
71
+ }
42
72
43
- # NOTE - the formatting get's all messed up
44
- echo -e $fileContents > pom.xml
73
+ # ---
74
+ # # Runs maven build and captures any manual actions for adding Fermenter executions to the deploy POM, then updates the
75
+ # # deploy POM based on the detected manual actions.
76
+ # ---
77
+ function runBuildAndUpdateDeploy {
78
+ deployInsert=" <!-- Add executions for each deployment module -->"
79
+ outputstart=' executions to test-generator-deploy'
80
+ outputend=' \[WARNING\]'
81
+ # $outputstart match at end ensures the match line isn't captured. NF ensures blank lines aren't captured.
82
+ execs=$( ./mvnw clean install | tee /dev/tty | \
83
+ awk " BEGIN {output=0} /$outputend / {output=0} NF && output {print} /$outputstart / {output=1}" ) \
84
+ || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
85
+ if [ -n " $execs " ]; then
86
+ # re-adding insert comment allows for subsequent insertions
87
+ execs=$deployInsert $' \n ' $execs
88
+ execs=$( esc <<< " $execs" )
89
+ echo -e " \n INFO: Adding execution profiles to deploy POM: \n$execs "
90
+ sub " s/$deployInsert /$execs /" test-generator-deploy/pom.xml
91
+ fi
45
92
}
46
93
47
94
package=' com.bah.aiops'
@@ -61,7 +108,7 @@ mvn archetype:generate -B \
61
108
-DmavenRepositoryUrl=https://repo1.maven.org/maven2 \
62
109
-DmavenSnapshotRepositoryUrl=https://s01.oss.sonatype.org/content/repositories/snapshots
63
110
64
- cd test-generator/
111
+ cd test-generator/ || exit
65
112
66
113
# Add pipelines files necessary for testing.
67
114
@@ -201,49 +248,41 @@ echo "{
201
248
echo -e " \n# maven-suppress-warnings" >> Tiltfile
202
249
203
250
echo -e " \nINFO: Running full build to generate project structure\n"
204
- ./mvnw clean install || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n ' ; exit 1 ; }
251
+ runBuildAndUpdateDeploy
205
252
206
-
207
- cd test-generator-shared/
253
+ cd test-generator-shared/ || exit
208
254
updatePomBasedOnChildDirs " <!-- TODO: replace with your project-specific modules here -->"
209
255
210
- cd ../test-generator-docker/
256
+ cd ../test-generator-docker/ || exit
211
257
updatePomBasedOnChildDirs " <!-- TODO: Add docker modules here -->"
212
258
213
- cd ../test-generator-pipelines/
259
+ cd ../test-generator-pipelines/ || exit
214
260
updatePomBasedOnChildDirs " <!-- TODO: replace with your pipeline-specific modules here -->"
215
261
216
262
cd ..
217
263
218
264
echo -e " \nINFO: Generating project structure for pipelines and data records\n"
219
- ./mvnw clean install || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n ' ; exit 1 ; }
265
+ runBuildAndUpdateDeploy
220
266
221
- cd test-generator-pipelines/example-machine-learning-pipeline/
267
+ cd test-generator-pipelines/example-machine-learning-pipeline/ || exit
222
268
updatePomBasedOnChildDirs " <!-- TODO: replace with your step-specific modules here -->"
223
269
224
270
cd ../..
225
271
226
272
echo -e " \nINFO: Generating project structure for ml pipelines\n"
227
- ./mvnw clean install || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
228
-
229
-
230
- echo -e " \nINFO: updating the test-generator-deploy/pom.xml based on static code as it's hard to predict without folder structure\n"
231
- executions=` cat ../../../extensions-to-add-to-archetype_test-generator-deploy_pom.xml`
232
-
233
- fileContents=` cat test-generator-deploy/pom.xml`
234
- todoText=" <!-- Add executions for each deployment module -->"
235
- fileContents=" ${fileContents/ $todoText / $executions } "
236
- echo -e $fileContents > test-generator-deploy/pom.xml
237
-
273
+ runBuildAndUpdateDeploy
238
274
275
+ echo -e " \nINFO: updating the test-generator-deploy/pom.xml based on static code as it's hard to predict\n"
276
+ plugins=$( esc < ../../../plugins-to-add-to-archetype_test-generator-deploy_pom.xml)
277
+ sub " s/ *<\/plugins>/$plugins <\/plugins>/" test-generator-deploy/pom.xml
239
278
240
279
echo -e " \nINFO: Running full build to check that the build passes w/o any manual actions needed\n"
241
- ./mvnw clean install || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; } > maven-build.log
242
- buildLog=` cat maven-build.log`
243
- if [[ $buildLog == * " MANUAL ACTION NEEDED" * ]]; then
280
+ # NOTE: because fermenter results are cached, the build-cache will hide remaining manual actions that were missed in previous steps
281
+ ./mvnw clean install -Dmaven.build.cache.skipCache -Dfermenter.display.message.keys=true | tee /dev/tty | awk ' /WARNING/ {print}' > maven-build.log \
282
+ || { echo -e ' \n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
283
+ if grep -iq ' Manual action' maven-build.log; then
244
284
echo -e " \n\n **** ERROR: Manual action still found in build **** \n Look at **archetype/target/temp/test-generator/maven-build.log** to see what the problem was. \n\n"
245
285
exit 1
246
286
else
247
287
echo -e " \n\n **** SUCCESS: Completed the full build successfully ****\n\n"
248
288
fi
249
-
0 commit comments