mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-09-05 19:46:55 +00:00
committed by
GitHub
parent
fce199e243
commit
adeb28643f
@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import { getRequiredVersionFromConfigFile } from "./config-file";
|
||||
import { getUvVersionFromRequirementsFile } from "./requirements-file";
|
||||
import { getUvVersionFromToolVersions } from "./tool-versions-file";
|
||||
|
||||
export function getUvVersionFromFile(filePath: string): string | undefined {
|
||||
core.info(`Trying to find version for uv in: ${filePath}`);
|
||||
@ -11,7 +12,10 @@ export function getUvVersionFromFile(filePath: string): string | undefined {
|
||||
}
|
||||
let uvVersion: string | undefined;
|
||||
try {
|
||||
uvVersion = getRequiredVersionFromConfigFile(filePath);
|
||||
uvVersion = getUvVersionFromToolVersions(filePath);
|
||||
if (uvVersion === undefined) {
|
||||
uvVersion = getRequiredVersionFromConfigFile(filePath);
|
||||
}
|
||||
if (uvVersion === undefined) {
|
||||
uvVersion = getUvVersionFromRequirementsFile(filePath);
|
||||
}
|
||||
|
31
src/version/tool-versions-file.ts
Normal file
31
src/version/tool-versions-file.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
export function getUvVersionFromToolVersions(
|
||||
filePath: string,
|
||||
): string | undefined {
|
||||
if (!filePath.endsWith(".tool-versions")) {
|
||||
return undefined;
|
||||
}
|
||||
const fileContents = fs.readFileSync(filePath, "utf8");
|
||||
const lines = fileContents.split("\n");
|
||||
|
||||
for (const line of lines) {
|
||||
// Skip commented lines
|
||||
if (line.trim().startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
const match = line.match(/^\s*uv\s*v?\s*(?<version>[^\s]+)\s*$/);
|
||||
if (match) {
|
||||
const matchedVersion = match.groups?.version.trim();
|
||||
if (matchedVersion?.startsWith("ref")) {
|
||||
core.warning(
|
||||
"The ref syntax of .tool-versions is not supported. Please use a released version instead.",
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
return matchedVersion;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
Reference in New Issue
Block a user