feat: add option to disable cache pruning

This commit is contained in:
merlinz01 2024-10-24 16:52:30 -04:00
parent cf841c25e2
commit bd646556e4
4 changed files with 22 additions and 2 deletions

View file

@ -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" 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 ### GitHub authentication token
This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API

View file

@ -29,6 +29,9 @@ inputs:
cache-local-path: cache-local-path:
description: "Local path to store the cache." description: "Local path to store the cache."
default: "" default: ""
prune-cache:
description: "Prune cache before saving."
default: true
tool-dir: tool-dir:
description: "Custom path to set UV_TOOL_DIR to." description: "Custom path to set UV_TOOL_DIR to."
required: false required: false

View file

@ -5,7 +5,7 @@ import {
STATE_CACHE_MATCHED_KEY, STATE_CACHE_MATCHED_KEY,
STATE_CACHE_KEY, STATE_CACHE_KEY,
} from "./cache/restore-cache"; } from "./cache/restore-cache";
import { cacheLocalPath, enableCache } from "./utils/inputs"; import { cacheLocalPath, enableCache, pruneCache as pruneCacheOption } from "./utils/inputs";
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
@ -32,7 +32,9 @@ async function saveCache(): Promise<void> {
return; return;
} }
if (pruneCacheOption) {
await pruneCache(); await pruneCache();
}
core.info(`Saving cache path: ${cacheLocalPath}`); core.info(`Saving cache path: ${cacheLocalPath}`);
await cache.saveCache([cacheLocalPath], cacheKey); await cache.saveCache([cacheLocalPath], cacheKey);

View file

@ -7,6 +7,7 @@ export const enableCache = core.getInput("enable-cache") === "true";
export const cacheSuffix = core.getInput("cache-suffix") || ""; export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath(); export const cacheLocalPath = getCacheLocalPath();
export const cacheDependencyGlob = core.getInput("cache-dependency-glob"); export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
export const pruneCache = (core.getInput("prune-cache") || "true") === "true";
export const toolBinDir = getToolBinDir(); export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir(); export const toolDir = getToolDir();
export const githubToken = core.getInput("github-token"); export const githubToken = core.getInput("github-token");