Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getKubectlPath() {
let kubectlPath = await io.which('kubectl', false);
if (!kubectlPath) {
const allVersions = toolCache.findAllVersions('kubectl');
kubectlPath = allVersions.length > 0 ? toolCache.find('kubectl', allVersions[0]) : '';
if (!kubectlPath) {
throw new Error('Kubectl is not installed');
}
kubectlPath = path.join(kubectlPath, `kubectl${getExecutableExtension()}`);
}
return kubectlPath;
}
async function setKubectlPath() {
if (core.getInput('kubectl-version')) {
const version = core.getInput('kubect-version');
kubectlPath = toolCache.find('kubectl', version);
if (!kubectlPath) {
kubectlPath = await installKubectl(version);
}
} else {
kubectlPath = await io.which('kubectl', false);
if (!kubectlPath) {
const allVersions = toolCache.findAllVersions('kubectl');
kubectlPath = allVersions.length > 0 ? toolCache.find('kubectl', allVersions[0]) : '';
if (!kubectlPath) {
throw new Error('Kubectl is not installed, either add install-kubectl action or provide "kubectl-version" input to download kubectl');
}
kubectlPath = path.join(kubectlPath, `kubectl${getExecutableExtension()}`);
}
}
}
async function checkAndSetKubectlPath() {
kubectlPath = await io.which('kubectl', false);
if (kubectlPath) {
return;
}
const allVersions = toolCache.findAllVersions('kubectl');
kubectlPath = allVersions.length > 0 ? toolCache.find('kubectl', allVersions[0]) : '';
if (!kubectlPath) {
throw new Error('Kubectl is not installed');
}
kubectlPath = path.join(kubectlPath, `kubectl${getExecutableExtension()}`);
}
async function setKubectlPath() {
if (core.getInput('kubectl-version')) {
const version = core.getInput('kubect-version');
kubectlPath = toolCache.find('kubectl', version);
if (!kubectlPath) {
kubectlPath = await installKubectl(version);
}
} else {
kubectlPath = await io.which('kubectl', false);
if (!kubectlPath) {
const allVersions = toolCache.findAllVersions('kubectl');
kubectlPath = allVersions.length > 0 ? toolCache.find('kubectl', allVersions[0]) : '';
if (!kubectlPath) {
throw new Error('Kubectl is not installed, either add install-kubectl action or provide "kubectl-version" input to download kubectl');
}
kubectlPath = path.join(kubectlPath, `kubectl${getExecutableExtension()}`);
}
}
}