How to use the @actions/tool-cache.find function in @actions/tool-cache

To help you get started, we’ve selected a few @actions/tool-cache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github warrenbuckley / Setup-Nuget / src / main.ts View on Github external
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);
github anchore / scan-action / index.js View on Github external
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);
}
github Azure / k8s-actions / k8s-deploy / lib / run.js View on Github external
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()}`);
            }
        }
    });
github Azure / k8s-actions / setup-kubectl / src / run.ts View on Github external
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;
}
github Azure / k8s-actions / k8s-set-context / src / login.ts View on Github external
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;
}
github Azure / k8s-actions / k8s-create-secret / lib / run.js View on Github external
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()}`);
    });
}
github Azure / k8s-actions / k8s-create-secret / src / run.ts View on Github external
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()}`);
}
github WebFreak001 / setup-dmd / src / main.ts View on Github external
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":
github Azure / k8s-actions / setup-kubectl / lib / run.js View on Github external
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;
    });
}
github Azure / k8s-deploy / lib / run.js View on Github external
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()}`);
            }
        }
    });