Persistent tool storage system with semantic versioning and architecture support for efficient tool management across GitHub Actions workflow runs.
Caches a complete directory and installs it into the tool cache with version and architecture tracking.
/**
* Caches a directory and installs it into the tool cache
* @param sourceDir - Path to the directory to cache
* @param tool - Name of the tool being cached
* @param version - Version of the tool (semantic version recommended)
* @param arch - Optional architecture identifier (defaults to current platform architecture)
* @returns Promise resolving to the path of the cached directory
*/
function cacheDir(
sourceDir: string,
tool: string,
version: string,
arch?: string
): Promise<string>;Usage Examples:
import { cacheDir } from "@actions/tool-cache";
// Cache a tool directory
const cachedPath = await cacheDir(
"/tmp/extracted-tool",
"node",
"18.17.0"
);
// Cache with specific architecture
const cachedPath = await cacheDir(
"/tmp/extracted-tool",
"node",
"18.17.0",
"x64"
);
// Cache a tool with semantic version
const cachedPath = await cacheDir(
"/path/to/my-tool",
"my-custom-tool",
"1.2.3-beta.1"
);Caches a single file and installs it into the tool cache with a specified filename.
/**
* Caches a single file and installs it into the tool cache
* @param sourceFile - Path to the file to cache
* @param targetFile - Name for the cached file
* @param tool - Name of the tool being cached
* @param version - Version of the tool (semantic version recommended)
* @param arch - Optional architecture identifier (defaults to current platform architecture)
* @returns Promise resolving to the path of the cached file's directory
*/
function cacheFile(
sourceFile: string,
targetFile: string,
tool: string,
version: string,
arch?: string
): Promise<string>;Usage Examples:
import { cacheFile } from "@actions/tool-cache";
// Cache a single executable
const cachedPath = await cacheFile(
"/tmp/downloaded-tool",
"mytool",
"mytool",
"2.1.0"
);
// Cache with custom filename and architecture
const cachedPath = await cacheFile(
"/tmp/tool.exe",
"tool.exe",
"windows-tool",
"1.0.0",
"x64"
);
// Cache a script or configuration file
const cachedPath = await cacheFile(
"/tmp/config.json",
"default-config.json",
"my-app",
"3.2.1"
);import * as tc from "@actions/tool-cache";
import * as core from "@actions/core";
async function setupPython() {
const version = "3.11.0";
const downloadUrl = `https://www.python.org/ftp/python/${version}/Python-${version}.tgz`;
// Download the tool
const downloadPath = await tc.downloadTool(downloadUrl);
// Extract the archive
const extractedPath = await tc.extractTar(downloadPath);
// Cache the extracted directory
const cachedPath = await tc.cacheDir(extractedPath, "python", version);
// Add to PATH for subsequent steps
core.addPath(cachedPath);
return cachedPath;
}import { cacheFile } from "@actions/tool-cache";
async function cacheToolComponents() {
const version = "2.0.0";
// Cache main executable
const executablePath = await cacheFile(
"/tmp/mytool",
"mytool",
"mytool",
version
);
// Cache configuration file
const configPath = await cacheFile(
"/tmp/config.yaml",
"config.yaml",
"mytool-config",
version
);
return { executablePath, configPath };
}RUNNER_TOOL_CACHE environment variable (set by GitHub Actions){CACHE_DIR}/{tool}/{version}/{arch}/x64, x86, arm, arm64, and other Node.js architecture identifiers// Required environment variables (automatically set by GitHub Actions)
process.env.RUNNER_TOOL_CACHE: string; // Cache directory locationThe tool cache requires the RUNNER_TOOL_CACHE environment variable to be set, which GitHub Actions automatically provides. For local testing or other environments, this must be set to a writable directory path.