@@ -41,28 +41,16 @@ val helmTemplateValidation by
4141
4242 val outputFile = helmTestReportsDir.get().file(" helm-template/validation.log" ).asFile
4343
44- doFirst {
45- outputFile.parentFile.mkdirs()
46- val outStream = outputFile.outputStream()
47- standardOutput = outStream
48- errorOutput = outStream
49- }
50-
51- commandLine =
52- listOf (
53- " sh" ,
54- " -c" ,
55- """
44+ runShellScript(
45+ """
5646 set -e
5747 for f in values.yaml ci/*.yaml; do
5848 echo "Validating helm template with ${' $' } f"
5949 helm template --debug --namespace polaris-ns --values ${' $' } f .
6050 done
61- """
62- .trimIndent(),
63- )
64-
65- checkExitCode(outputFile)
51+ """ ,
52+ outputFile,
53+ )
6654
6755 inputs.files(
6856 fileTree(projectDir) { include(" Chart.yaml" , " values.yaml" , " ci/*.yaml" , " templates/**/*" ) }
@@ -78,29 +66,17 @@ val helmUnitTest by
7866
7967 val outputFile = helmTestReportsDir.get().file(" helm-unit/test.log" ).asFile
8068
81- doFirst {
82- outputFile.parentFile.mkdirs()
83- val outStream = outputFile.outputStream()
84- standardOutput = outStream
85- errorOutput = outStream
86- }
87-
88- commandLine =
89- listOf (
90- " sh" ,
91- " -c" ,
92- """
69+ runShellScript(
70+ """
9371 set -e
9472 echo "====== Install helm-unittest plugin ======"
9573 helm plugin install https://github.com/helm-unittest/helm-unittest.git || true
9674
9775 echo "====== Run helm unit tests ======"
9876 helm unittest .
99- """
100- .trimIndent(),
101- )
102-
103- checkExitCode(outputFile)
77+ """ ,
78+ outputFile,
79+ )
10480
10581 inputs.files(
10682 fileTree(projectDir) { include(" Chart.yaml" , " values.yaml" , " templates/**/*" , " tests/**/*" ) }
@@ -116,25 +92,13 @@ val chartTestingLint by
11692
11793 val outputFile = helmTestReportsDir.get().file(" ct/lint.log" ).asFile
11894
119- doFirst {
120- outputFile.parentFile.mkdirs()
121- val outStream = outputFile.outputStream()
122- standardOutput = outStream
123- errorOutput = outStream
124- }
125-
126- commandLine =
127- listOf (
128- " sh" ,
129- " -c" ,
130- """
95+ runShellScript(
96+ """
13197 set -e
13298 ct lint --debug --charts .
133- """
134- .trimIndent(),
135- )
136-
137- checkExitCode(outputFile)
99+ """ ,
100+ outputFile,
101+ )
138102
139103 inputs.files(
140104 fileTree(projectDir) { include(" Chart.yaml" , " values.yaml" , " ci/*.yaml" , " templates/**/*" ) }
@@ -157,19 +121,10 @@ val buildMinikubeImages by
157121 val digestFile = helmTestReportsDir.get().file(" minikube-images/build.sha256" ).asFile
158122 val dockerFile = project(" :polaris-server" ).projectDir.resolve(" src/main/docker/Dockerfile.jvm" )
159123
160- doFirst {
161- outputFile.parentFile.mkdirs()
162- digestFile.parentFile.mkdirs()
163- val outStream = outputFile.outputStream()
164- standardOutput = outStream
165- errorOutput = outStream
166- }
124+ digestFile.parentFile.mkdirs()
167125
168- commandLine =
169- listOf (
170- " sh" ,
171- " -c" ,
172- """
126+ runShellScript(
127+ """
173128 set -e
174129 echo "====== Check if minikube is running ======"
175130 if ! minikube status >/dev/null 2>&1; then
@@ -188,11 +143,9 @@ val buildMinikubeImages by
188143 {
189144 docker inspect --format='{{.Id}}' apache/polaris:latest
190145 } > ${digestFile.relativeTo(workingDir)}
191- """
192- .trimIndent(),
193- )
194-
195- checkExitCode(outputFile)
146+ """ ,
147+ outputFile,
148+ )
196149
197150 dependsOn(" :polaris-server:quarkusBuild" )
198151
@@ -210,18 +163,8 @@ val chartTestingInstall by
210163
211164 val outputFile = helmTestReportsDir.get().file(" ct/install.log" ).asFile
212165
213- doFirst {
214- outputFile.parentFile.mkdirs()
215- val outStream = outputFile.outputStream()
216- standardOutput = outStream
217- errorOutput = outStream
218- }
219-
220- commandLine =
221- listOf (
222- " sh" ,
223- " -c" ,
224- """
166+ runShellScript(
167+ """
225168 set -eo pipefail
226169 echo "====== Check if minikube is running ======"
227170 if ! minikube status >/dev/null 2>&1; then
@@ -233,15 +176,13 @@ val chartTestingInstall by
233176 kubectl create namespace polaris-ns --dry-run=client -o yaml | kubectl apply -f -
234177
235178 echo "===== Install fixtures ======"
236- kubectl apply --namespace polaris-ns -f helm/polaris/ ci/fixtures
179+ kubectl apply --namespace polaris-ns -f ci/fixtures
237180
238181 echo "===== Run chart-testing install ======"
239182 ct install --namespace polaris-ns --debug --charts .
240- """
241- .trimIndent(),
242- )
243-
244- checkExitCode(outputFile)
183+ """ ,
184+ outputFile,
185+ )
245186
246187 dependsOn(buildMinikubeImages)
247188
@@ -259,25 +200,13 @@ val helmDocs by
259200
260201 val outputFile = helmTestReportsDir.get().file(" helm-docs/build.log" ).asFile
261202
262- doFirst {
263- outputFile.parentFile.mkdirs()
264- val outStream = outputFile.outputStream()
265- standardOutput = outStream
266- errorOutput = outStream
267- }
268-
269- commandLine =
270- listOf (
271- " sh" ,
272- " -c" ,
273- """
203+ runShellScript(
204+ """
274205 set -e
275206 helm-docs --chart-search-root=.
276- """
277- .trimIndent(),
278- )
279-
280- checkExitCode(outputFile)
207+ """ ,
208+ outputFile,
209+ )
281210
282211 inputs.files(fileTree(projectDir) { include(" Chart.yaml" , " values.yaml" , " README.md.gotmpl" ) })
283212
@@ -303,14 +232,21 @@ tasks.named("check") { dependsOn(test, intTest) }
303232
304233tasks.named(" assemble" ) { dependsOn(helmDocs) }
305234
306- fun Exec.checkExitCode (outputFile : File ) {
307- isIgnoreExitValue = true
235+ fun Exec.runShellScript (script : String , outputFile : File ) {
236+ doFirst {
237+ outputFile.parentFile.mkdirs()
238+ val outStream = outputFile.outputStream()
239+ standardOutput = outStream
240+ errorOutput = outStream
241+ }
242+ commandLine = listOf (" sh" , " -c" , script.trimIndent())
243+ this .isIgnoreExitValue = true
308244 doLast {
309245 val exitValue = executionResult.get().exitValue
310246 if (exitValue != 0 ) {
311- logger.error(" Shell script failed with exit code $exitValue ." )
312- logger.error(" To identify the cause of the failure, inspect the logs:" )
313- logger.error(outputFile.absolutePath)
247+ this . logger.error(" Shell script failed with exit code $exitValue ." )
248+ this . logger.error(" To identify the cause of the failure, inspect the logs:" )
249+ this . logger.error(outputFile.absolutePath)
314250 throw GradleException (" Shell script failed with exit code $exitValue " )
315251 }
316252 }
0 commit comments