mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-05-17 23:00:13 +02:00
Default to ruff-version from pyproject.toml (#30)
Closes: #9 Changes the default behavior to: - Search for a pyproject.toml in the repo root - Search in project.dependencies and dependency-groups.dev for ruff - If none is found use latest Support for requirements.txt files can be added later
This commit is contained in:
committed by
GitHub
parent
cac2f108b2
commit
7a82f1f7e4
@@ -5,3 +5,4 @@ export const checkSum = core.getInput("checksum");
|
||||
export const githubToken = core.getInput("github-token");
|
||||
export const args = core.getInput("args");
|
||||
export const src = core.getInput("src");
|
||||
export const versionFile = core.getInput("version-file");
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import * as toml from "toml";
|
||||
|
||||
export function getRuffVersionFromPyproject(
|
||||
filePath: string,
|
||||
): string | undefined {
|
||||
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
||||
const pyproject = toml.parse(pyprojectContent);
|
||||
|
||||
const dependencies: string[] = pyproject.project?.dependencies || [];
|
||||
const devDependencies: string[] = pyproject["dependency-groups"]?.dev || [];
|
||||
|
||||
const ruffVersionDefinition =
|
||||
dependencies.find((dep: string) => dep.startsWith("ruff")) ||
|
||||
devDependencies.find((dep: string) => dep.startsWith("ruff"));
|
||||
|
||||
if (ruffVersionDefinition) {
|
||||
const ruffVersion = ruffVersionDefinition
|
||||
.match(/^ruff([^A-Z0-9._-]+.*)$/)?.[1]
|
||||
.trim();
|
||||
if (ruffVersion?.startsWith("==")) {
|
||||
return ruffVersion.slice(2);
|
||||
}
|
||||
core.info(`Found ruff version in pyproject.toml: ${ruffVersion}`);
|
||||
return ruffVersion;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user