or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

caching.mddiscovery.mddownload.mdextraction.mdindex.mdmanifest.mdversions.md
tile.json

caching.mddocs/

Tool Caching

Persistent tool storage system with semantic versioning and architecture support for efficient tool management across GitHub Actions workflow runs.

Capabilities

Cache Directory

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"
);

Cache File

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"
);

Complete Workflow Examples

Download, Extract, and Cache

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;
}

Cache Multiple Files

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 };
}

Implementation Details

Cache Storage

  • Location: Uses RUNNER_TOOL_CACHE environment variable (set by GitHub Actions)
  • Structure: {CACHE_DIR}/{tool}/{version}/{arch}/
  • Persistence: Cached tools persist across workflow runs for self-hosted runners
  • Permissions: Maintains file permissions from source directory/file

Architecture Handling

  • Default architecture: Automatically detected from current platform
  • Supported values: x64, x86, arm, arm64, and other Node.js architecture identifiers
  • Cross-platform: Tools can be cached with different architectures for multi-platform workflows

Version Management

  • Semantic versions: Recommended format (e.g., "1.2.3", "2.0.0-beta.1")
  • Custom versions: Any string can be used as version identifier
  • Collision handling: Same tool/version/arch combination will overwrite existing cache entry

Directory vs File Caching

  • Directory caching: Use for tools that consist of multiple files and subdirectories
  • File caching: Use for single executable files or standalone scripts
  • Return paths: Both functions return the directory path containing the cached content

Environment Requirements

// Required environment variables (automatically set by GitHub Actions)
process.env.RUNNER_TOOL_CACHE: string; // Cache directory location

The 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.