Respect UV_CACHE_DIR and cache-dir (#612)
Some checks failed
CodeQL / Analyze (TypeScript) (push) Failing after 2s
test / lint (push) Failing after 2s
test / test-default-version (ubuntu-latest) (push) Failing after 2s
test / test-uv-no-modify-path (push) Failing after 2s
test / test-specific-version (map[expected-version:0.3.0 version-input:0.3.0]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.3.2 version-input:0.3.2]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.3.5 version-input:0.3.x]) (push) Failing after 2s
test / test-specific-version (map[expected-version:0.3.5 version-input:0.3]) (push) Failing after 2s
test / test-specific-version (map[expected-version:0.4.30 version-input:>=0.4.25,<0.5]) (push) Failing after 2s
test / test-latest-version (>=0.8) (push) Failing after 1s
test / test-latest-version (latest) (push) Failing after 2s
test / test-setup-cache-save-cache-false (push) Failing after 1s
test / test-from-working-directory-version (map[expected-version:0.5.14 working-directory:__tests__/fixtures/pyproject-toml-project]) (push) Failing after 2s
test / test-from-working-directory-version (map[expected-version:0.5.15 working-directory:__tests__/fixtures/uv-toml-project]) (push) Failing after 1s
test / test-version-file-version (map[expected-version:0.5.15 version-file:__tests__/fixtures/.tool-versions]) (push) Failing after 2s
test / test-version-file-version (map[expected-version:0.6.17 version-file:__tests__/fixtures/uv-in-requirements-txt-project/requirements.txt]) (push) Failing after 2s
test / test-version-file-version (map[expected-version:0.8.3 version-file:__tests__/fixtures/uv-in-requirements-hash-txt-project/requirements.txt]) (push) Failing after 1s
test / test-malformed-pyproject-file-fallback (push) Failing after 1s
test / test-checksum (map[checksum:4d9279ad5ca596b1e2d703901d508430eb07564dc4d8837de9e2fca9c90f8ecd os:ubuntu-latest]) (push) Failing after 1s
test / test-with-explicit-token (push) Failing after 1s
test / test-uvx (push) Failing after 1s
test / test-tool-install (ubuntu-latest) (push) Failing after 1s
test / test-python-version (ubuntu-latest) (push) Failing after 1s
test / test-activate-environment (ubuntu-latest) (push) Failing after 2s
test / test-setup-cache (auto, ubuntu-latest) (push) Failing after 1s
test / test-setup-cache (false, ubuntu-latest) (push) Failing after 2s
test / test-setup-cache (true, ubuntu-latest) (push) Failing after 2s
test / test-setup-cache-requirements-txt (push) Failing after 2s
test / test-musl (push) Failing after 5s
test / test-restore-cache-requirements-txt (push) Has been skipped
test / test-setup-cache-dependency-glob (push) Failing after 2s
test / test-restore-cache-dependency-glob (push) Has been skipped
test / test-restore-cache-save-cache-false (push) Has been skipped
test / test-setup-cache-restore-cache-false (push) Failing after 1s
test / test-restore-cache-restore-cache-false (push) Has been skipped
test / test-cache-local (map[expected-cache-dir:/home/runner/work/_temp/setup-uv-cache os:ubuntu-latest]) (push) Failing after 2s
test / test-cache-local-cache-disabled (push) Failing after 4s
test / test-no-python-version (push) Failing after 5s
test / test-custom-manifest-file (push) Failing after 5s
test / test-absolute-path (push) Failing after 5s
test / test-relative-path (push) Failing after 5s
test / test-cache-prune-force (push) Failing after 5s
test / test-cache-dir-from-file (push) Failing after 5s
Release Drafter / ✏️ Draft release (push) Has been cancelled
test / test-default-version (macos-14) (push) Has been cancelled
test / test-default-version (macos-latest) (push) Has been cancelled
test / test-default-version (windows-latest) (push) Has been cancelled
test / test-checksum (map[checksum:a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218 os:macos-latest]) (push) Has been cancelled
test / test-tool-install (macos-14) (push) Has been cancelled
test / test-tool-install (macos-latest) (push) Has been cancelled
test / test-tool-install (windows-latest) (push) Has been cancelled
test / test-tilde-expansion-tool-dirs (push) Has been cancelled
test / test-python-version (macos-latest) (push) Has been cancelled
test / test-python-version (windows-latest) (push) Has been cancelled
test / test-activate-environment (macos-latest) (push) Has been cancelled
test / test-activate-environment (windows-latest) (push) Has been cancelled
test / test-setup-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (auto, windows-latest) (push) Has been cancelled
test / test-setup-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (false, windows-latest) (push) Has been cancelled
test / test-setup-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (true, windows-latest) (push) Has been cancelled
test / test-cache-local (map[expected-cache-dir:/home/ubuntu/.cache/uv os:selfhosted-ubuntu-arm64]) (push) Has been cancelled
test / test-cache-local (map[expected-cache-dir:D:\a\_temp\setup-uv-cache os:windows-latest]) (push) Has been cancelled
test / test-setup-cache-local (push) Has been cancelled
test / test-tilde-expansion-cache-local-path (push) Has been cancelled
test / test-tilde-expansion-cache-dependency-glob (push) Has been cancelled
test / test-restore-cache (false, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache (false, windows-latest) (push) Has been cancelled
test / test-restore-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-restore-cache (true, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache (true, windows-latest) (push) Has been cancelled
test / test-restore-cache (auto, windows-latest) (push) Has been cancelled
test / test-restore-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-restore-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-restore-cache (auto, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache-local (push) Has been cancelled
test / cleanup-tilde-expansion-tests (push) Has been cancelled
test / all-tests-passed (push) Has been cancelled

Fixes: #583
This commit is contained in:
Kevin Stillhammer
2025-10-07 16:08:30 +02:00
committed by GitHub
parent f610be5ff9
commit 535dc2664c
13 changed files with 1277 additions and 96 deletions

997
dist/save-cache/index.js generated vendored

File diff suppressed because it is too large Load Diff

169
dist/setup/index.js generated vendored
View File

@@ -129387,6 +129387,7 @@ const core = __importStar(__nccwpck_require__(37484));
const exec = __importStar(__nccwpck_require__(95236));
const restore_cache_1 = __nccwpck_require__(95391);
const download_version_1 = __nccwpck_require__(28255);
const config_file_1 = __nccwpck_require__(27846);
const constants_1 = __nccwpck_require__(56156);
const inputs_1 = __nccwpck_require__(9612);
const platforms_1 = __nccwpck_require__(98361);
@@ -129409,7 +129410,7 @@ async function run() {
setupPython();
await activateEnvironment();
addMatchers();
setCacheDir(inputs_1.cacheLocalPath);
setCacheDir();
core.setOutput("uv-version", setupResult.version);
core.saveState(constants_1.STATE_UV_VERSION, setupResult.version);
core.info(`Successfully installed uv version ${setupResult.version}`);
@@ -129537,9 +129538,16 @@ async function activateEnvironment() {
core.exportVariable("VIRTUAL_ENV", path.resolve(`${inputs_1.workingDirectory}${path.sep}.venv`));
}
}
function setCacheDir(cacheLocalPath) {
core.exportVariable("UV_CACHE_DIR", cacheLocalPath);
core.info(`Set UV_CACHE_DIR to ${cacheLocalPath}`);
function setCacheDir() {
if (inputs_1.enableCache) {
const cacheDirFromConfig = (0, config_file_1.getConfigValueFromTomlFile)("", "cache-dir");
if (cacheDirFromConfig !== undefined) {
core.info("Using cache-dir from uv config file, not modifying UV_CACHE_DIR");
return;
}
core.exportVariable("UV_CACHE_DIR", inputs_1.cacheLocalPath);
core.info(`Set UV_CACHE_DIR to ${inputs_1.cacheLocalPath}`);
}
}
function addMatchers() {
if (inputs_1.addProblemMatchers) {
@@ -129550,6 +129558,67 @@ function addMatchers() {
run();
/***/ }),
/***/ 27846:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getConfigValueFromTomlFile = getConfigValueFromTomlFile;
const node_fs_1 = __importDefault(__nccwpck_require__(73024));
const toml = __importStar(__nccwpck_require__(27106));
function getConfigValueFromTomlFile(filePath, key) {
if (!node_fs_1.default.existsSync(filePath) || !filePath.endsWith(".toml")) {
return undefined;
}
const fileContent = node_fs_1.default.readFileSync(filePath, "utf-8");
if (filePath.endsWith("pyproject.toml")) {
const tomlContent = toml.parse(fileContent);
return tomlContent?.tool?.uv?.[key];
}
const tomlContent = toml.parse(fileContent);
return tomlContent[key];
}
/***/ }),
/***/ 56156:
@@ -129642,6 +129711,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = 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));
const config_file_1 = __nccwpck_require__(27846);
exports.workingDirectory = core.getInput("working-directory");
exports.version = core.getInput("version");
exports.versionFile = getVersionFile();
@@ -129711,6 +129781,14 @@ function getCacheLocalPath() {
const tildeExpanded = expandTilde(cacheLocalPathInput);
return resolveRelativePath(tildeExpanded);
}
const cacheDirFromConfig = getCacheDirFromConfig();
if (cacheDirFromConfig !== undefined) {
return cacheDirFromConfig;
}
if (process.env.UV_CACHE_DIR !== undefined) {
core.info(`UV_CACHE_DIR is already set to ${process.env.UV_CACHE_DIR}`);
return process.env.UV_CACHE_DIR;
}
if (process.env.RUNNER_ENVIRONMENT === "github-hosted") {
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${node_path_1.default.sep}setup-uv-cache`;
@@ -129722,6 +129800,24 @@ function getCacheLocalPath() {
}
return `${process.env.HOME}${node_path_1.default.sep}.cache${node_path_1.default.sep}uv`;
}
function getCacheDirFromConfig() {
for (const filePath of [exports.versionFile, "uv.toml", "pyproject.toml"]) {
const resolvedPath = resolveRelativePath(filePath);
try {
const cacheDir = (0, config_file_1.getConfigValueFromTomlFile)(resolvedPath, "cache-dir");
if (cacheDir !== undefined) {
core.info(`Found cache-dir in ${resolvedPath}: ${cacheDir}`);
return cacheDir;
}
}
catch (err) {
const message = err.message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
}
return undefined;
}
function getCacheDependencyGlob() {
const cacheDependencyGlobInput = core.getInput("cache-dependency-glob");
if (cacheDependencyGlobInput !== "") {
@@ -129888,67 +129984,6 @@ async function isMuslOs() {
}
/***/ }),
/***/ 9931:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getRequiredVersionFromConfigFile = getRequiredVersionFromConfigFile;
const node_fs_1 = __importDefault(__nccwpck_require__(73024));
const toml = __importStar(__nccwpck_require__(27106));
function getRequiredVersionFromConfigFile(filePath) {
if (!filePath.endsWith(".toml")) {
return undefined;
}
const fileContent = node_fs_1.default.readFileSync(filePath, "utf-8");
if (filePath.endsWith("pyproject.toml")) {
const tomlContent = toml.parse(fileContent);
return tomlContent?.tool?.uv?.["required-version"];
}
const tomlContent = toml.parse(fileContent);
return tomlContent["required-version"];
}
/***/ }),
/***/ 4569:
@@ -130068,7 +130103,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getUvVersionFromFile = getUvVersionFromFile;
const node_fs_1 = __importDefault(__nccwpck_require__(73024));
const core = __importStar(__nccwpck_require__(37484));
const config_file_1 = __nccwpck_require__(9931);
const config_file_1 = __nccwpck_require__(27846);
const requirements_file_1 = __nccwpck_require__(4569);
const tool_versions_file_1 = __nccwpck_require__(4895);
function getUvVersionFromFile(filePath) {
@@ -130081,7 +130116,7 @@ function getUvVersionFromFile(filePath) {
try {
uvVersion = (0, tool_versions_file_1.getUvVersionFromToolVersions)(filePath);
if (uvVersion === undefined) {
uvVersion = (0, config_file_1.getRequiredVersionFromConfigFile)(filePath);
uvVersion = (0, config_file_1.getConfigValueFromTomlFile)(filePath, "required-version");
}
if (uvVersion === undefined) {
uvVersion = (0, requirements_file_1.getUvVersionFromRequirementsFile)(filePath);