How to use the @actions/tool-cache.extractZip 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 r-lib / actions / setup-pandoc / src / setup-pandoc.ts View on Github external
try {
    downloadPath = await tc.downloadTool(downloadUrl);
  } catch (error) {
    throw `Failed to download Pandoc ${version}: ${error}`;
  }

  //
  // Extract
  //
  let extPath: string = tempDirectory;
  if (!extPath) {
    throw new Error("Temp directory not set");
  }

  extPath = await tc.extractZip(downloadPath);

  const toolPath = await tc.cacheDir(extPath, "pandoc", version);

  // It extracts to this folder
  const toolRoot = path.join(
    toolPath,
    util.format("pandoc-%s-windows-x86_64", version)
  );

  core.addPath(toolRoot);
}
github arduino / setup-arduino-cli / src / installer.ts View on Github external
"https://github.com/Arduino/arduino-cli/releases/download/%s/%s",
    version,
    fileName
  );
  let downloadPath: string | null = null;
  try {
    downloadPath = await tc.downloadTool(downloadUrl);
  } catch (error) {
    core.debug(error);
    throw `Failed to download version ${version}: ${error}`;
  }

  // Extract
  let extPath: string | null = null;
  if (osPlat == "win32") {
    extPath = await tc.extractZip(downloadPath);
  } else {
    extPath = await tc.extractTar(downloadPath);
  }

  // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded
  return await tc.cacheDir(extPath, "arduino-cli", version);
}
github Geertvdc / setup-hub / src / installer.ts View on Github external
async function extractFiles(
  file: string,
  fileEnding: string,
  destinationFolder: string
): Promise {
  const stats = fs.statSync(file);
  if (!stats) {
    throw new Error(`Failed to extract ${file} - it doesn't exist`);
  } else if (stats.isDirectory()) {
    throw new Error(`Failed to extract ${file} - it is a directory`);
  }

  if ('.tgz' === fileEnding) {
    await tc.extractTar(file, destinationFolder);
  } else if ('.zip' === fileEnding) {
    await tc.extractZip(file, destinationFolder);
  } else {
    // fall through and use sevenZip
    await tc.extract7z(file, destinationFolder);
  }
}
github peaceiris / actions-hugo / src / installer.ts View on Github external
let baseLocation: string;
    if (process.platform === 'win32') {
      baseLocation = process.env['USERPROFILE'] || 'C:\\';
    } else {
      baseLocation = `${process.env.HOME}`;
    }
    const hugoPath: string = path.join(baseLocation, 'hugobin');
    await io.mkdirP(hugoPath);
    core.addPath(hugoPath);

    // Download and extract Hugo binary
    await io.mkdirP(tempDir);
    const hugoAssets: string = await tc.downloadTool(hugoURL);
    let hugoBin: string = '';
    if (osName === 'Windows') {
      const hugoExtractedFolder: string = await tc.extractZip(
        hugoAssets,
        tempDir
      );
      hugoBin = `${hugoExtractedFolder}/hugo.exe`;
    } else {
      const hugoExtractedFolder: string = await tc.extractTar(
        hugoAssets,
        tempDir
      );
      hugoBin = `${hugoExtractedFolder}/hugo`;
    }
    await io.mv(hugoBin, hugoPath);
  } catch (error) {
    core.setFailed(error.message);
  }
}
github mihails-strasuns / setup-dlang / src / main.ts View on Github external
async function extract(format: string, archive: string, into?: string) {
    if (format.endsWith(".7z"))
        return await tc.extract7z(archive, into);
    else if (format.endsWith(".zip"))
        return await tc.extractZip(archive, into);
    else if (/\.tar(\.\w+)?$/.test(format))
        return await tc.extractTar(archive, into, 'x');

    throw new Error("unsupported archive format: " + format);
}
github GoogleCloudPlatform / github-actions / setup-gcloud / src / download-util.ts View on Github external
export async function downloadAndExtractTool(url: string): Promise {
  const downloadPath = await toolCache.downloadTool(url);
  let extractedPath: string;
  if (url.indexOf('.zip') != -1) {
    extractedPath = await toolCache.extractZip(downloadPath);
  } else if (url.indexOf('.tar.gz') != -1) {
    extractedPath = await toolCache.extractTar(downloadPath);
  } else if (url.indexOf('.7z') != -1) {
    extractedPath = await toolCache.extract7z(downloadPath);
  } else {
    throw new Error(
      `Unexpected download archive type, downloadPath: ${downloadPath}`,
    );
  }
  return extractedPath;
}
github WebFreak001 / setup-dmd / src / main.ts View on Github external
if (!url.length || type === undefined)
    throw new Error(`Failed to determine dmd download URL for version ${dmdVersion}`);

  core.debug("Downloading DMD from " + url);
  const tmppath = await tc.downloadTool(url);
  let dstdir: string;
  switch (type) {
    case "tarxz":
      dstdir = await tc.extractTar(tmppath);
      break;
    case "7z":
      dstdir = await tc.extract7z(tmppath);
      break;
    case "zip":
      dstdir = await tc.extractZip(tmppath);
      break;
    default: throw new Error("unexpected program state");
  }

  if (dmdVersion !== "master")
    tc.cacheDir(dstdir, "dmd", dmdVersion);

  return dstdir;
}
github subosito / flutter-action / src / installer.ts View on Github external
async function extractFile(file: string, destDir: string): Promise {
  const stats = fs.statSync(file);

  if (!stats) {
    throw new Error(`Failed to extract ${file} - it doesn't exist`);
  } else if (stats.isDirectory()) {
    throw new Error(`Failed to extract ${file} - it is a directory`);
  }

  if ('tar.xz' === extName()) {
    await tc.extractTar(file, destDir, 'x');
  } else {
    await tc.extractZip(file, destDir);
  }
}