mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-03-29 01:49:53 +00:00
Simplify inputs.ts (#827)
Do not pass around inputs. Its okay to freely work with core.getInput in this file
This commit is contained in:
committed by
GitHub
parent
7fdbe7cf0c
commit
4dd8ab4520
@@ -36,7 +36,7 @@ jest.unstable_mockModule("@actions/core", () => ({
|
|||||||
|
|
||||||
const { CacheLocalSource, loadInputs } = await import("../../src/utils/inputs");
|
const { CacheLocalSource, loadInputs } = await import("../../src/utils/inputs");
|
||||||
|
|
||||||
function createTempProject(files: Record<string, string>): string {
|
function createTempProject(files: Record<string, string> = {}): string {
|
||||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "setup-uv-inputs-test-"));
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "setup-uv-inputs-test-"));
|
||||||
tempDirs.push(dir);
|
tempDirs.push(dir);
|
||||||
|
|
||||||
@@ -60,11 +60,8 @@ function resetEnvironment(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restoreEnvironment(): void {
|
function restoreEnvironment(): void {
|
||||||
while (tempDirs.length > 0) {
|
for (const dir of tempDirs.splice(0)) {
|
||||||
const dir = tempDirs.pop();
|
fs.rmSync(dir, { force: true, recursive: true });
|
||||||
if (dir !== undefined) {
|
|
||||||
fs.rmSync(dir, { force: true, recursive: true });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env.HOME = ORIGINAL_HOME;
|
process.env.HOME = ORIGINAL_HOME;
|
||||||
@@ -74,13 +71,8 @@ function restoreEnvironment(): void {
|
|||||||
process.env.UV_PYTHON_INSTALL_DIR = ORIGINAL_UV_PYTHON_INSTALL_DIR;
|
process.env.UV_PYTHON_INSTALL_DIR = ORIGINAL_UV_PYTHON_INSTALL_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(resetEnvironment);
|
||||||
resetEnvironment();
|
afterEach(restoreEnvironment);
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
restoreEnvironment();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("loadInputs", () => {
|
describe("loadInputs", () => {
|
||||||
it("loads defaults for a github-hosted runner", () => {
|
it("loads defaults for a github-hosted runner", () => {
|
||||||
@@ -125,7 +117,7 @@ cache-dir = "/tmp/pyproject-toml-defined-cache-path"
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses UV_CACHE_DIR from the environment", () => {
|
it("uses UV_CACHE_DIR from the environment", () => {
|
||||||
mockInputs["working-directory"] = createTempProject({});
|
mockInputs["working-directory"] = createTempProject();
|
||||||
process.env.UV_CACHE_DIR = "/env/cache-dir";
|
process.env.UV_CACHE_DIR = "/env/cache-dir";
|
||||||
|
|
||||||
const inputs = loadInputs();
|
const inputs = loadInputs();
|
||||||
|
|||||||
55
dist/save-cache/index.cjs
generated
vendored
55
dist/save-cache/index.cjs
generated
vendored
@@ -62959,19 +62959,12 @@ function getConfigValueFromTomlFile(filePath, key) {
|
|||||||
function loadInputs() {
|
function loadInputs() {
|
||||||
const workingDirectory = getInput("working-directory");
|
const workingDirectory = getInput("working-directory");
|
||||||
const version3 = getInput("version");
|
const version3 = getInput("version");
|
||||||
const versionFile = getVersionFile(
|
const versionFile = getVersionFile(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
getInput("version-file")
|
|
||||||
);
|
|
||||||
const pythonVersion = getInput("python-version");
|
const pythonVersion = getInput("python-version");
|
||||||
const activateEnvironment = getBooleanInput("activate-environment");
|
const activateEnvironment = getBooleanInput("activate-environment");
|
||||||
const venvPath = getVenvPath(
|
const venvPath = getVenvPath(workingDirectory, activateEnvironment);
|
||||||
workingDirectory,
|
|
||||||
getInput("venv-path"),
|
|
||||||
activateEnvironment
|
|
||||||
);
|
|
||||||
const checksum = getInput("checksum");
|
const checksum = getInput("checksum");
|
||||||
const enableCache = getEnableCache(getInput("enable-cache"));
|
const enableCache = getEnableCache();
|
||||||
const restoreCache2 = getInput("restore-cache") === "true";
|
const restoreCache2 = getInput("restore-cache") === "true";
|
||||||
const saveCache4 = getInput("save-cache") === "true";
|
const saveCache4 = getInput("save-cache") === "true";
|
||||||
const cacheSuffix = getInput("cache-suffix") || "";
|
const cacheSuffix = getInput("cache-suffix") || "";
|
||||||
@@ -62980,26 +62973,18 @@ function loadInputs() {
|
|||||||
versionFile,
|
versionFile,
|
||||||
enableCache
|
enableCache
|
||||||
);
|
);
|
||||||
const cacheDependencyGlob = getCacheDependencyGlob(
|
const cacheDependencyGlob = getCacheDependencyGlob(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
getInput("cache-dependency-glob")
|
|
||||||
);
|
|
||||||
const pruneCache2 = getInput("prune-cache") === "true";
|
const pruneCache2 = getInput("prune-cache") === "true";
|
||||||
const cachePython = getInput("cache-python") === "true";
|
const cachePython = getInput("cache-python") === "true";
|
||||||
const ignoreNothingToCache = getInput("ignore-nothing-to-cache") === "true";
|
const ignoreNothingToCache = getInput("ignore-nothing-to-cache") === "true";
|
||||||
const ignoreEmptyWorkdir = getInput("ignore-empty-workdir") === "true";
|
const ignoreEmptyWorkdir = getInput("ignore-empty-workdir") === "true";
|
||||||
const toolBinDir = getToolBinDir(
|
const toolBinDir = getToolBinDir(workingDirectory);
|
||||||
workingDirectory,
|
const toolDir = getToolDir(workingDirectory);
|
||||||
getInput("tool-bin-dir")
|
|
||||||
);
|
|
||||||
const toolDir = getToolDir(workingDirectory, getInput("tool-dir"));
|
|
||||||
const pythonDir = getUvPythonDir();
|
const pythonDir = getUvPythonDir();
|
||||||
const githubToken = getInput("github-token");
|
const githubToken = getInput("github-token");
|
||||||
const manifestFile = getManifestFile(getInput("manifest-file"));
|
const manifestFile = getManifestFile();
|
||||||
const addProblemMatchers = getInput("add-problem-matchers") === "true";
|
const addProblemMatchers = getInput("add-problem-matchers") === "true";
|
||||||
const resolutionStrategy = getResolutionStrategy(
|
const resolutionStrategy = getResolutionStrategy();
|
||||||
getInput("resolution-strategy")
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
activateEnvironment,
|
activateEnvironment,
|
||||||
addProblemMatchers,
|
addProblemMatchers,
|
||||||
@@ -63027,14 +63012,16 @@ function loadInputs() {
|
|||||||
workingDirectory
|
workingDirectory
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getVersionFile(workingDirectory, versionFileInput) {
|
function getVersionFile(workingDirectory) {
|
||||||
|
const versionFileInput = getInput("version-file");
|
||||||
if (versionFileInput !== "") {
|
if (versionFileInput !== "") {
|
||||||
const tildeExpanded = expandTilde(versionFileInput);
|
const tildeExpanded = expandTilde(versionFileInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
}
|
}
|
||||||
return versionFileInput;
|
return versionFileInput;
|
||||||
}
|
}
|
||||||
function getVenvPath(workingDirectory, venvPathInput, activateEnvironment) {
|
function getVenvPath(workingDirectory, activateEnvironment) {
|
||||||
|
const venvPathInput = getInput("venv-path");
|
||||||
if (venvPathInput !== "") {
|
if (venvPathInput !== "") {
|
||||||
if (!activateEnvironment) {
|
if (!activateEnvironment) {
|
||||||
warning("venv-path is only used when activate-environment is true");
|
warning("venv-path is only used when activate-environment is true");
|
||||||
@@ -63044,13 +63031,15 @@ function getVenvPath(workingDirectory, venvPathInput, activateEnvironment) {
|
|||||||
}
|
}
|
||||||
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
||||||
}
|
}
|
||||||
function getEnableCache(enableCacheInput) {
|
function getEnableCache() {
|
||||||
|
const enableCacheInput = getInput("enable-cache");
|
||||||
if (enableCacheInput === "auto") {
|
if (enableCacheInput === "auto") {
|
||||||
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
||||||
}
|
}
|
||||||
return enableCacheInput === "true";
|
return enableCacheInput === "true";
|
||||||
}
|
}
|
||||||
function getToolBinDir(workingDirectory, toolBinDirInput) {
|
function getToolBinDir(workingDirectory) {
|
||||||
|
const toolBinDirInput = getInput("tool-bin-dir");
|
||||||
if (toolBinDirInput !== "") {
|
if (toolBinDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolBinDirInput);
|
const tildeExpanded = expandTilde(toolBinDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -63065,7 +63054,8 @@ function getToolBinDir(workingDirectory, toolBinDirInput) {
|
|||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
function getToolDir(workingDirectory, toolDirInput) {
|
function getToolDir(workingDirectory) {
|
||||||
|
const toolDirInput = getInput("tool-dir");
|
||||||
if (toolDirInput !== "") {
|
if (toolDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolDirInput);
|
const tildeExpanded = expandTilde(toolDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -63161,7 +63151,8 @@ function getUvPythonDir() {
|
|||||||
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable"
|
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function getCacheDependencyGlob(workingDirectory, cacheDependencyGlobInput) {
|
function getCacheDependencyGlob(workingDirectory) {
|
||||||
|
const cacheDependencyGlobInput = getInput("cache-dependency-glob");
|
||||||
if (cacheDependencyGlobInput !== "") {
|
if (cacheDependencyGlobInput !== "") {
|
||||||
return cacheDependencyGlobInput.split("\n").map((part) => part.trim()).map((part) => expandTilde(part)).map((part) => resolveRelativePath(workingDirectory, part)).join("\n");
|
return cacheDependencyGlobInput.split("\n").map((part) => part.trim()).map((part) => expandTilde(part)).map((part) => resolveRelativePath(workingDirectory, part)).join("\n");
|
||||||
}
|
}
|
||||||
@@ -63191,13 +63182,15 @@ function resolveRelativePath(workingDirectory, inputPath) {
|
|||||||
);
|
);
|
||||||
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
||||||
}
|
}
|
||||||
function getManifestFile(manifestFileInput) {
|
function getManifestFile() {
|
||||||
|
const manifestFileInput = getInput("manifest-file");
|
||||||
if (manifestFileInput !== "") {
|
if (manifestFileInput !== "") {
|
||||||
return manifestFileInput;
|
return manifestFileInput;
|
||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
function getResolutionStrategy(resolutionStrategyInput) {
|
function getResolutionStrategy() {
|
||||||
|
const resolutionStrategyInput = getInput("resolution-strategy");
|
||||||
if (resolutionStrategyInput === "lowest") {
|
if (resolutionStrategyInput === "lowest") {
|
||||||
return "lowest";
|
return "lowest";
|
||||||
}
|
}
|
||||||
|
|||||||
55
dist/setup/index.cjs
generated
vendored
55
dist/setup/index.cjs
generated
vendored
@@ -96557,19 +96557,12 @@ function getConfigValueFromTomlFile(filePath, key) {
|
|||||||
function loadInputs() {
|
function loadInputs() {
|
||||||
const workingDirectory = getInput("working-directory");
|
const workingDirectory = getInput("working-directory");
|
||||||
const version3 = getInput("version");
|
const version3 = getInput("version");
|
||||||
const versionFile = getVersionFile(
|
const versionFile = getVersionFile(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
getInput("version-file")
|
|
||||||
);
|
|
||||||
const pythonVersion = getInput("python-version");
|
const pythonVersion = getInput("python-version");
|
||||||
const activateEnvironment2 = getBooleanInput("activate-environment");
|
const activateEnvironment2 = getBooleanInput("activate-environment");
|
||||||
const venvPath = getVenvPath(
|
const venvPath = getVenvPath(workingDirectory, activateEnvironment2);
|
||||||
workingDirectory,
|
|
||||||
getInput("venv-path"),
|
|
||||||
activateEnvironment2
|
|
||||||
);
|
|
||||||
const checksum = getInput("checksum");
|
const checksum = getInput("checksum");
|
||||||
const enableCache = getEnableCache(getInput("enable-cache"));
|
const enableCache = getEnableCache();
|
||||||
const restoreCache3 = getInput("restore-cache") === "true";
|
const restoreCache3 = getInput("restore-cache") === "true";
|
||||||
const saveCache2 = getInput("save-cache") === "true";
|
const saveCache2 = getInput("save-cache") === "true";
|
||||||
const cacheSuffix = getInput("cache-suffix") || "";
|
const cacheSuffix = getInput("cache-suffix") || "";
|
||||||
@@ -96578,26 +96571,18 @@ function loadInputs() {
|
|||||||
versionFile,
|
versionFile,
|
||||||
enableCache
|
enableCache
|
||||||
);
|
);
|
||||||
const cacheDependencyGlob = getCacheDependencyGlob(
|
const cacheDependencyGlob = getCacheDependencyGlob(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
getInput("cache-dependency-glob")
|
|
||||||
);
|
|
||||||
const pruneCache = getInput("prune-cache") === "true";
|
const pruneCache = getInput("prune-cache") === "true";
|
||||||
const cachePython = getInput("cache-python") === "true";
|
const cachePython = getInput("cache-python") === "true";
|
||||||
const ignoreNothingToCache = getInput("ignore-nothing-to-cache") === "true";
|
const ignoreNothingToCache = getInput("ignore-nothing-to-cache") === "true";
|
||||||
const ignoreEmptyWorkdir = getInput("ignore-empty-workdir") === "true";
|
const ignoreEmptyWorkdir = getInput("ignore-empty-workdir") === "true";
|
||||||
const toolBinDir = getToolBinDir(
|
const toolBinDir = getToolBinDir(workingDirectory);
|
||||||
workingDirectory,
|
const toolDir = getToolDir(workingDirectory);
|
||||||
getInput("tool-bin-dir")
|
|
||||||
);
|
|
||||||
const toolDir = getToolDir(workingDirectory, getInput("tool-dir"));
|
|
||||||
const pythonDir = getUvPythonDir();
|
const pythonDir = getUvPythonDir();
|
||||||
const githubToken = getInput("github-token");
|
const githubToken = getInput("github-token");
|
||||||
const manifestFile = getManifestFile(getInput("manifest-file"));
|
const manifestFile = getManifestFile();
|
||||||
const addProblemMatchers = getInput("add-problem-matchers") === "true";
|
const addProblemMatchers = getInput("add-problem-matchers") === "true";
|
||||||
const resolutionStrategy = getResolutionStrategy(
|
const resolutionStrategy = getResolutionStrategy();
|
||||||
getInput("resolution-strategy")
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
activateEnvironment: activateEnvironment2,
|
activateEnvironment: activateEnvironment2,
|
||||||
addProblemMatchers,
|
addProblemMatchers,
|
||||||
@@ -96625,14 +96610,16 @@ function loadInputs() {
|
|||||||
workingDirectory
|
workingDirectory
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getVersionFile(workingDirectory, versionFileInput) {
|
function getVersionFile(workingDirectory) {
|
||||||
|
const versionFileInput = getInput("version-file");
|
||||||
if (versionFileInput !== "") {
|
if (versionFileInput !== "") {
|
||||||
const tildeExpanded = expandTilde(versionFileInput);
|
const tildeExpanded = expandTilde(versionFileInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
}
|
}
|
||||||
return versionFileInput;
|
return versionFileInput;
|
||||||
}
|
}
|
||||||
function getVenvPath(workingDirectory, venvPathInput, activateEnvironment2) {
|
function getVenvPath(workingDirectory, activateEnvironment2) {
|
||||||
|
const venvPathInput = getInput("venv-path");
|
||||||
if (venvPathInput !== "") {
|
if (venvPathInput !== "") {
|
||||||
if (!activateEnvironment2) {
|
if (!activateEnvironment2) {
|
||||||
warning("venv-path is only used when activate-environment is true");
|
warning("venv-path is only used when activate-environment is true");
|
||||||
@@ -96642,13 +96629,15 @@ function getVenvPath(workingDirectory, venvPathInput, activateEnvironment2) {
|
|||||||
}
|
}
|
||||||
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
||||||
}
|
}
|
||||||
function getEnableCache(enableCacheInput) {
|
function getEnableCache() {
|
||||||
|
const enableCacheInput = getInput("enable-cache");
|
||||||
if (enableCacheInput === "auto") {
|
if (enableCacheInput === "auto") {
|
||||||
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
||||||
}
|
}
|
||||||
return enableCacheInput === "true";
|
return enableCacheInput === "true";
|
||||||
}
|
}
|
||||||
function getToolBinDir(workingDirectory, toolBinDirInput) {
|
function getToolBinDir(workingDirectory) {
|
||||||
|
const toolBinDirInput = getInput("tool-bin-dir");
|
||||||
if (toolBinDirInput !== "") {
|
if (toolBinDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolBinDirInput);
|
const tildeExpanded = expandTilde(toolBinDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -96663,7 +96652,8 @@ function getToolBinDir(workingDirectory, toolBinDirInput) {
|
|||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
function getToolDir(workingDirectory, toolDirInput) {
|
function getToolDir(workingDirectory) {
|
||||||
|
const toolDirInput = getInput("tool-dir");
|
||||||
if (toolDirInput !== "") {
|
if (toolDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolDirInput);
|
const tildeExpanded = expandTilde(toolDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -96759,7 +96749,8 @@ function getUvPythonDir() {
|
|||||||
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable"
|
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function getCacheDependencyGlob(workingDirectory, cacheDependencyGlobInput) {
|
function getCacheDependencyGlob(workingDirectory) {
|
||||||
|
const cacheDependencyGlobInput = getInput("cache-dependency-glob");
|
||||||
if (cacheDependencyGlobInput !== "") {
|
if (cacheDependencyGlobInput !== "") {
|
||||||
return cacheDependencyGlobInput.split("\n").map((part) => part.trim()).map((part) => expandTilde(part)).map((part) => resolveRelativePath(workingDirectory, part)).join("\n");
|
return cacheDependencyGlobInput.split("\n").map((part) => part.trim()).map((part) => expandTilde(part)).map((part) => resolveRelativePath(workingDirectory, part)).join("\n");
|
||||||
}
|
}
|
||||||
@@ -96789,13 +96780,15 @@ function resolveRelativePath(workingDirectory, inputPath) {
|
|||||||
);
|
);
|
||||||
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
||||||
}
|
}
|
||||||
function getManifestFile(manifestFileInput) {
|
function getManifestFile() {
|
||||||
|
const manifestFileInput = getInput("manifest-file");
|
||||||
if (manifestFileInput !== "") {
|
if (manifestFileInput !== "") {
|
||||||
return manifestFileInput;
|
return manifestFileInput;
|
||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
function getResolutionStrategy(resolutionStrategyInput) {
|
function getResolutionStrategy() {
|
||||||
|
const resolutionStrategyInput = getInput("resolution-strategy");
|
||||||
if (resolutionStrategyInput === "lowest") {
|
if (resolutionStrategyInput === "lowest") {
|
||||||
return "lowest";
|
return "lowest";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export interface CacheLocalPath {
|
|||||||
source: CacheLocalSource;
|
source: CacheLocalSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ResolutionStrategy = "highest" | "lowest";
|
||||||
|
|
||||||
export interface SetupInputs {
|
export interface SetupInputs {
|
||||||
workingDirectory: string;
|
workingDirectory: string;
|
||||||
version: string;
|
version: string;
|
||||||
@@ -38,25 +40,18 @@ export interface SetupInputs {
|
|||||||
githubToken: string;
|
githubToken: string;
|
||||||
manifestFile?: string;
|
manifestFile?: string;
|
||||||
addProblemMatchers: boolean;
|
addProblemMatchers: boolean;
|
||||||
resolutionStrategy: "highest" | "lowest";
|
resolutionStrategy: ResolutionStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadInputs(): SetupInputs {
|
export function loadInputs(): SetupInputs {
|
||||||
const workingDirectory = core.getInput("working-directory");
|
const workingDirectory = core.getInput("working-directory");
|
||||||
const version = core.getInput("version");
|
const version = core.getInput("version");
|
||||||
const versionFile = getVersionFile(
|
const versionFile = getVersionFile(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
core.getInput("version-file"),
|
|
||||||
);
|
|
||||||
const pythonVersion = core.getInput("python-version");
|
const pythonVersion = core.getInput("python-version");
|
||||||
const activateEnvironment = core.getBooleanInput("activate-environment");
|
const activateEnvironment = core.getBooleanInput("activate-environment");
|
||||||
const venvPath = getVenvPath(
|
const venvPath = getVenvPath(workingDirectory, activateEnvironment);
|
||||||
workingDirectory,
|
|
||||||
core.getInput("venv-path"),
|
|
||||||
activateEnvironment,
|
|
||||||
);
|
|
||||||
const checksum = core.getInput("checksum");
|
const checksum = core.getInput("checksum");
|
||||||
const enableCache = getEnableCache(core.getInput("enable-cache"));
|
const enableCache = getEnableCache();
|
||||||
const restoreCache = core.getInput("restore-cache") === "true";
|
const restoreCache = core.getInput("restore-cache") === "true";
|
||||||
const saveCache = core.getInput("save-cache") === "true";
|
const saveCache = core.getInput("save-cache") === "true";
|
||||||
const cacheSuffix = core.getInput("cache-suffix") || "";
|
const cacheSuffix = core.getInput("cache-suffix") || "";
|
||||||
@@ -65,27 +60,19 @@ export function loadInputs(): SetupInputs {
|
|||||||
versionFile,
|
versionFile,
|
||||||
enableCache,
|
enableCache,
|
||||||
);
|
);
|
||||||
const cacheDependencyGlob = getCacheDependencyGlob(
|
const cacheDependencyGlob = getCacheDependencyGlob(workingDirectory);
|
||||||
workingDirectory,
|
|
||||||
core.getInput("cache-dependency-glob"),
|
|
||||||
);
|
|
||||||
const pruneCache = core.getInput("prune-cache") === "true";
|
const pruneCache = core.getInput("prune-cache") === "true";
|
||||||
const cachePython = core.getInput("cache-python") === "true";
|
const cachePython = core.getInput("cache-python") === "true";
|
||||||
const ignoreNothingToCache =
|
const ignoreNothingToCache =
|
||||||
core.getInput("ignore-nothing-to-cache") === "true";
|
core.getInput("ignore-nothing-to-cache") === "true";
|
||||||
const ignoreEmptyWorkdir = core.getInput("ignore-empty-workdir") === "true";
|
const ignoreEmptyWorkdir = core.getInput("ignore-empty-workdir") === "true";
|
||||||
const toolBinDir = getToolBinDir(
|
const toolBinDir = getToolBinDir(workingDirectory);
|
||||||
workingDirectory,
|
const toolDir = getToolDir(workingDirectory);
|
||||||
core.getInput("tool-bin-dir"),
|
|
||||||
);
|
|
||||||
const toolDir = getToolDir(workingDirectory, core.getInput("tool-dir"));
|
|
||||||
const pythonDir = getUvPythonDir();
|
const pythonDir = getUvPythonDir();
|
||||||
const githubToken = core.getInput("github-token");
|
const githubToken = core.getInput("github-token");
|
||||||
const manifestFile = getManifestFile(core.getInput("manifest-file"));
|
const manifestFile = getManifestFile();
|
||||||
const addProblemMatchers = core.getInput("add-problem-matchers") === "true";
|
const addProblemMatchers = core.getInput("add-problem-matchers") === "true";
|
||||||
const resolutionStrategy = getResolutionStrategy(
|
const resolutionStrategy = getResolutionStrategy();
|
||||||
core.getInput("resolution-strategy"),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activateEnvironment,
|
activateEnvironment,
|
||||||
@@ -115,10 +102,8 @@ export function loadInputs(): SetupInputs {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionFile(
|
function getVersionFile(workingDirectory: string): string {
|
||||||
workingDirectory: string,
|
const versionFileInput = core.getInput("version-file");
|
||||||
versionFileInput: string,
|
|
||||||
): string {
|
|
||||||
if (versionFileInput !== "") {
|
if (versionFileInput !== "") {
|
||||||
const tildeExpanded = expandTilde(versionFileInput);
|
const tildeExpanded = expandTilde(versionFileInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -128,9 +113,9 @@ function getVersionFile(
|
|||||||
|
|
||||||
function getVenvPath(
|
function getVenvPath(
|
||||||
workingDirectory: string,
|
workingDirectory: string,
|
||||||
venvPathInput: string,
|
|
||||||
activateEnvironment: boolean,
|
activateEnvironment: boolean,
|
||||||
): string {
|
): string {
|
||||||
|
const venvPathInput = core.getInput("venv-path");
|
||||||
if (venvPathInput !== "") {
|
if (venvPathInput !== "") {
|
||||||
if (!activateEnvironment) {
|
if (!activateEnvironment) {
|
||||||
core.warning("venv-path is only used when activate-environment is true");
|
core.warning("venv-path is only used when activate-environment is true");
|
||||||
@@ -141,17 +126,16 @@ function getVenvPath(
|
|||||||
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
return normalizePath(resolveRelativePath(workingDirectory, ".venv"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnableCache(enableCacheInput: string): boolean {
|
function getEnableCache(): boolean {
|
||||||
|
const enableCacheInput = core.getInput("enable-cache");
|
||||||
if (enableCacheInput === "auto") {
|
if (enableCacheInput === "auto") {
|
||||||
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
|
||||||
}
|
}
|
||||||
return enableCacheInput === "true";
|
return enableCacheInput === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolBinDir(
|
function getToolBinDir(workingDirectory: string): string | undefined {
|
||||||
workingDirectory: string,
|
const toolBinDirInput = core.getInput("tool-bin-dir");
|
||||||
toolBinDirInput: string,
|
|
||||||
): string | undefined {
|
|
||||||
if (toolBinDirInput !== "") {
|
if (toolBinDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolBinDirInput);
|
const tildeExpanded = expandTilde(toolBinDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -167,10 +151,8 @@ function getToolBinDir(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolDir(
|
function getToolDir(workingDirectory: string): string | undefined {
|
||||||
workingDirectory: string,
|
const toolDirInput = core.getInput("tool-dir");
|
||||||
toolDirInput: string,
|
|
||||||
): string | undefined {
|
|
||||||
if (toolDirInput !== "") {
|
if (toolDirInput !== "") {
|
||||||
const tildeExpanded = expandTilde(toolDirInput);
|
const tildeExpanded = expandTilde(toolDirInput);
|
||||||
return resolveRelativePath(workingDirectory, tildeExpanded);
|
return resolveRelativePath(workingDirectory, tildeExpanded);
|
||||||
@@ -277,10 +259,8 @@ export function getUvPythonDir(): string {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCacheDependencyGlob(
|
function getCacheDependencyGlob(workingDirectory: string): string {
|
||||||
workingDirectory: string,
|
const cacheDependencyGlobInput = core.getInput("cache-dependency-glob");
|
||||||
cacheDependencyGlobInput: string,
|
|
||||||
): string {
|
|
||||||
if (cacheDependencyGlobInput !== "") {
|
if (cacheDependencyGlobInput !== "") {
|
||||||
return cacheDependencyGlobInput
|
return cacheDependencyGlobInput
|
||||||
.split("\n")
|
.split("\n")
|
||||||
@@ -327,16 +307,16 @@ function resolveRelativePath(
|
|||||||
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
return hasNegation ? `!${resolvedPath}` : resolvedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getManifestFile(manifestFileInput: string): string | undefined {
|
function getManifestFile(): string | undefined {
|
||||||
|
const manifestFileInput = core.getInput("manifest-file");
|
||||||
if (manifestFileInput !== "") {
|
if (manifestFileInput !== "") {
|
||||||
return manifestFileInput;
|
return manifestFileInput;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResolutionStrategy(
|
function getResolutionStrategy(): ResolutionStrategy {
|
||||||
resolutionStrategyInput: string,
|
const resolutionStrategyInput = core.getInput("resolution-strategy");
|
||||||
): "highest" | "lowest" {
|
|
||||||
if (resolutionStrategyInput === "lowest") {
|
if (resolutionStrategyInput === "lowest") {
|
||||||
return "lowest";
|
return "lowest";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user