mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-05-18 23:20:14 +02:00
Use TOML 1.0.0 compliant library for parsing (#47)
iarna/toml is unmaintained. Replaced by smol-toml which is maintained and has the same api
This commit is contained in:
committed by
GitHub
parent
0c24450c01
commit
9071a7b1c3
+18
-5
@@ -1,15 +1,28 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import * as toml from "@iarna/toml";
|
||||
import * as toml from "smol-toml";
|
||||
|
||||
export function getRuffVersionFromPyproject(
|
||||
filePath: string,
|
||||
): string | undefined {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
core.warning(`Could not find file: ${filePath}`);
|
||||
return undefined;
|
||||
}
|
||||
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
||||
const pyproject = toml.parse(pyprojectContent) as {
|
||||
project?: { dependencies?: string[] };
|
||||
"dependency-groups"?: { dev?: string[] };
|
||||
};
|
||||
let pyproject:
|
||||
| {
|
||||
project?: { dependencies?: string[] };
|
||||
"dependency-groups"?: { dev?: string[] };
|
||||
}
|
||||
| undefined;
|
||||
try {
|
||||
pyproject = toml.parse(pyprojectContent);
|
||||
} catch (err) {
|
||||
const message = (err as Error).message;
|
||||
core.warning(`Error while parsing ${filePath}: ${message}`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const dependencies: string[] = pyproject?.project?.dependencies || [];
|
||||
const devDependencies: string[] = pyproject?.["dependency-groups"]?.dev || [];
|
||||
|
||||
Reference in New Issue
Block a user