Skip to content

Commit 3d75155

Browse files
committed
Do not leave deno-bundle.js after failed helm deno push
1 parent 9fca209 commit 3d75155

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

e2e-tests/e2e.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,36 @@ Deno.test({
494494
},
495495
})
496496

497+
Deno.test({
498+
name: "should clean deno-bundle.js if push wasn't successful",
499+
ignore: !runAllTests,
500+
async fn() {
501+
const chartPath = path.join(chartsBin, "one-service")
502+
const denoBundlePath = path.join(chartPath, "deno-bundle.js")
503+
504+
try {
505+
const { status, stdout, stderr } = await runHelmDeno([
506+
"push",
507+
chartPath,
508+
"http://127.0.0.1:1",
509+
])
510+
511+
if (status.success) {
512+
assertEquals(status.success, false, "should not successfully push")
513+
}
514+
515+
const isDenoBundleExists = await fs.exists(denoBundlePath)
516+
assertEquals(
517+
isDenoBundleExists,
518+
false,
519+
"should not have left temporary file deno-bundle.js"
520+
)
521+
} finally {
522+
await removeIfExists(denoBundlePath)
523+
}
524+
},
525+
})
526+
497527
Deno.test({
498528
name: "should use deno-bundle.js if `--deno-bundle require` have been passed",
499529
async fn() {

src/helm/execute.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export async function helmExecute(args: readonly string[]): Promise<void> {
1+
export async function helmExecute(
2+
args: readonly string[],
3+
{ autoExitOnError = false }: { autoExitOnError?: boolean } = {}
4+
): Promise<{ exitCode?: number }> {
25
const helm = Deno.env.get("HELM_BIN") as string
36
const cmd = Deno.run({
47
cmd: [helm, ...args],
@@ -8,6 +11,11 @@ export async function helmExecute(args: readonly string[]): Promise<void> {
811

912
const status = await cmd.status()
1013
if (!status.success) {
11-
Deno.exit(status.code)
14+
if (autoExitOnError) {
15+
Deno.exit(status.code)
16+
}
17+
return { exitCode: status.code }
1218
}
19+
20+
return {}
1321
}

src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,30 @@ async function main() {
9494
)
9595

9696
if (command.length === 1 && command[0] === "push") {
97+
let helmExecuteResult: { exitCode?: number } = {}
9798
try {
99+
console.log("bundleChart")
98100
await bundleChart(chartLocation, options)
99-
await helmExecute(["push", chartLocation, ...helmRestArgs])
101+
console.log("helmExecute")
102+
helmExecuteResult = await helmExecute([
103+
"push",
104+
chartLocation,
105+
...helmRestArgs,
106+
])
100107
} finally {
101108
await cleanupBundle(chartLocation)
102109
}
110+
111+
if (helmExecuteResult.exitCode) {
112+
Deno.exit(helmExecuteResult.exitCode)
113+
}
114+
103115
return
104116
}
105117

106118
const lastCommand = command[command.length - 1]
107119
if (command.length === 0 || !supportedCommands.includes(lastCommand)) {
108-
await helmExecute(args)
120+
await helmExecute(args, { autoExitOnError: true })
109121
return
110122
}
111123

@@ -150,7 +162,7 @@ async function main() {
150162
...helmRestArgs,
151163
]
152164
debug(`Executing: ${helmExecuteArgs.join(" ")}`)
153-
await helmExecute(helmExecuteArgs)
165+
await helmExecute(helmExecuteArgs, { autoExitOnError: true })
154166

155167
debug("Success")
156168
} catch (err) {

0 commit comments

Comments
 (0)