mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-09-20 19:06:45 +00:00
Detect required-version from config file (#233)
1. If defined use version input 2. If defined use uv-file input 3. If defined use pyproject-file input 4. Search for required-version in uv.toml in repo root 5. Search for required-version in pyproject.toml in repo root 6. Use latest Closes: #215
This commit is contained in:
committed by
GitHub
parent
d577e74f98
commit
5ce9ee0011
@ -2,6 +2,8 @@ import * as core from "@actions/core";
|
||||
import path from "node:path";
|
||||
|
||||
export const version = core.getInput("version");
|
||||
export const pyProjectFile = core.getInput("pyproject-file");
|
||||
export const uvFile = core.getInput("uv-file");
|
||||
export const pythonVersion = core.getInput("python-version");
|
||||
export const checkSum = core.getInput("checksum");
|
||||
export const enableCache = getEnableCache();
|
||||
|
38
src/utils/pyproject.ts
Normal file
38
src/utils/pyproject.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import * as toml from "@iarna/toml";
|
||||
|
||||
export function getUvVersionFromConfigFile(
|
||||
filePath: string,
|
||||
): string | undefined {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
core.warning(`Could not find file: ${filePath}`);
|
||||
return undefined;
|
||||
}
|
||||
let requiredVersion = getRequiredVersion(filePath);
|
||||
|
||||
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"];
|
||||
}
|
Reference in New Issue
Block a user