Skip to content

Commit 09e638e

Browse files
committed
more checks
1 parent cebb81a commit 09e638e

File tree

1 file changed

+123
-35
lines changed

1 file changed

+123
-35
lines changed

helm/polaris/build.gradle.kts

Lines changed: 123 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,107 @@ dependencies { runtimeServerDistribution(project(":polaris-server", "distributio
3434

3535
val helmTestReportsDir = layout.buildDirectory.dir("reports")
3636

37+
private val missingDependencyExitCode = -42
38+
39+
val helmChecks =
40+
"""
41+
echo "====== Check if helm is installed ======"
42+
if ! command -v helm >/dev/null 2>&1; then
43+
echo "helm is not installed."
44+
# Check if we're on macOS
45+
if [[ "${'$'}(uname -s)" == "Darwin" ]]; then
46+
# Check if brew is available
47+
if command -v brew >/dev/null 2>&1; then
48+
echo "Installing helm using Homebrew..."
49+
brew install helm
50+
else
51+
echo "WARNING: Homebrew is not installed. Cannot auto-install helm."
52+
echo "Please install Homebrew from https://brew.sh/ or install helm manually."
53+
exit $missingDependencyExitCode
54+
fi
55+
else
56+
echo "WARNING: helm is not installed."
57+
echo "To install helm, see https://helm.sh/docs/intro/install/"
58+
exit $missingDependencyExitCode
59+
fi
60+
fi
61+
"""
62+
63+
val chartTestingChecks =
64+
"""
65+
echo "====== Check if chart-testing is installed ======"
66+
if ! command -v ct >/dev/null 2>&1; then
67+
echo "chart-testing is not installed."
68+
# Check if we're on macOS
69+
if [[ "${'$'}(uname -s)" == "Darwin" ]]; then
70+
# Check if brew is available
71+
if command -v brew >/dev/null 2>&1; then
72+
echo "Installing chart-testing using Homebrew..."
73+
brew install chart-testing
74+
else
75+
echo "WARNING: Homebrew is not installed. Cannot auto-install chart-testing."
76+
echo "Please install Homebrew from https://brew.sh/ or install chart-testing manually."
77+
exit $missingDependencyExitCode
78+
fi
79+
else
80+
echo "WARNING: chart-testing is not installed."
81+
echo "To install chart-testing, see https://github.com/helm/chart-testing."
82+
exit $missingDependencyExitCode
83+
fi
84+
fi
85+
"""
86+
87+
val minikubeChecks =
88+
"""
89+
echo "====== Check if Minikube is installed ======"
90+
if ! command -v minikube >/dev/null 2>&1; then
91+
echo "Minikube is not installed."
92+
echo "To install minikube, see https://minikube.sigs.k8s.io/docs/start/."
93+
exit $missingDependencyExitCode
94+
fi
95+
96+
echo "====== Check if Minikube is running ======"
97+
if ! minikube status >/dev/null 2>&1; then
98+
echo "Minikube is not running. Starting minikube..."
99+
minikube start
100+
fi
101+
"""
102+
103+
val kubectlChecks =
104+
"""
105+
echo "====== Check if kubectl is installed ======"
106+
if ! command -v kubectl >/dev/null 2>&1; then
107+
echo "kubectl is not installed."
108+
echo "To install kubectl, see https://kubernetes.io/docs/tasks/tools/"
109+
exit $missingDependencyExitCode
110+
fi
111+
"""
112+
113+
val helmDocsChecks =
114+
"""
115+
echo "====== Check if helm-docs is installed ======"
116+
if ! command -v helm-docs >/dev/null 2>&1; then
117+
echo "helm-docs is not installed."
118+
119+
# Check if we're on macOS
120+
if [[ "${'$'}(uname -s)" == "Darwin" ]]; then
121+
# Check if brew is available
122+
if command -v brew >/dev/null 2>&1; then
123+
echo "Installing helm-docs using Homebrew..."
124+
brew install norwoodj/tap/helm-docs
125+
else
126+
echo "WARNING: Homebrew is not installed. Cannot auto-install helm-docs."
127+
echo "Please install Homebrew from https://brew.sh/ or install helm-docs manually."
128+
exit $missingDependencyExitCode
129+
fi
130+
else
131+
echo "WARNING: helm-docs is not installed. Skipping documentation generation."
132+
echo "To install helm-docs on Linux, download from: https://github.com/norwoodj/helm-docs/releases"
133+
exit $missingDependencyExitCode
134+
fi
135+
fi
136+
"""
137+
37138
val helmTemplateValidation by
38139
tasks.registering(Exec::class) {
39140
group = "verification"
@@ -44,6 +145,7 @@ val helmTemplateValidation by
44145
runShellScript(
45146
"""
46147
set -e
148+
${helmChecks.trimIndent()}
47149
for f in values.yaml ci/*.yaml; do
48150
echo "Validating helm template with ${'$'}f"
49151
helm template --debug --namespace polaris-ns --values ${'$'}f .
@@ -69,6 +171,7 @@ val helmUnitTest by
69171
runShellScript(
70172
"""
71173
set -e
174+
${helmChecks.trimIndent()}
72175
echo "====== Install helm-unittest plugin ======"
73176
helm plugin install https://github.com/helm-unittest/helm-unittest.git || true
74177
@@ -95,6 +198,8 @@ val chartTestingLint by
95198
runShellScript(
96199
"""
97200
set -e
201+
${helmChecks.trimIndent()}
202+
${chartTestingChecks.trimIndent()}
98203
ct lint --debug --charts .
99204
""",
100205
outputFile,
@@ -126,11 +231,8 @@ val buildMinikubeImages by
126231
runShellScript(
127232
"""
128233
set -e
129-
echo "====== Check if minikube is running ======"
130-
if ! minikube status >/dev/null 2>&1; then
131-
echo "Minikube is not running. Starting minikube..."
132-
minikube start
133-
fi
234+
235+
${minikubeChecks.trimIndent()}
134236
135237
echo "====== Set up docker environment and build images ======"
136238
eval $(minikube -p minikube docker-env)
@@ -166,11 +268,11 @@ val chartTestingInstall by
166268
runShellScript(
167269
"""
168270
set -eo pipefail
169-
echo "====== Check if minikube is running ======"
170-
if ! minikube status >/dev/null 2>&1; then
171-
echo "Minikube is not running. Starting minikube..."
172-
minikube start
173-
fi
271+
272+
${helmChecks.trimIndent()}
273+
${minikubeChecks.trimIndent()}
274+
${chartTestingChecks.trimIndent()}
275+
${kubectlChecks.trimIndent()}
174276
175277
echo "====== Create namespace if it doesn't exist ======"
176278
kubectl create namespace polaris-ns --dry-run=client -o yaml | kubectl apply -f -
@@ -204,27 +306,8 @@ val helmDocs by
204306
"""
205307
set -e
206308
207-
echo "====== Check if helm-docs is installed ======"
208-
if ! command -v helm-docs >/dev/null 2>&1; then
209-
echo "helm-docs is not installed."
210-
211-
# Check if we're on macOS
212-
if [[ "${'$'}(uname -s)" == "Darwin" ]]; then
213-
# Check if brew is available
214-
if command -v brew >/dev/null 2>&1; then
215-
echo "Installing helm-docs using Homebrew..."
216-
brew install norwoodj/tap/helm-docs
217-
else
218-
echo "WARNING: Homebrew is not installed. Cannot auto-install helm-docs."
219-
echo "Please install Homebrew from https://brew.sh/ or install helm-docs manually."
220-
exit 0
221-
fi
222-
else
223-
echo "WARNING: helm-docs is not installed. Skipping documentation generation."
224-
echo "To install helm-docs on Linux, download from: https://github.com/norwoodj/helm-docs/releases"
225-
exit 0
226-
fi
227-
fi
309+
${helmChecks.trimIndent()}
310+
${helmDocsChecks.trimIndent()}
228311
229312
echo "====== Generate Helm documentation ======"
230313
helm-docs --chart-search-root=.
@@ -263,14 +346,19 @@ fun Exec.runShellScript(script: String, outputFile: File) {
263346
standardOutput = outStream
264347
errorOutput = outStream
265348
}
266-
commandLine = listOf("sh", "-c", script.trimIndent())
349+
commandLine = listOf("bash", "-c", script.trimIndent())
267350
this.isIgnoreExitValue = true
268351
doLast {
269352
val exitValue = executionResult.get().exitValue
270353
if (exitValue != 0) {
271-
this.logger.error("Shell script failed with exit code $exitValue:\n")
272-
outputFile.readLines().forEach { this.logger.error(it) }
273-
throw GradleException("Shell script failed with exit code $exitValue")
354+
if (exitValue == missingDependencyExitCode) {
355+
this.logger.warn("Missing required executable, skipping task:")
356+
outputFile.readLines().forEach { this.logger.warn(it) }
357+
} else {
358+
this.logger.error("Shell script failed with exit code $exitValue:\n")
359+
outputFile.readLines().forEach { this.logger.error(it) }
360+
throw GradleException("Shell script failed with exit code $exitValue")
361+
}
274362
}
275363
}
276364
}

0 commit comments

Comments
 (0)