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 run() {
try {
// Tripple check it's Windows process
// Can't install nuget.exe for Ubuntu image etc..
const IS_WINDOWS = process.platform === 'win32';
if(IS_WINDOWS === false){
core.setFailed("Nuget.exe only works for Windows.");
return;
}
// Try & find tool in cache
let directoryToAddToPath:string;
directoryToAddToPath = await tc.find("nuget", "latest");
if(directoryToAddToPath){
core.debug(`Found local cached tool at ${directoryToAddToPath} adding that to path`);
await core.addPath(directoryToAddToPath);
return;
}
// Download latest Nuget.exe
core.debug("Downloading Nuget tool");
const nugetPath = await tc.downloadTool("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe");
// Rename the file which is a GUID without extension
var folder = path.dirname(nugetPath);
var fullPath = path.join(folder, "nuget.exe");
fs.renameSync(nugetPath, fullPath);
async function installInlineScan(version) {
let scanScriptPath = cache.find(scanScript, version);
if (!scanScriptPath) {
// Not found, install it
scanScriptPath = await downloadInlineScan(version);
}
// Add tool to path for this and future actions to use
core.addPath(scanScriptPath);
}
return __awaiter(this, void 0, void 0, function* () {
if (core.getInput('kubectl-version')) {
const version = core.getInput('kubect-version');
kubectlPath = toolCache.find('kubectl', version);
if (!kubectlPath) {
kubectlPath = yield installKubectl(version);
}
}
else {
kubectlPath = yield 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${utils_1.getExecutableExtension()}`);
}
}
});
async function downloadKubectl(version: string): Promise {
let cachedToolpath = toolCache.find(kubectlToolName, version);
let kubectlDownloadPath = '';
if (!cachedToolpath) {
try {
kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version));
} catch (exception) {
throw new Error('DownloadKubectlFailed');
}
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
}
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
fs.chmodSync(kubectlPath, '777');
return kubectlPath;
}
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;
}
return __awaiter(this, void 0, void 0, function* () {
kubectlPath = yield 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 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()}`);
}
export async function installDMD(dmdVersion: string): Promise {
const match = /^(?:2\.(\d{3})(\.\d+(-[-+_.a-zA-Z0-9]+)?)?|master)$/.exec(dmdVersion);
if (!match)
throw new Error("Invalid DMD version " + dmdVersion);
if (process.platform != "win32" && process.platform != "linux" && process.platform != "darwin") {
throw new Error("Unsupported platform to install dmd on: " + process.platform);
}
if (dmdVersion !== "master") {
const existingPath = tc.find("dmd", dmdVersion);
if (existingPath) {
return existingPath;
}
}
let url: string = "";
let type: "7z" | "zip" | "tarxz" | undefined = undefined;
const dst = path.join(process.cwd(), "dmd_" + dmdVersion);
if (dmdVersion == "master") {
switch (process.platform) {
case "win32":
type = "7z";
url = `http://downloads.dlang.org/nightlies/dmd-master/dmd.master.windows.7z`;
break;
case "linux":
return __awaiter(this, void 0, void 0, function* () {
let cachedToolpath = toolCache.find(kubectlToolName, version);
let kubectlDownloadPath = '';
if (!cachedToolpath) {
try {
kubectlDownloadPath = yield toolCache.downloadTool(getkubectlDownloadURL(version));
}
catch (exception) {
throw new Error('DownloadKubectlFailed');
}
cachedToolpath = yield toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
}
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
fs.chmodSync(kubectlPath, '777');
return kubectlPath;
});
}
return __awaiter(this, void 0, void 0, function* () {
if (core.getInput('kubectl-version')) {
const version = core.getInput('kubect-version');
kubectlPath = toolCache.find('kubectl', version);
if (!kubectlPath) {
kubectlPath = yield installKubectl(version);
}
}
else {
kubectlPath = yield 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${utility_1.getExecutableExtension()}`);
}
}
});