mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-09-21 11:27:06 +00:00
committed by
GitHub
parent
c893ac1cb2
commit
b75ff7d7b8
@ -1,46 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import * as toml from "smol-toml";
|
||||
|
||||
export function getUvVersionFromConfigFile(
|
||||
filePath: string,
|
||||
): string | undefined {
|
||||
core.info(`Trying to find required-version for uv in: ${filePath}`);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
core.info(`Could not find file: ${filePath}`);
|
||||
return undefined;
|
||||
}
|
||||
let requiredVersion: string | undefined;
|
||||
try {
|
||||
requiredVersion = getRequiredVersion(filePath);
|
||||
} catch (err) {
|
||||
const message = (err as Error).message;
|
||||
core.warning(`Error while parsing ${filePath}: ${message}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (requiredVersion?.startsWith("==")) {
|
||||
requiredVersion = requiredVersion.slice(2);
|
||||
}
|
||||
if (requiredVersion !== undefined) {
|
||||
core.info(
|
||||
`Found required-version for uv in ${filePath}: ${requiredVersion}`,
|
||||
);
|
||||
}
|
||||
return requiredVersion;
|
||||
}
|
||||
|
||||
function getRequiredVersion(filePath: string): string | undefined {
|
||||
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||
|
||||
if (filePath.endsWith("pyproject.toml")) {
|
||||
const tomlContent = toml.parse(fileContent) as {
|
||||
tool?: { uv?: { "required-version"?: string } };
|
||||
};
|
||||
return tomlContent?.tool?.uv?.["required-version"];
|
||||
}
|
||||
const tomlContent = toml.parse(fileContent) as {
|
||||
"required-version"?: string;
|
||||
};
|
||||
return tomlContent["required-version"];
|
||||
}
|
@ -3,6 +3,7 @@ import path from "node:path";
|
||||
import { getManifestFromRepo } from "@actions/tool-cache";
|
||||
|
||||
export const version = core.getInput("version");
|
||||
export const versionFile = core.getInput("version-file");
|
||||
export const pythonVersion = core.getInput("python-version");
|
||||
export const activateEnvironment = core.getBooleanInput("activate-environment");
|
||||
export const workingDirectory = core.getInput("working-directory");
|
||||
|
Reference in New Issue
Block a user