mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-05-19 15:30:14 +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
+36
-10
@@ -13,7 +13,16 @@ import {
|
||||
getPlatform,
|
||||
type Platform,
|
||||
} from "./utils/platforms";
|
||||
import { args, checkSum, githubToken, src, version } from "./utils/inputs";
|
||||
import {
|
||||
args,
|
||||
checkSum,
|
||||
githubToken,
|
||||
src,
|
||||
version,
|
||||
versionFile as versionFileInput,
|
||||
} from "./utils/inputs";
|
||||
import { getRuffVersionFromPyproject } from "./utils/pyproject";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
async function run(): Promise<void> {
|
||||
const platform = getPlatform();
|
||||
@@ -26,13 +35,7 @@ async function run(): Promise<void> {
|
||||
if (arch === undefined) {
|
||||
throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||
}
|
||||
const setupResult = await setupRuff(
|
||||
platform,
|
||||
arch,
|
||||
version,
|
||||
checkSum,
|
||||
githubToken,
|
||||
);
|
||||
const setupResult = await setupRuff(platform, arch, checkSum, githubToken);
|
||||
|
||||
addRuffToPath(setupResult.ruffDir);
|
||||
setOutputFormat();
|
||||
@@ -55,11 +58,10 @@ async function run(): Promise<void> {
|
||||
async function setupRuff(
|
||||
platform: Platform,
|
||||
arch: Architecture,
|
||||
versionInput: string,
|
||||
checkSum: string | undefined,
|
||||
githubToken: string,
|
||||
): Promise<{ ruffDir: string; version: string }> {
|
||||
const resolvedVersion = await resolveVersion(versionInput, githubToken);
|
||||
const resolvedVersion = await determineVersion();
|
||||
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
||||
if (toolCacheResult.installedPath) {
|
||||
core.info(`Found ruffDir in tool-cache for ${toolCacheResult.version}`);
|
||||
@@ -83,6 +85,30 @@ async function setupRuff(
|
||||
};
|
||||
}
|
||||
|
||||
async function determineVersion(): Promise<string> {
|
||||
if (versionFileInput !== "" && version !== "") {
|
||||
throw Error("It is not allowed to specify both version and version-file");
|
||||
}
|
||||
if (version !== "") {
|
||||
return await resolveVersion(version, githubToken);
|
||||
}
|
||||
if (versionFileInput !== "") {
|
||||
const versionFromPyproject = getRuffVersionFromPyproject(versionFileInput);
|
||||
if (versionFromPyproject === undefined) {
|
||||
core.warning(
|
||||
"Could not parse version from supplied pyproject.toml. Using latest version.",
|
||||
);
|
||||
return await resolveVersion("latest", githubToken);
|
||||
}
|
||||
}
|
||||
const pyProjectPath = path.join(src, "pyproject.toml");
|
||||
if (!fs.existsSync(pyProjectPath)) {
|
||||
return await resolveVersion("latest", githubToken);
|
||||
}
|
||||
const versionFromPyproject = getRuffVersionFromPyproject(pyProjectPath);
|
||||
return await resolveVersion(versionFromPyproject || "latest", githubToken);
|
||||
}
|
||||
|
||||
function addRuffToPath(cachedPath: string): void {
|
||||
core.addPath(cachedPath);
|
||||
core.info(`Added ${cachedPath} to the path`);
|
||||
|
||||
Reference in New Issue
Block a user