Actions Tool Cache is a comprehensive TypeScript library that provides essential functionality for downloading, extracting, caching, and retrieving tools within GitHub Actions workflows. It offers cross-platform support for downloading files from URLs with authentication, platform-specific extraction capabilities for various archive formats, intelligent caching system for storing tools locally, and efficient tool discovery through semantic version matching.
npm install @actions/tool-cacheimport {
downloadTool,
extractZip,
extractTar,
extract7z,
extractXar,
cacheDir,
cacheFile,
find,
findAllVersions
} from "@actions/tool-cache";For CommonJS:
const {
downloadTool,
extractZip,
extractTar,
extract7z,
extractXar,
cacheDir,
cacheFile,
find,
findAllVersions
} = require("@actions/tool-cache");import * as tc from "@actions/tool-cache";
import * as core from "@actions/core";
// Download, extract, cache, and use a tool
async function setupNode() {
// Download tool
const downloadPath = await tc.downloadTool(
"https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.gz"
);
// Extract archive
const extractedPath = await tc.extractTar(downloadPath);
// Cache the tool
const cachedPath = await tc.cacheDir(extractedPath, "node", "18.17.0");
// Add to PATH
core.addPath(cachedPath);
}
// Find previously cached tool
const nodePath = tc.find("node", "18.x");
if (nodePath) {
core.addPath(nodePath);
}Actions Tool Cache is built around several key components:
HTTP-based tool downloading with authentication, retry logic, and error handling. Supports custom headers and destinations.
function downloadTool(
url: string,
dest?: string,
auth?: string,
headers?: OutgoingHttpHeaders
): Promise<string>;
class HTTPError extends Error {
constructor(readonly httpStatusCode: number | undefined);
}Archive extraction supporting multiple formats including ZIP, tar with various compression schemes, 7z (Windows only), and XAR (macOS).
function extractZip(file: string, dest?: string): Promise<string>;
function extractTar(
file: string,
dest?: string,
flags?: string | string[]
): Promise<string>;
function extract7z(
file: string,
dest?: string,
_7zPath?: string
): Promise<string>;
function extractXar(
file: string,
dest?: string,
flags?: string | string[]
): Promise<string>;Persistent tool storage system with semantic versioning and architecture support for efficient tool management across workflow runs.
function cacheDir(
sourceDir: string,
tool: string,
version: string,
arch?: string
): Promise<string>;
function cacheFile(
sourceFile: string,
targetFile: string,
tool: string,
version: string,
arch?: string
): Promise<string>;Semantic version-aware tool discovery for finding cached tools with support for version ranges and architecture filtering.
function find(
toolName: string,
versionSpec: string,
arch?: string
): string;
function findAllVersions(toolName: string, arch?: string): string[];GitHub repository-based tool manifest system for automated tool discovery, version resolution, and platform-specific downloads.
function getManifestFromRepo(
owner: string,
repo: string,
auth?: string,
branch?: string
): Promise<IToolRelease[]>;
function findFromManifest(
versionSpec: string,
stable: boolean,
manifest: IToolRelease[],
archFilter?: string
): Promise<IToolRelease | undefined>;
interface IToolRelease {
version: string;
stable: boolean;
release_url: string;
files: IToolReleaseFile[];
}
interface IToolReleaseFile {
filename: string;
platform: string;
platform_version?: string;
arch: string;
download_url: string;
}Semantic version evaluation and validation utilities for working with version specifications and ranges.
function isExplicitVersion(versionSpec: string): boolean;
function evaluateVersions(
versions: string[],
versionSpec: string
): string;import { OutgoingHttpHeaders } from "http";
class HTTPError extends Error {
constructor(readonly httpStatusCode: number | undefined);
}
interface IToolRelease {
version: string;
stable: boolean;
release_url: string;
files: IToolReleaseFile[];
}
interface IToolReleaseFile {
filename: string;
platform: string;
platform_version?: string;
arch: string;
download_url: string;
}