Files
setup-uv/src/utils/inputs.ts
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
4.6 KiB
TypeScript
Raw Normal View History

2024-09-05 08:06:45 -04:00
import * as core from "@actions/core";
import path from "node:path";
2024-08-23 23:58:26 +02:00
export const workingDirectory = core.getInput("working-directory");
2024-09-05 08:06:45 -04:00
export const version = core.getInput("version");
export const versionFile = getVersionFile();
2024-11-28 21:41:37 +01:00
export const pythonVersion = core.getInput("python-version");
export const activateEnvironment = core.getBooleanInput("activate-environment");
2024-09-05 08:06:45 -04:00
export const checkSum = core.getInput("checksum");
export const enableCache = getEnableCache();
2024-09-05 08:06:45 -04:00
export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath();
export const cacheDependencyGlob = getCacheDependencyGlob();
export const pruneCache = core.getInput("prune-cache") === "true";
export const ignoreNothingToCache =
core.getInput("ignore-nothing-to-cache") === "true";
2025-03-16 22:15:17 +01:00
export const ignoreEmptyWorkdir =
core.getInput("ignore-empty-workdir") === "true";
2024-09-21 10:14:36 +02:00
export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir();
2025-05-23 09:43:52 +02:00
export const serverUrl = core.getInput("server-url");
2024-09-21 10:14:36 +02:00
export const githubToken = core.getInput("github-token");
2025-06-18 22:33:20 +02:00
export const manifestFile = getManifestFile();
2024-09-21 10:14:36 +02:00
function getVersionFile(): string {
const versionFileInput = core.getInput("version-file");
if (versionFileInput !== "") {
const tildeExpanded = expandTilde(versionFileInput);
return resolveRelativePath(tildeExpanded);
}
return versionFileInput;
}
function getEnableCache(): boolean {
const enableCacheInput = core.getInput("enable-cache");
if (enableCacheInput === "auto") {
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
}
return enableCacheInput === "true";
}
2024-09-21 10:14:36 +02:00
function getToolBinDir(): string | undefined {
const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") {
const tildeExpanded = expandTilde(toolBinDirInput);
return resolveRelativePath(tildeExpanded);
2024-09-21 10:14:36 +02:00
}
if (process.platform === "win32") {
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${path.sep}uv-tool-bin-dir`;
}
throw Error(
"Could not determine UV_TOOL_BIN_DIR. Please make sure RUNNER_TEMP is set or provide the tool-bin-dir input",
);
}
return undefined;
}
function getToolDir(): string | undefined {
const toolDirInput = core.getInput("tool-dir");
if (toolDirInput !== "") {
const tildeExpanded = expandTilde(toolDirInput);
return resolveRelativePath(tildeExpanded);
2024-09-21 10:14:36 +02:00
}
if (process.platform === "win32") {
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${path.sep}uv-tool-dir`;
}
throw Error(
"Could not determine UV_TOOL_DIR. Please make sure RUNNER_TEMP is set or provide the tool-dir input",
);
}
return undefined;
}
function getCacheLocalPath(): string {
const cacheLocalPathInput = core.getInput("cache-local-path");
if (cacheLocalPathInput !== "") {
const tildeExpanded = expandTilde(cacheLocalPathInput);
return resolveRelativePath(tildeExpanded);
}
if (process.env.RUNNER_ENVIRONMENT === "github-hosted") {
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${path.sep}setup-uv-cache`;
}
throw Error(
"Could not determine UV_CACHE_DIR. Please make sure RUNNER_TEMP is set or provide the cache-local-path input",
);
}
if (process.platform === "win32") {
return `${process.env.APPDATA}${path.sep}uv${path.sep}cache`;
}
return `${process.env.HOME}${path.sep}.cache${path.sep}uv`;
}
2024-11-23 09:21:51 +01:00
function getCacheDependencyGlob(): string {
const cacheDependencyGlobInput = core.getInput("cache-dependency-glob");
if (cacheDependencyGlobInput !== "") {
return cacheDependencyGlobInput
.split("\n")
.map((part) => part.trim())
.map((part) => expandTilde(part))
.map((part) => resolveRelativePath(part))
.join("\n");
}
return cacheDependencyGlobInput;
}
2024-11-23 09:21:51 +01:00
function expandTilde(input: string): string {
if (input.startsWith("~")) {
return `${process.env.HOME}${input.substring(1)}`;
}
return input;
}
2025-06-18 22:33:20 +02:00
function resolveRelativePath(inputPath: string): string {
if (path.isAbsolute(inputPath)) {
return inputPath;
}
let absolutePath = inputPath;
if (absolutePath.startsWith("./")) {
absolutePath = absolutePath.substring(2);
}
absolutePath = `${workingDirectory}${path.sep}${absolutePath}`;
core.debug(`Resolving relative path ${inputPath} to ${absolutePath}`);
return absolutePath;
}
2025-06-18 22:33:20 +02:00
function getManifestFile(): string | undefined {
const manifestFileInput = core.getInput("manifest-file");
if (manifestFileInput !== "") {
return manifestFileInput;
}
return undefined;
}