From bd646556e49751056bbad04ace88312c18558286 Mon Sep 17 00:00:00 2001 From: merlinz01 Date: Thu, 24 Oct 2024 16:52:30 -0400 Subject: [PATCH] feat: add option to disable cache pruning --- README.md | 14 ++++++++++++++ action.yml | 3 +++ src/save-cache.ts | 6 ++++-- src/utils/inputs.ts | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3be400c..86386de 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,20 @@ It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Wi cache-local-path: "/path/to/cache" ``` +### Disable cache pruning + +By default, the cache is pruned after a run, which means that all pre-built wheels are removed from +the cache ([documentation](https://docs.astral.sh/uv/concepts/cache/#caching-in-continuous-integration)). +If you want to keep the cache after a run, you can disable cache pruning with the `prune-cache` input. + +```yaml +- name: Don't prune the cache before saving it + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + prune-cache: false +``` + ### GitHub authentication token This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API diff --git a/action.yml b/action.yml index 8cbe5b3..bcb05f9 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,9 @@ inputs: cache-local-path: description: "Local path to store the cache." default: "" + prune-cache: + description: "Prune cache before saving." + default: true tool-dir: description: "Custom path to set UV_TOOL_DIR to." required: false diff --git a/src/save-cache.ts b/src/save-cache.ts index 3d9558b..027456e 100644 --- a/src/save-cache.ts +++ b/src/save-cache.ts @@ -5,7 +5,7 @@ import { STATE_CACHE_MATCHED_KEY, STATE_CACHE_KEY, } from "./cache/restore-cache"; -import { cacheLocalPath, enableCache } from "./utils/inputs"; +import { cacheLocalPath, enableCache, pruneCache as pruneCacheOption } from "./utils/inputs"; export async function run(): Promise { try { @@ -32,7 +32,9 @@ async function saveCache(): Promise { return; } - await pruneCache(); + if (pruneCacheOption) { + await pruneCache(); + } core.info(`Saving cache path: ${cacheLocalPath}`); await cache.saveCache([cacheLocalPath], cacheKey); diff --git a/src/utils/inputs.ts b/src/utils/inputs.ts index cdad291..323f6fb 100644 --- a/src/utils/inputs.ts +++ b/src/utils/inputs.ts @@ -7,6 +7,7 @@ export const enableCache = core.getInput("enable-cache") === "true"; export const cacheSuffix = core.getInput("cache-suffix") || ""; export const cacheLocalPath = getCacheLocalPath(); export const cacheDependencyGlob = core.getInput("cache-dependency-glob"); +export const pruneCache = (core.getInput("prune-cache") || "true") === "true"; export const toolBinDir = getToolBinDir(); export const toolDir = getToolDir(); export const githubToken = core.getInput("github-token");