Skip to content

Commit 3b9817b

Browse files
merlinz01eifingercharliermarsh
authored
feat: add option to disable cache pruning (#134)
This PR adds an input to control whether or not the cache is pruned before saving. Closes #122 --------- Co-authored-by: Kevin Stillhammer <[email protected]> Co-authored-by: Charlie Marsh <[email protected]> Co-authored-by: Charlie Marsh <[email protected]>
1 parent cf841c2 commit 3b9817b

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ It defaults to `setup-uv-cache` in the `TMP` dir, `D:\a\_temp\uv-tool-dir` on Wi
166166
cache-local-path: "/path/to/cache"
167167
```
168168

169+
### Disable cache pruning
170+
171+
By default, the uv cache is pruned after every run, removing pre-built wheels, but retaining any
172+
wheels that were built from source. On GitHub-hosted runners, it's typically faster to omit those
173+
pre-built wheels from the cache (and instead re-download them from the registry on each run).
174+
However, on self-hosted or local runners, preserving the cache may be more efficient. See
175+
the[documentation](https://docs.astral.sh/uv/concepts/cache/#caching-in-continuous-integration) for
176+
more.
177+
178+
If you want to persist the entire cache across runs, disable cache pruning with the `prune-cache`
179+
input.
180+
181+
```yaml
182+
- name: Don't prune the cache before saving it
183+
uses: astral-sh/setup-uv@v3
184+
with:
185+
enable-cache: true
186+
prune-cache: false
187+
```
188+
169189
### GitHub authentication token
170190

171191
This action uses the GitHub API to fetch the uv release artifacts. To avoid hitting the GitHub API

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ inputs:
2929
cache-local-path:
3030
description: "Local path to store the cache."
3131
default: ""
32+
prune-cache:
33+
description: "Prune cache before saving."
34+
default: true
3235
tool-dir:
3336
description: "Custom path to set UV_TOOL_DIR to."
3437
required: false

dist/save-cache/index.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/save-cache.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
STATE_CACHE_MATCHED_KEY,
66
STATE_CACHE_KEY,
77
} from "./cache/restore-cache";
8-
import { cacheLocalPath, enableCache } from "./utils/inputs";
8+
import {
9+
cacheLocalPath,
10+
enableCache,
11+
pruneCache as shouldPruneCache,
12+
} from "./utils/inputs";
913

1014
export async function run(): Promise<void> {
1115
try {
@@ -32,7 +36,9 @@ async function saveCache(): Promise<void> {
3236
return;
3337
}
3438

35-
await pruneCache();
39+
if (shouldPruneCache) {
40+
await pruneCache();
41+
}
3642

3743
core.info(`Saving cache path: ${cacheLocalPath}`);
3844
await cache.saveCache([cacheLocalPath], cacheKey);

src/utils/inputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const enableCache = core.getInput("enable-cache") === "true";
77
export const cacheSuffix = core.getInput("cache-suffix") || "";
88
export const cacheLocalPath = getCacheLocalPath();
99
export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
10+
export const pruneCache = core.getInput("prune-cache") === "true";
1011
export const toolBinDir = getToolBinDir();
1112
export const toolDir = getToolDir();
1213
export const githubToken = core.getInput("github-token");

0 commit comments

Comments
 (0)