Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port entry.sh output to main.js #32

Merged
merged 1 commit into from
Dec 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,49 @@ async function main() {
discardDescriptor: true,
});

fs.mkdirSync(homedir + '/.kube', {
recursive: true,
});
fs.appendFileSync(
homedir + '/.kube/config',
"\r\n\r\n" + process.env.INPUT_KUBECONFIG,
{
mode: 0o600,
}
);
const kubeConfigLocation = homedir + '/.kube/config';
const kubeConfigExists = fs.existsSync(kubeConfigLocation);
if (kubeConfigExists) {
console.log("\033[36mExisting kubeconfig found, using that and ignoring input\033[0m");
} else {
console.log("\033[36mUsing kubeconfig from input\033[0m");
fs.mkdirSync(homedir + '/.kube', {
recursive: true,
});
fs.appendFileSync(
kubeConfigLocation,
"\r\n\r\n" + process.env.INPUT_KUBECONFIG,
{
mode: 0o600,
}
);
}

console.log("\033[36mPreparing helm execution\033[0m");
fs.appendFileSync(execShFile.name, process.env.INPUT_EXEC);

await waitFile({
resources: [
homedir + '/.kube/config',
kubeConfigLocation,
execShFile.name,
],
});

try {
console.log("\033[36mExecuting helm\033[0m");
const result = execFileSync(execShFile.name).toString();
console.log(result);
console.log('::set-output name=helm_output::' + result.split('%').join('%25').split('\n').join('%0A').split('\r').join('%0D'));
} catch (error) {
process.exit(1);
} finally {
console.log("\033[36mCleaning up: \033[0m");
fs.unlinkSync(execShFile.name);
console.log("\033[36m - exec ✅ \033[0m");
if (!kubeConfigExists) {
fs.unlinkSync(kubeConfigLocation);
console.log("\033[36m - kubeconfig ✅ \033[0m");
}
}
}

Expand Down