From de938e707d6c238b34e29b5770a011e3155e2a3c Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 16 Nov 2026 16:24:53 -0500 Subject: [PATCH] Add the `require-checksums` input (#1139) Adds `require-checksums`, which enforces the "intrinsic or explicitly provided checksum" idea. See #1032.
Automated notes Add the opt-in input `require-checksums`. When enabled, setup-uv verifies the archive against the workflow's `checksum` input or the digest bundled for the resolved uv version, architecture, and platform. If neither is available, setup fails before downloading the archive. By default, setup-uv continues to accept manifest checksums as it does today. The setting also applies to custom manifests, which can still supply download URLs. On persistent runners, strict mode keys tool-cache entries by the expected archive digest so a previous manifest-verified installation cannot bypass the check. Closes #1032. Builds on #1033. ## Validation - `npm ci --ignore-scripts` and `npm run all` passed under Node 24 (182 tests). - The packaged-action regression test installs a custom build into a temporary runner tool cache. It checks that strict mode rejects a manifest-only version even with a warm cache, reuses a verified installation for the same digest, and rejects a changed digest or a custom build that conflicts with the bundled digest.
--------- Signed-off-by: William Woodruff --- README.md | 5 +- __tests__/download/checksum/checksum.test.ts | 4 +- .../download/intrinsic-checksums.test.ts | 93 +++++++++++++++++++ __tests__/helpers/setup-inputs.ts | 1 + __tests__/utils/inputs.test.ts | 6 ++ action-types.yml | 2 + action.yml | 3 + dist/save-cache/index.cjs | 2 + dist/setup/index.cjs | 63 ++++++++----- docs/advanced-version-configuration.md | 4 +- docs/customization.md | 25 ++++- docs/threat-model.md | 2 +- src/download/checksum/checksum.ts | 6 +- src/download/download-version.ts | 33 +++++-- src/setup-uv.ts | 26 +++++- src/utils/inputs.ts | 3 + 16 files changed, 235 insertions(+), 43 deletions(-) create mode 100644 __tests__/download/intrinsic-checksums.test.ts diff --git a/README.md b/README.md index ca9a252..e221604 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs - Cache the installed version of uv to speed up consecutive runs on self-hosted runners - Register problem matchers for error output - (Optional) Persist the uv's cache in the GitHub Actions Cache -- (Optional) Verify the checksum of the downloaded uv executable +- Verify the SHA-256 checksum of the downloaded uv archive ## Contents @@ -75,6 +75,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed # The checksum of the uv version to install checksum: "" + # Require a checksum bundled with setup-uv or supplied through the checksum input + require-checksums: "false" + # Used when downloading uv from GitHub releases github-token: ${{ github.token }} diff --git a/__tests__/download/checksum/checksum.test.ts b/__tests__/download/checksum/checksum.test.ts index b3d13a6..ee7f4ef 100644 --- a/__tests__/download/checksum/checksum.test.ts +++ b/__tests__/download/checksum/checksum.test.ts @@ -56,7 +56,7 @@ test("manifest checksums are used when no known checksum exists", async () => { ).rejects.toThrow("did not match"); }); -test("empty manifest checksums are rejected", async () => { +test.each(["", undefined])("rejects missing checksums (%s)", async (hash) => { await expect( validateChecksum( undefined, @@ -64,7 +64,7 @@ test("empty manifest checksums are rejected", async () => { "aarch64", "pc-windows-msvc", "1.2.3", - "", + hash, ), ).rejects.toThrow("No checksum found"); }); diff --git a/__tests__/download/intrinsic-checksums.test.ts b/__tests__/download/intrinsic-checksums.test.ts new file mode 100644 index 0000000..80597c0 --- /dev/null +++ b/__tests__/download/intrinsic-checksums.test.ts @@ -0,0 +1,93 @@ +import { execFile, execFileSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import fs from "node:fs"; +import { createServer } from "node:http"; +import type { AddressInfo } from "node:net"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { promisify } from "node:util"; +import { expect, test } from "@jest/globals"; +import { getArch, getPlatform } from "../../src/utils/platforms"; + +test("enforces intrinsic checksums on downloads and tool-cache hits", async () => { + const platform = await getPlatform(); + const target = `${getArch()}-${platform}`; + const windows = platform === "pc-windows-msvc"; + const dir = fs.mkdtempSync(path.join(tmpdir(), "setup-uv-checksums-")); + const server = createServer(); + try { + const member = windows ? "uv.exe" : `uv-${target}/uv`; + const archiveName = windows ? "uv.zip" : "uv.tar.gz"; + fs.mkdirSync(path.dirname(path.join(dir, member)), { recursive: true }); + fs.writeFileSync(path.join(dir, member), "test build"); + execFileSync("tar", ["-acf", archiveName, member], { cwd: dir }); + const archive = fs.readFileSync(path.join(dir, archiveName)); + const digest = createHash("sha256").update(archive).digest("hex"); + let downloads = 0; + server.on("request", (_req, res) => { + downloads++; + res.end(archive); + }); + await new Promise((resolve) => + server.listen(0, "127.0.0.1", resolve), + ); + const address = server.address() as AddressInfo; + + function install(version: string, strict: boolean, checksum = "") { + const manifest = JSON.stringify({ + artifacts: [ + { + archive_format: windows ? "zip" : "tar.gz", + platform: target, + sha256: digest, + url: `http://127.0.0.1:${address.port}/${archiveName}`, + }, + ], + version, + }); + return promisify(execFile)(process.execPath, ["dist/setup/index.cjs"], { + env: { + "INPUT_ACTIVATE-ENVIRONMENT": "false", + INPUT_CHECKSUM: checksum, + "INPUT_MANIFEST-FILE": `data:application/json,${encodeURIComponent(manifest)}`, + "INPUT_NO-PROJECT": "false", + "INPUT_PYTHON-VERSION": "3.13", + "INPUT_REQUIRE-CHECKSUMS": String(strict), + INPUT_VERSION: version, + "INPUT_WORKING-DIRECTORY": dir, + PATH: process.env.PATH, + RUNNER_TEMP: dir, + RUNNER_TOOL_CACHE: path.join(dir, "cache"), + SystemRoot: process.env.SystemRoot, + }, + timeout: 10_000, + }); + } + + const version = "99.0.0"; + await install(version, false); + await expect(install(version, true)).rejects.toMatchObject({ + stdout: expect.stringContaining( + `No bundled checksum for ${target}-${version}`, + ), + }); + expect(downloads).toBe(1); + await install(version, true, digest); + expect(downloads).toBe(2); + await install(version, true, digest); + expect(downloads).toBe(2); + await expect(install(version, true, "0".repeat(64))).rejects.toMatchObject({ + stdout: expect.stringContaining("did not match"), + }); + // The custom manifest also offers these bytes under a known release version. + await expect(install("0.9.26", true)).rejects.toMatchObject({ + stdout: expect.stringContaining("did not match"), + }); + await expect(install(version, true, "../uv")).rejects.toMatchObject({ + stdout: expect.stringContaining("Expected a SHA-256 checksum"), + }); + } finally { + server.close(); + fs.rmSync(dir, { force: true, recursive: true }); + } +}, 30_000); diff --git a/__tests__/helpers/setup-inputs.ts b/__tests__/helpers/setup-inputs.ts index f20e57d..26f6b66 100644 --- a/__tests__/helpers/setup-inputs.ts +++ b/__tests__/helpers/setup-inputs.ts @@ -26,6 +26,7 @@ export function createSetupInputs( pythonDir: "/tmp/uv-python-dir", pythonVersion: "", quiet: false, + requireChecksums: false, resolutionStrategy: "highest", restoreCache: false, saveCache: true, diff --git a/__tests__/utils/inputs.test.ts b/__tests__/utils/inputs.test.ts index 126ca8f..be2c7cb 100644 --- a/__tests__/utils/inputs.test.ts +++ b/__tests__/utils/inputs.test.ts @@ -109,9 +109,15 @@ describe("loadInputs", () => { expect(inputs.exportPythonArch).toBe(false); expect(inputs.venvPath).toBe("/workspace/.venv"); expect(inputs.manifestFile).toBeUndefined(); + expect(inputs.requireChecksums).toBe(false); expect(inputs.resolutionStrategy).toBe("highest"); }); + it("loads require-checksums", () => { + mockInputs["require-checksums"] = "true"; + expect(loadInputs().requireChecksums).toBe(true); + }); + it("uses the Python version from an explicitly selected .tool-versions file", () => { mockInputs["working-directory"] = createTempProject({ ".tool-versions": "uv 0.12.3\npython 3.13.1t\n", diff --git a/action-types.yml b/action-types.yml index 3746c94..b5c27c3 100644 --- a/action-types.yml +++ b/action-types.yml @@ -19,6 +19,8 @@ inputs: type: string checksum: type: string + require-checksums: + type: boolean github-token: type: string enable-cache: diff --git a/action.yml b/action.yml index 16220a0..cc629f6 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,9 @@ inputs: checksum: description: "The checksum of the uv version to install" required: false + require-checksums: + description: "Require a SHA-256 checksum bundled with setup-uv or supplied through the checksum input." + default: "false" github-token: description: "Used when downloading uv from GitHub releases." diff --git a/dist/save-cache/index.cjs b/dist/save-cache/index.cjs index 1d25968..f1b81b5 100644 --- a/dist/save-cache/index.cjs +++ b/dist/save-cache/index.cjs @@ -66242,6 +66242,7 @@ function loadInputs() { const noProject = getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment); const checksum = getInput("checksum"); + const requireChecksums = getBooleanInput("require-checksums"); const enableCache = getEnableCache(); const restoreCache2 = getInput("restore-cache") === "true"; const saveCache4 = getSaveCache(); @@ -66286,6 +66287,7 @@ function loadInputs() { pythonDir, pythonVersion, quiet: quiet2, + requireChecksums, resolutionStrategy, restoreCache: restoreCache2, saveCache: saveCache4, diff --git a/dist/setup/index.cjs b/dist/setup/index.cjs index 4ec7dc9..b1df42e 100644 --- a/dist/setup/index.cjs +++ b/dist/setup/index.cjs @@ -101009,11 +101009,7 @@ async function validateChecksum(checksum, downloadPath, arch3, platform2, versio const hasManifestChecksum = manifestChecksum !== void 0 && manifestChecksum !== ""; const checksumToUse = hasProvidedChecksum ? checksum : knownChecksum ?? (hasManifestChecksum ? manifestChecksum : void 0); if (checksumToUse === void 0) { - if (manifestChecksum !== void 0) { - throw new Error(`No checksum found for ${key} in manifest.`); - } - debug(`No checksum found for ${key}.`); - return; + throw new Error(`No checksum found for ${key} in manifest.`); } const checksumSource = hasProvidedChecksum ? "provided checksum" : knownChecksum !== void 0 ? `KNOWN_CHECKSUMS entry for ${key}` : "manifest checksum"; debug(`Validating checksum using ${checksumSource}.`); @@ -102888,18 +102884,30 @@ function minSatisfying3(versions, version3) { } // src/download/download-version.ts -function tryGetFromToolCache(arch3, version3) { +function getIntrinsicChecksum(key, providedChecksum) { + const checksum = providedChecksum || KNOWN_CHECKSUMS[key]; + if (!checksum) { + throw new Error( + `No bundled checksum for ${key}. With require-checksums enabled, update setup-uv or provide the checksum input for this archive.` + ); + } + if (!/^[a-f0-9]{64}$/.test(checksum)) { + throw new Error(`Expected a SHA-256 checksum for ${key}.`); + } + return checksum; +} +function tryGetFromToolCache(arch3, version3, toolCacheName = TOOL_CACHE_NAME) { debug(`Trying to get uv from tool cache for ${version3}...`); - const cachedVersions = findAllVersions(TOOL_CACHE_NAME, arch3); + const cachedVersions = findAllVersions(toolCacheName, arch3); debug(`Cached versions: ${cachedVersions}`); let resolvedVersion = evaluateVersions(cachedVersions, version3); if (resolvedVersion === "") { resolvedVersion = version3; } - const installedPath = find(TOOL_CACHE_NAME, resolvedVersion, arch3); + const installedPath = find(toolCacheName, resolvedVersion, arch3); return { installedPath, version: resolvedVersion }; } -async function downloadVersion(platform2, arch3, version3, checksum, githubToken, manifestUrl, downloadFromAstralMirror = true) { +async function downloadVersion(platform2, arch3, version3, checksum, githubToken, manifestUrl, downloadFromAstralMirror = true, toolCacheName = TOOL_CACHE_NAME) { const artifact = await getArtifact(version3, arch3, platform2, manifestUrl); if (!artifact) { throw new Error( @@ -102919,7 +102927,8 @@ async function downloadVersion(platform2, arch3, version3, checksum, githubToken version3, resolvedChecksum, manifestChecksum, - githubTokenForUrl(downloadUrl, githubToken) + githubTokenForUrl(downloadUrl, githubToken), + toolCacheName ); } catch (err) { if (mirrorUrl === void 0) { @@ -102936,7 +102945,8 @@ async function downloadVersion(platform2, arch3, version3, checksum, githubToken version3, resolvedChecksum, manifestChecksum, - githubTokenForUrl(artifact.downloadUrl, githubToken) + githubTokenForUrl(artifact.downloadUrl, githubToken), + toolCacheName ); } } @@ -102953,7 +102963,7 @@ function githubTokenForUrl(downloadUrl, githubToken) { return void 0; } } -async function downloadArtifact(downloadUrl, artifactName, platform2, arch3, version3, checksum, manifestChecksum, githubToken) { +async function downloadArtifact(downloadUrl, artifactName, platform2, arch3, version3, checksum, manifestChecksum, githubToken, toolCacheName) { info2(`Downloading uv from "${downloadUrl}" ...`); const downloadPath = await downloadTool( downloadUrl, @@ -102985,12 +102995,7 @@ async function downloadArtifact(downloadUrl, artifactName, platform2, arch3, ver const extractedDir = await extractTar2(downloadPath); uvDir = path15.join(extractedDir, artifactName); } - const cachedToolDir = await cacheDir( - uvDir, - TOOL_CACHE_NAME, - version3, - arch3 - ); + const cachedToolDir = await cacheDir(uvDir, toolCacheName, version3, arch3); return { cachedToolDir, version: version3 }; } function getMissingArtifactMessage(version3, arch3, platform2, manifestUrl) { @@ -103021,6 +103026,7 @@ function loadInputs() { const noProject = getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment2); const checksum = getInput("checksum"); + const requireChecksums = getBooleanInput("require-checksums"); const enableCache = getEnableCache(); const restoreCache3 = getInput("restore-cache") === "true"; const saveCache2 = getSaveCache(); @@ -103065,6 +103071,7 @@ function loadInputs() { pythonDir, pythonVersion, quiet: quiet2, + requireChecksums, resolutionStrategy, restoreCache: restoreCache3, saveCache: saveCache2, @@ -103502,7 +103509,20 @@ async function setupUv(inputs, platform2, arch3) { versionFile: inputs.versionFile, workingDirectory: inputs.workingDirectory }); - const toolCacheResult = tryGetFromToolCache(arch3, resolvedVersion); + let checksum = inputs.checksum; + let toolCacheName = TOOL_CACHE_NAME; + if (inputs.requireChecksums) { + checksum = getIntrinsicChecksum( + `${arch3}-${platform2}-${resolvedVersion}`, + inputs.checksum + ); + toolCacheName = `${TOOL_CACHE_NAME}-${checksum}`; + } + const toolCacheResult = tryGetFromToolCache( + arch3, + resolvedVersion, + toolCacheName + ); if (toolCacheResult.installedPath) { info2(`Found uv in tool-cache for ${toolCacheResult.version}`); return { @@ -103514,10 +103534,11 @@ async function setupUv(inputs, platform2, arch3) { platform2, arch3, resolvedVersion, - inputs.checksum, + checksum, inputs.githubToken, inputs.manifestFile, - inputs.downloadFromAstralMirror + inputs.downloadFromAstralMirror, + toolCacheName ); return { uvDir: downloadResult.cachedToolDir, diff --git a/docs/advanced-version-configuration.md b/docs/advanced-version-configuration.md index 0d20015..c821e6f 100644 --- a/docs/advanced-version-configuration.md +++ b/docs/advanced-version-configuration.md @@ -15,7 +15,9 @@ This document covers advanced options for configuring which version of uv to ins Use `latest-known` to install the newest uv version whose checksums were bundled with the version of setup-uv used by your workflow. Version resolution is performed locally without fetching the latest release, so updating setup-uv also updates the version selected by `latest-known`. -When `manifest-file` is set, `latest-known` still selects a version from setup-uv's bundled checksum table, but the artifact and checksum come from the custom manifest. +When `manifest-file` is set, `latest-known` still selects a version from setup-uv's bundled checksum table. +By default the custom manifest supplies the artifact and checksum. To require a bundled or explicitly +supplied checksum, enable `require-checksums`. [Checksum validation](customization.md#validate-checksum) ```yaml - name: Install the latest version of uv known to setup-uv diff --git a/docs/customization.md b/docs/customization.md index b160c24..89e0713 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -4,7 +4,7 @@ This document covers advanced customization options including checksum validatio ## Validate checksum -Downloaded executables are automatically verified using checksums bundled with this action or, +Downloaded archives are automatically verified using checksums bundled with this action or, for newer, not yet bundled versions, the checksum from [`astral-sh/versions`](https://github.com/astral-sh/versions). You can specify a checksum to override those values. The sha256 hashes can also be found on the [releases page](https://github.com/astral-sh/uv/releases) of the uv repo. @@ -17,6 +17,29 @@ You can specify a checksum to override those values. The sha256 hashes can also checksum: "e11b01402ab645392c7ad6044db63d37e4fd1e745e015306993b07695ea5f9f8" ``` +For an additional layer of protection, you can set `require-checksums: true`. +This prevents setup-uv from trusting an unknown version's checksum from +[`astral-sh/versions`](https://github.com/astral-sh/versions) *unless* it is also +present in the action's own bundled data *or* explicitly provided with `checksum`. + +This can be combined with `version: latest-known` to select the newest bundled release, +meaning that this newer requires an external checksum source: + +```yaml +- name: Install the latest known version of uv + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + version: latest-known + require-checksums: true +``` + +With this mode, you'll need to update setup-uv itself to get newer uv versions +*unless* you explicitly pass in a `checksum` with a version that post-dates the setup-uv +release. + +On runners with a persistent tool cache, this mode reuses only installations previously verified +against the same digest. The first run may download uv again. + ## Manifest file By default, setup-uv reads version metadata from diff --git a/docs/threat-model.md b/docs/threat-model.md index 7f3a315..e4a3d81 100644 --- a/docs/threat-model.md +++ b/docs/threat-model.md @@ -38,7 +38,7 @@ Material failures are unauthorized executable selection, credential disclosure, ### Security invariants 1. **Published runtime:** review `action.yml`, committed `dist/*.cjs`, and runner-interpreted shipped files; source-only fixes do not protect consumers. -2. **Executable identity:** precedence is workflow version, version file, project configuration, then `latest`. Manifest authority, platform, variant, URL, checksum, mirror fallback, extraction, and cache placement must bind the intended artifact. A tool-cache hit bypasses download validation and depends on cache provenance. +2. **Executable identity:** precedence is workflow version, version file, project configuration, then `latest`. Manifest authority, platform, variant, URL, checksum, mirror fallback, extraction, and cache placement must bind the intended artifact. A tool-cache hit bypasses download validation and depends on cache provenance. With `require-checksums`, only entries keyed by the explicit or bundled archive digest are eligible. 3. **Credential recipients:** tokens and URL credentials may reach only workflow-authorized origins, redirects, paths, and logs. Metadata authority does not imply token-recipient authority. 4. **Executable boundaries:** checkout-selected interpreters are authorized by default. Explicit workflow selections must win, and independent cache, runner, or remote state must not substitute executables or gain additional authority. 5. **Paths and action channels:** path/environment changes, virtual-environment clearing, outputs, state, and problem matchers must affect only authorized targets and keep untrusted values as data. diff --git a/src/download/checksum/checksum.ts b/src/download/checksum/checksum.ts index 11c2278..fdfad7f 100644 --- a/src/download/checksum/checksum.ts +++ b/src/download/checksum/checksum.ts @@ -23,11 +23,7 @@ export async function validateChecksum( : (knownChecksum ?? (hasManifestChecksum ? manifestChecksum : undefined)); if (checksumToUse === undefined) { - if (manifestChecksum !== undefined) { - throw new Error(`No checksum found for ${key} in manifest.`); - } - core.debug(`No checksum found for ${key}.`); - return; + throw new Error(`No checksum found for ${key} in manifest.`); } const checksumSource = hasProvidedChecksum diff --git a/src/download/download-version.ts b/src/download/download-version.ts index dc808c2..4ba9e1b 100644 --- a/src/download/download-version.ts +++ b/src/download/download-version.ts @@ -11,22 +11,40 @@ import { import * as log from "../utils/logging"; import type { Architecture, Platform } from "../utils/platforms"; import { validateChecksum } from "./checksum/checksum"; +import { KNOWN_CHECKSUMS } from "./checksum/known-checksums"; import { getArtifact } from "./manifest"; export { resolveVersion } from "../version/resolve"; +export function getIntrinsicChecksum( + key: string, + providedChecksum: string, +): string { + const checksum = providedChecksum || KNOWN_CHECKSUMS[key]; + if (!checksum) { + throw new Error( + `No bundled checksum for ${key}. With require-checksums enabled, update setup-uv or provide the checksum input for this archive.`, + ); + } + if (!/^[a-f0-9]{64}$/.test(checksum)) { + throw new Error(`Expected a SHA-256 checksum for ${key}.`); + } + return checksum; +} + export function tryGetFromToolCache( arch: Architecture, version: string, + toolCacheName = TOOL_CACHE_NAME, ): { version: string; installedPath: string | undefined } { core.debug(`Trying to get uv from tool cache for ${version}...`); - const cachedVersions = tc.findAllVersions(TOOL_CACHE_NAME, arch); + const cachedVersions = tc.findAllVersions(toolCacheName, arch); core.debug(`Cached versions: ${cachedVersions}`); let resolvedVersion = tc.evaluateVersions(cachedVersions, version); if (resolvedVersion === "") { resolvedVersion = version; } - const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch); + const installedPath = tc.find(toolCacheName, resolvedVersion, arch); return { installedPath, version: resolvedVersion }; } @@ -38,6 +56,7 @@ export async function downloadVersion( githubToken: string, manifestUrl?: string, downloadFromAstralMirror = true, + toolCacheName = TOOL_CACHE_NAME, ): Promise<{ version: string; cachedToolDir: string }> { const artifact = await getArtifact(version, arch, platform, manifestUrl); @@ -71,6 +90,7 @@ export async function downloadVersion( resolvedChecksum, manifestChecksum, githubTokenForUrl(downloadUrl, githubToken), + toolCacheName, ); } catch (err) { if (mirrorUrl === undefined) { @@ -90,6 +110,7 @@ export async function downloadVersion( resolvedChecksum, manifestChecksum, githubTokenForUrl(artifact.downloadUrl, githubToken), + toolCacheName, ); } } @@ -128,6 +149,7 @@ async function downloadArtifact( checksum: string | undefined, manifestChecksum: string | undefined, githubToken: string | undefined, + toolCacheName: string, ): Promise<{ version: string; cachedToolDir: string }> { log.info(`Downloading uv from "${downloadUrl}" ...`); const downloadPath = await tc.downloadTool( @@ -165,12 +187,7 @@ async function downloadArtifact( uvDir = path.join(extractedDir, artifactName); } - const cachedToolDir = await tc.cacheDir( - uvDir, - TOOL_CACHE_NAME, - version, - arch, - ); + const cachedToolDir = await tc.cacheDir(uvDir, toolCacheName, version, arch); return { cachedToolDir, version }; } diff --git a/src/setup-uv.ts b/src/setup-uv.ts index 08f0204..f87404a 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -5,9 +5,14 @@ import * as exec from "@actions/exec"; import { restoreCache } from "./cache/restore-cache"; import { downloadVersion, + getIntrinsicChecksum, tryGetFromToolCache, } from "./download/download-version"; -import { STATE_UV_PATH, STATE_UV_VERSION } from "./utils/constants"; +import { + STATE_UV_PATH, + STATE_UV_VERSION, + TOOL_CACHE_NAME, +} from "./utils/constants"; import { CacheLocalSource, loadInputs, type SetupInputs } from "./utils/inputs"; import * as log from "./utils/logging"; import { @@ -147,7 +152,21 @@ async function setupUv( versionFile: inputs.versionFile, workingDirectory: inputs.workingDirectory, }); - const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion); + let checksum = inputs.checksum; + let toolCacheName = TOOL_CACHE_NAME; + if (inputs.requireChecksums) { + checksum = getIntrinsicChecksum( + `${arch}-${platform}-${resolvedVersion}`, + inputs.checksum, + ); + // A regular tool-cache entry may have been verified using a manifest checksum. + toolCacheName = `${TOOL_CACHE_NAME}-${checksum}`; + } + const toolCacheResult = tryGetFromToolCache( + arch, + resolvedVersion, + toolCacheName, + ); if (toolCacheResult.installedPath) { log.info(`Found uv in tool-cache for ${toolCacheResult.version}`); return { @@ -160,10 +179,11 @@ async function setupUv( platform, arch, resolvedVersion, - inputs.checksum, + checksum, inputs.githubToken, inputs.manifestFile, inputs.downloadFromAstralMirror, + toolCacheName, ); return { diff --git a/src/utils/inputs.ts b/src/utils/inputs.ts index c342a2b..7c502a2 100644 --- a/src/utils/inputs.ts +++ b/src/utils/inputs.ts @@ -30,6 +30,7 @@ export interface SetupInputs { noProject: boolean; venvPath: string; checksum: string; + requireChecksums: boolean; enableCache: boolean; restoreCache: boolean; saveCache: boolean; @@ -63,6 +64,7 @@ export function loadInputs(): SetupInputs { const noProject = core.getBooleanInput("no-project"); const venvPath = getVenvPath(workingDirectory, activateEnvironment); const checksum = core.getInput("checksum"); + const requireChecksums = core.getBooleanInput("require-checksums"); const enableCache = getEnableCache(); const restoreCache = core.getInput("restore-cache") === "true"; const saveCache = getSaveCache(); @@ -110,6 +112,7 @@ export function loadInputs(): SetupInputs { pythonDir, pythonVersion, quiet, + requireChecksums, resolutionStrategy, restoreCache, saveCache,