HTTP-based tool downloading with authentication, retry logic, and robust error handling for reliable tool acquisition from remote URLs.
Downloads a tool from a URL and streams it into a file with automatic retry logic and error handling.
/**
* Downloads a tool from a URL with retry logic and error handling
* @param url - URL of the tool to download
* @param dest - Optional destination path (auto-generated if not provided)
* @param auth - Optional authorization header value
* @param headers - Optional additional HTTP headers
* @returns Promise resolving to the path of the downloaded tool
*/
function downloadTool(
url: string,
dest?: string,
auth?: string,
headers?: OutgoingHttpHeaders
): Promise<string>;Usage Examples:
import { downloadTool } from "@actions/tool-cache";
// Basic download
const toolPath = await downloadTool("https://example.com/tool.zip");
// Download with custom destination
const toolPath = await downloadTool(
"https://example.com/tool.zip",
"/tmp/my-tool.zip"
);
// Download with authentication
const toolPath = await downloadTool(
"https://api.github.com/repos/owner/repo/releases/assets/123",
undefined,
"token your-github-token"
);
// Download with custom headers
const toolPath = await downloadTool(
"https://example.com/tool.zip",
undefined,
undefined,
{
"User-Agent": "MyAction/1.0",
"Accept": "application/octet-stream"
}
);Custom error class for HTTP-related failures during downloads.
/**
* Custom error class for HTTP download failures
* Contains the HTTP status code that caused the error
*/
class HTTPError extends Error {
constructor(readonly httpStatusCode: number | undefined);
}Usage Examples:
import { downloadTool, HTTPError } from "@actions/tool-cache";
try {
const toolPath = await downloadTool("https://example.com/nonexistent.zip");
} catch (error) {
if (error instanceof HTTPError) {
console.log(`HTTP Error: ${error.httpStatusCode}`);
console.log(`Message: ${error.message}`);
}
}auth parameter in format "username:password"auth parameter in format "token your-token"headers parameter for complex authentication schemesimport { OutgoingHttpHeaders } from "http";
class HTTPError extends Error {
readonly httpStatusCode: number | undefined;
constructor(httpStatusCode: number | undefined);
}