or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

discovery.mddocs/

Tool Discovery

Semantic version-aware tool discovery for finding cached tools with support for version ranges, architecture filtering, and comprehensive version enumeration.

Capabilities

Find Tool

Finds the path to a cached tool by name and version specification with architecture support.

/**
 * Finds the path to a tool in the local installed tool cache
 * @param toolName - Name of the tool to find
 * @param versionSpec - Version specification (exact version or semantic range)
 * @param arch - Optional architecture filter (defaults to current platform architecture)
 * @returns Path to the tool directory, or empty string if not found
 */
function find(
  toolName: string,
  versionSpec: string,
  arch?: string
): string;

Usage Examples:

import { find } from "@actions/tool-cache";
import * as core from "@actions/core";

// Find exact version
const nodePath = find("node", "18.17.0");
if (nodePath) {
  core.addPath(nodePath);
}

// Find with semantic version range
const pythonPath = find("python", "3.x");
if (pythonPath) {
  core.addPath(pythonPath);
}

// Find with more specific range
const toolPath = find("my-tool", ">=2.0.0 <3.0.0");

// Find with specific architecture
const toolPath = find("node", "16.x", "x64");

// Check if tool exists before using
const javaPath = find("java", "11");
if (!javaPath) {
  throw new Error("Java 11 not found in tool cache");
}

Find All Versions

Finds all cached versions of a tool with optional architecture filtering.

/**
 * Finds all versions of a tool that are installed in the local tool cache
 * @param toolName - Name of the tool to search for
 * @param arch - Optional architecture filter (defaults to all architectures)
 * @returns Array of version strings sorted in descending order
 */
function findAllVersions(toolName: string, arch?: string): string[];

Usage Examples:

import { findAllVersions } from "@actions/tool-cache";

// Get all cached versions of a tool
const nodeVersions = findAllVersions("node");
console.log("Available Node.js versions:", nodeVersions);
// Example output: ["18.17.0", "16.20.1", "14.21.3"]

// Get versions for specific architecture
const x64Versions = findAllVersions("python", "x64");

// Check if any version is available
const versions = findAllVersions("my-tool");
if (versions.length === 0) {
  console.log("No cached versions of my-tool found");
}

// Find latest cached version
const latestVersion = findAllVersions("java")[0]; // Array is sorted descending

Version Specification Examples

Exact Version Matching

find("node", "18.17.0");        // Exact match
find("python", "3.11.2");       // Exact match
find("java", "11.0.19");        // Exact match

Semantic Version Ranges

find("node", "18.x");           // Latest 18.x version
find("python", "3.x");          // Latest 3.x version
find("tool", ">=2.0.0");        // Version 2.0.0 or higher
find("tool", "~1.2.0");         // Compatible with 1.2.0
find("tool", "^2.1.0");         // Compatible with 2.1.0
find("tool", ">=1.0.0 <2.0.0"); // Range between 1.0.0 and 2.0.0

Architecture-Specific Discovery

find("node", "18.x", "x64");    // 64-bit version
find("node", "18.x", "arm64");  // ARM64 version
find("python", "3.x", "x86");   // 32-bit version

Complete Discovery Workflows

Tool Availability Check

import { find, findAllVersions } from "@actions/tool-cache";
import * as core from "@actions/core";

function checkToolAvailability(toolName: string, versionSpec: string): boolean {
  const toolPath = find(toolName, versionSpec);
  if (toolPath) {
    core.info(`Found ${toolName} ${versionSpec} at ${toolPath}`);
    return true;
  }
  
  const availableVersions = findAllVersions(toolName);
  if (availableVersions.length > 0) {
    core.warning(`${toolName} ${versionSpec} not found. Available versions: ${availableVersions.join(", ")}`);
  } else {
    core.warning(`No cached versions of ${toolName} found`);
  }
  
  return false;
}

Multi-Version Tool Setup

import { find, findAllVersions } from "@actions/tool-cache";
import * as core from "@actions/core";

async function setupMultipleNodeVersions() {
  const versions = ["16.x", "18.x", "20.x"];
  const foundVersions: string[] = [];
  
  for (const version of versions) {
    const nodePath = find("node", version);
    if (nodePath) {
      foundVersions.push(version);
      // Add to PATH or set up environment
      core.addPath(nodePath);
    }
  }
  
  core.info(`Set up Node.js versions: ${foundVersions.join(", ")}`);
  
  // List all available Node versions
  const allVersions = findAllVersions("node");
  core.debug(`All cached Node versions: ${allVersions.join(", ")}`);
}

Fallback Version Strategy

import { find } from "@actions/tool-cache";

function findToolWithFallback(toolName: string, preferredVersions: string[]): string {
  for (const version of preferredVersions) {
    const toolPath = find(toolName, version);
    if (toolPath) {
      return toolPath;
    }
  }
  
  throw new Error(`None of the preferred versions found for ${toolName}: ${preferredVersions.join(", ")}`);
}

// Usage
const pythonPath = findToolWithFallback("python", ["3.11.x", "3.10.x", "3.9.x", "3.x"]);

Implementation Details

Version Resolution

  • Semantic versioning: Uses semver library for range matching and comparison
  • Exact matching: String equality for non-semantic versions
  • Sorting: Versions returned in descending order (newest first)
  • Range evaluation: Supports all semantic version range operators

Architecture Handling

  • Default behavior: Uses current platform architecture if not specified
  • Cross-platform: Can find tools cached for different architectures
  • Multiple architectures: findAllVersions can filter by specific architecture

Performance

  • File system scanning: Searches tool cache directory structure efficiently
  • Caching: Results are not cached; each call performs fresh directory scan
  • Path resolution: Returns absolute paths to tool directories

Error Handling

  • Missing tools: Returns empty string or empty array rather than throwing errors
  • Invalid versions: Handles malformed version specifications gracefully
  • Directory access: Handles permissions and missing cache directories safely

Return Value Patterns

// find() returns empty string when not found
const toolPath = find("nonexistent-tool", "1.0.0");
if (toolPath === "") {
  console.log("Tool not found");
}

// findAllVersions() returns empty array when not found
const versions = findAllVersions("nonexistent-tool");
if (versions.length === 0) {
  console.log("No versions found");
}