mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-09-21 03:16:58 +00:00
committed by
GitHub
parent
f67343ac2e
commit
dc724a12b6
78
.github/workflows/test.yml
vendored
78
.github/workflows/test.yml
vendored
@ -457,7 +457,7 @@ jobs:
|
||||
working-directory: __tests__/fixtures/requirements-txt-project
|
||||
test-restore-cache-requirements-txt:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test-setup-cache
|
||||
needs: test-setup-cache-requirements-txt
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
@ -525,6 +525,78 @@ jobs:
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
|
||||
|
||||
test-setup-cache-save-cache-false:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
save-cache: false
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-false
|
||||
- run: uv sync
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
shell: bash
|
||||
test-restore-cache-save-cache-false:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test-setup-cache-save-cache-false
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-false
|
||||
- name: Cache was not hit
|
||||
run: |
|
||||
if [ "$CACHE_HIT" == "true" ]; then
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
|
||||
|
||||
test-setup-cache-restore-cache-false:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Setup with cache
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-restore-cache-false
|
||||
- run: uv sync
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
shell: bash
|
||||
test-restore-cache-restore-cache-false:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test-setup-cache-restore-cache-false
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
restore-cache: false
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-restore-cache-false
|
||||
- name: Cache was not hit
|
||||
run: |
|
||||
if [ "$CACHE_HIT" == "true" ]; then
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
|
||||
|
||||
test-cache-local:
|
||||
strategy:
|
||||
matrix:
|
||||
@ -747,6 +819,10 @@ jobs:
|
||||
- test-restore-cache-requirements-txt
|
||||
- test-setup-cache-dependency-glob
|
||||
- test-restore-cache-dependency-glob
|
||||
- test-setup-cache-save-cache-false
|
||||
- test-restore-cache-save-cache-false
|
||||
- test-setup-cache-restore-cache-false
|
||||
- test-restore-cache-restore-cache-false
|
||||
- test-setup-cache-local
|
||||
- test-restore-cache-local
|
||||
- test-tilde-expansion-cache-local-path
|
||||
|
29
README.md
29
README.md
@ -22,6 +22,8 @@ Set up your GitHub Actions workflow with a specific version of [uv](https://docs
|
||||
- [Validate checksum](#validate-checksum)
|
||||
- [Enable Caching](#enable-caching)
|
||||
- [Cache dependency glob](#cache-dependency-glob)
|
||||
- [Restore cache](#restore-cache)
|
||||
- [Save cache](#save-cache)
|
||||
- [Local cache path](#local-cache-path)
|
||||
- [Disable cache pruning](#disable-cache-pruning)
|
||||
- [Ignore nothing to cache](#ignore-nothing-to-cache)
|
||||
@ -284,6 +286,33 @@ changes. If you use relative paths, they are relative to the repository root.
|
||||
cache-dependency-glob: ""
|
||||
```
|
||||
|
||||
#### Restore cache
|
||||
|
||||
Restoring an existing cache can be enabled or disabled with the `restore-cache` input.
|
||||
By default, the cache will be restored.
|
||||
|
||||
```yaml
|
||||
- name: Don't restore an existing cache
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
enable-cache: true
|
||||
restore-cache: false
|
||||
```
|
||||
|
||||
#### Save cache
|
||||
|
||||
You can also disable saving the cache after the run with the `save-cache` input.
|
||||
This can be useful to save cache storage when you know you will not use the cache of the run again.
|
||||
By default, the cache will be saved.
|
||||
|
||||
```yaml
|
||||
- name: Don't save the cache after the run
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
enable-cache: true
|
||||
save-cache: false
|
||||
```
|
||||
|
||||
### Local cache path
|
||||
|
||||
This action controls where uv stores its cache on the runner's filesystem by setting `UV_CACHE_DIR`.
|
||||
|
@ -44,6 +44,12 @@ inputs:
|
||||
**/*constraints*.in
|
||||
**/pyproject.toml
|
||||
**/uv.lock
|
||||
restore-cache:
|
||||
description: "Whether to restore the cache if found."
|
||||
default: "true"
|
||||
save-cache:
|
||||
description: "Whether to save the cache after the run."
|
||||
default: "true"
|
||||
cache-suffix:
|
||||
description: "Suffix for the cache key"
|
||||
required: false
|
||||
|
17
dist/save-cache/index.js
generated
vendored
17
dist/save-cache/index.js
generated
vendored
@ -89809,6 +89809,11 @@ exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
const CACHE_VERSION = "1";
|
||||
async function restoreCache() {
|
||||
const cacheKey = await computeKeys();
|
||||
core.saveState(exports.STATE_CACHE_KEY, cacheKey);
|
||||
if (!inputs_1.restoreCache) {
|
||||
core.info("restore-cache is false. Skipping restore cache step.");
|
||||
return;
|
||||
}
|
||||
let matchedKey;
|
||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||
try {
|
||||
@ -89820,7 +89825,6 @@ async function restoreCache() {
|
||||
core.setOutput("cache-hit", false);
|
||||
return;
|
||||
}
|
||||
core.saveState(exports.STATE_CACHE_KEY, cacheKey);
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
}
|
||||
async function computeKeys() {
|
||||
@ -90019,7 +90023,12 @@ const inputs_1 = __nccwpck_require__(9612);
|
||||
async function run() {
|
||||
try {
|
||||
if (inputs_1.enableCache) {
|
||||
await saveCache();
|
||||
if (inputs_1.saveCache) {
|
||||
await saveCache();
|
||||
}
|
||||
else {
|
||||
core.info("save-cache is false. Skipping save cache step.");
|
||||
}
|
||||
// node will stay alive if any promises are not resolved,
|
||||
// which is a possibility if HTTP requests are dangling
|
||||
// due to retries or timeouts. We know that if we got here
|
||||
@ -90121,7 +90130,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.serverUrl = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
|
||||
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.serverUrl = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
|
||||
const node_path_1 = __importDefault(__nccwpck_require__(6760));
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
exports.workingDirectory = core.getInput("working-directory");
|
||||
@ -90131,6 +90140,8 @@ exports.pythonVersion = core.getInput("python-version");
|
||||
exports.activateEnvironment = core.getBooleanInput("activate-environment");
|
||||
exports.checkSum = core.getInput("checksum");
|
||||
exports.enableCache = getEnableCache();
|
||||
exports.restoreCache = core.getInput("restore-cache") === "true";
|
||||
exports.saveCache = core.getInput("save-cache") === "true";
|
||||
exports.cacheSuffix = core.getInput("cache-suffix") || "";
|
||||
exports.cacheLocalPath = getCacheLocalPath();
|
||||
exports.cacheDependencyGlob = getCacheDependencyGlob();
|
||||
|
10
dist/setup/index.js
generated
vendored
10
dist/setup/index.js
generated
vendored
@ -124221,6 +124221,11 @@ exports.STATE_CACHE_MATCHED_KEY = "cache-matched-key";
|
||||
const CACHE_VERSION = "1";
|
||||
async function restoreCache() {
|
||||
const cacheKey = await computeKeys();
|
||||
core.saveState(exports.STATE_CACHE_KEY, cacheKey);
|
||||
if (!inputs_1.restoreCache) {
|
||||
core.info("restore-cache is false. Skipping restore cache step.");
|
||||
return;
|
||||
}
|
||||
let matchedKey;
|
||||
core.info(`Trying to restore uv cache from GitHub Actions cache with key: ${cacheKey}`);
|
||||
try {
|
||||
@ -124232,7 +124237,6 @@ async function restoreCache() {
|
||||
core.setOutput("cache-hit", false);
|
||||
return;
|
||||
}
|
||||
core.saveState(exports.STATE_CACHE_KEY, cacheKey);
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
}
|
||||
async function computeKeys() {
|
||||
@ -128634,7 +128638,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.serverUrl = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
|
||||
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.serverUrl = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
|
||||
const node_path_1 = __importDefault(__nccwpck_require__(76760));
|
||||
const core = __importStar(__nccwpck_require__(37484));
|
||||
exports.workingDirectory = core.getInput("working-directory");
|
||||
@ -128644,6 +128648,8 @@ exports.pythonVersion = core.getInput("python-version");
|
||||
exports.activateEnvironment = core.getBooleanInput("activate-environment");
|
||||
exports.checkSum = core.getInput("checksum");
|
||||
exports.enableCache = getEnableCache();
|
||||
exports.restoreCache = core.getInput("restore-cache") === "true";
|
||||
exports.saveCache = core.getInput("save-cache") === "true";
|
||||
exports.cacheSuffix = core.getInput("cache-suffix") || "";
|
||||
exports.cacheLocalPath = getCacheLocalPath();
|
||||
exports.cacheDependencyGlob = getCacheDependencyGlob();
|
||||
|
9
src/cache/restore-cache.ts
vendored
9
src/cache/restore-cache.ts
vendored
@ -8,6 +8,7 @@ import {
|
||||
cacheSuffix,
|
||||
pruneCache,
|
||||
pythonVersion as pythonVersionInput,
|
||||
restoreCache as shouldRestoreCache,
|
||||
workingDirectory,
|
||||
} from "../utils/inputs";
|
||||
import { getArch, getPlatform } from "../utils/platforms";
|
||||
@ -18,6 +19,12 @@ const CACHE_VERSION = "1";
|
||||
|
||||
export async function restoreCache(): Promise<void> {
|
||||
const cacheKey = await computeKeys();
|
||||
core.saveState(STATE_CACHE_KEY, cacheKey);
|
||||
|
||||
if (!shouldRestoreCache) {
|
||||
core.info("restore-cache is false. Skipping restore cache step.");
|
||||
return;
|
||||
}
|
||||
|
||||
let matchedKey: string | undefined;
|
||||
core.info(
|
||||
@ -32,8 +39,6 @@ export async function restoreCache(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
core.saveState(STATE_CACHE_KEY, cacheKey);
|
||||
|
||||
handleMatchResult(matchedKey, cacheKey);
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,17 @@ import {
|
||||
enableCache,
|
||||
ignoreNothingToCache,
|
||||
pruneCache as shouldPruneCache,
|
||||
saveCache as shouldSaveCache,
|
||||
} from "./utils/inputs";
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
if (enableCache) {
|
||||
await saveCache();
|
||||
if (shouldSaveCache) {
|
||||
await saveCache();
|
||||
} else {
|
||||
core.info("save-cache is false. Skipping save cache step.");
|
||||
}
|
||||
// node will stay alive if any promises are not resolved,
|
||||
// which is a possibility if HTTP requests are dangling
|
||||
// due to retries or timeouts. We know that if we got here
|
||||
|
@ -8,6 +8,8 @@ export const pythonVersion = core.getInput("python-version");
|
||||
export const activateEnvironment = core.getBooleanInput("activate-environment");
|
||||
export const checkSum = core.getInput("checksum");
|
||||
export const enableCache = getEnableCache();
|
||||
export const restoreCache = core.getInput("restore-cache") === "true";
|
||||
export const saveCache = core.getInput("save-cache") === "true";
|
||||
export const cacheSuffix = core.getInput("cache-suffix") || "";
|
||||
export const cacheLocalPath = getCacheLocalPath();
|
||||
export const cacheDependencyGlob = getCacheDependencyGlob();
|
||||
|
Reference in New Issue
Block a user