Add input version-file (#486)

Closes: #411
This commit is contained in:
Kevin Stillhammer
2025-07-17 20:22:18 +02:00
committed by GitHub
parent c893ac1cb2
commit b75ff7d7b8
13 changed files with 369 additions and 136 deletions

View File

@ -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"];
}

View File

@ -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");