mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-11-25 21:41:57 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84f83ecf9e | ||
|
|
ea12b8ac41 | ||
|
|
b259b0b299 |
@@ -40,10 +40,11 @@ jobs:
|
|||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
version: latest
|
version: latest
|
||||||
test-specific-version:
|
test-specific-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruff-version: ["0.7.4", "0.7", "0.7.x", ">=0.7.0"]
|
ruff-version: ["0.1.7", "0.1.8", "0.4.7", "0.4.10", "0.7", "0.7.x", ">=0.7.0"]
|
||||||
|
os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-14, windows-latest ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Use version ${{ matrix.ruff-version }}
|
- name: Use version ${{ matrix.ruff-version }}
|
||||||
@@ -51,6 +52,22 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: ${{ matrix.ruff-version }}
|
version: ${{ matrix.ruff-version }}
|
||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
|
test-unsupported-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Try install old version
|
||||||
|
id: install
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: 0.0.246
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
- name: Check if the action failed
|
||||||
|
run: |
|
||||||
|
if [ ${{ steps.install.outcome }} == "success" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
test-version-from-version-file-pyproject:
|
test-version-from-version-file-pyproject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -272,6 +289,7 @@ jobs:
|
|||||||
- lint
|
- lint
|
||||||
- test-latest-version
|
- test-latest-version
|
||||||
- test-specific-version
|
- test-specific-version
|
||||||
|
- test-unsupported-version
|
||||||
- test-version-from-version-file-pyproject
|
- test-version-from-version-file-pyproject
|
||||||
- test-default-version-from-pyproject
|
- test-default-version-from-pyproject
|
||||||
- test-default-version-from-pyproject-dev-group
|
- test-default-version-from-pyproject-dev-group
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ the ruff version to install. If no pyproject.toml file is found, or no ruff vers
|
|||||||
`project.dependencies`, `project.optional-dependencies`, or `dependency-groups`,
|
`project.dependencies`, `project.optional-dependencies`, or `dependency-groups`,
|
||||||
the latest version is installed.
|
the latest version is installed.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This action does only support ruff versions v0.0.247 and above.
|
||||||
|
|
||||||
#### Install the latest version
|
#### Install the latest version
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -1,5 +1,39 @@
|
|||||||
// AUTOGENERATED_DO_NOT_EDIT
|
// AUTOGENERATED_DO_NOT_EDIT
|
||||||
export const KNOWN_CHECKSUMS: { [key: string]: string } = {
|
export const KNOWN_CHECKSUMS: { [key: string]: string } = {
|
||||||
|
"aarch64-apple-darwin-0.11.8":
|
||||||
|
"bc3fc6693437efab1add3f288d6d16fac6926e6888c1e758ec162d5b6fe9099d",
|
||||||
|
"aarch64-pc-windows-msvc-0.11.8":
|
||||||
|
"06c2152f269949390bdde0cc9f6d74eb3f4068853a3d772b9ac9baa675b63a06",
|
||||||
|
"aarch64-unknown-linux-gnu-0.11.8":
|
||||||
|
"a6010d9393e254c73c81a9942fd1d49c6d1061a84bf76e024627924adfdd9e99",
|
||||||
|
"aarch64-unknown-linux-musl-0.11.8":
|
||||||
|
"7a4882654cd8b7c79b0bacd0f9b2062ec08a111a7f2621c69718000a165c93b6",
|
||||||
|
"arm-unknown-linux-musleabihf-0.11.8":
|
||||||
|
"e9d8c2e59d97b841273369350c64113708b402372fa6fd933aef70f2d4db9bf6",
|
||||||
|
"armv7-unknown-linux-gnueabihf-0.11.8":
|
||||||
|
"1eda8253c82dfc9232508ffb52e1e7d320719c60781a95a0f0e2a4b9ac7d7829",
|
||||||
|
"armv7-unknown-linux-musleabihf-0.11.8":
|
||||||
|
"cf4e4ca7426279051c4bdfb846749b8a75fe01892b9b08247dc700ece64af277",
|
||||||
|
"i686-pc-windows-msvc-0.11.8":
|
||||||
|
"c9d35f023f94110fd77e0d84240b8c1daf26f923e115556d7ef1e1d3af663e83",
|
||||||
|
"i686-unknown-linux-gnu-0.11.8":
|
||||||
|
"3d98524a340aede7ab974fb6f62778254aff1e9a57e565a22a348fdc02753566",
|
||||||
|
"i686-unknown-linux-musl-0.11.8":
|
||||||
|
"01f5a7ac05eaa0d548792c309e75fa24d18b6685831743e984d56b0fc4514251",
|
||||||
|
"powerpc64-unknown-linux-gnu-0.11.8":
|
||||||
|
"2c45c30ed216f67148ad8e96656efa0f9a4a7591c7def32fdd9db5db86a643fa",
|
||||||
|
"powerpc64le-unknown-linux-gnu-0.11.8":
|
||||||
|
"85705683af19f1dfc3c90424dab2525422a1e03e487610a79b725f96e04a4953",
|
||||||
|
"s390x-unknown-linux-gnu-0.11.8":
|
||||||
|
"722aa00e479f58f906e7bf697336b9ed3ccf0df939b83e10f2b778a6b136bdc6",
|
||||||
|
"x86_64-apple-darwin-0.11.8":
|
||||||
|
"56eaecad5d4e41d2f799bbb705d83238436de4a547e5d04c0591ae3422ae61cc",
|
||||||
|
"x86_64-pc-windows-msvc-0.11.8":
|
||||||
|
"2279f17ad7474b9a1493ec2aab404e6f1109272d3221a5d38ee06ceb0e4c6100",
|
||||||
|
"x86_64-unknown-linux-gnu-0.11.8":
|
||||||
|
"8edc7a28bb958af4ebfb6a85002c8cd96d88f264dd8c080e065a6e984963ce3c",
|
||||||
|
"x86_64-unknown-linux-musl-0.11.8":
|
||||||
|
"d5b331c4dd88a99b3b16babcaa8dec8b22f4004b880243f35f73c276f56684ff",
|
||||||
"aarch64-apple-darwin-0.11.7":
|
"aarch64-apple-darwin-0.11.7":
|
||||||
"1c6cc5fb36fb001dfa7331892f9d808bc7ced1d45f0ec54b4caeaa571bc55495",
|
"1c6cc5fb36fb001dfa7331892f9d808bc7ced1d45f0ec54b4caeaa571bc55495",
|
||||||
"aarch64-pc-windows-msvc-0.11.7":
|
"aarch64-pc-windows-msvc-0.11.7":
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as core from "@actions/core";
|
|||||||
import * as tc from "@actions/tool-cache";
|
import * as tc from "@actions/tool-cache";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import { promises as fs } from "node:fs";
|
import { promises as fs } from "node:fs";
|
||||||
|
import * as semver from "semver";
|
||||||
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
|
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
|
||||||
import type { Architecture, Platform } from "../utils/platforms";
|
import type { Architecture, Platform } from "../utils/platforms";
|
||||||
import { validateChecksum } from "./checksum/checksum";
|
import { validateChecksum } from "./checksum/checksum";
|
||||||
@@ -38,16 +39,59 @@ export async function downloadVersion(
|
|||||||
if (platform === "pc-windows-msvc") {
|
if (platform === "pc-windows-msvc") {
|
||||||
extension = ".zip";
|
extension = ".zip";
|
||||||
}
|
}
|
||||||
const downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}${extension}`;
|
const downloadUrl = constructDownloadUrl(version, platform, arch);
|
||||||
core.info(`Downloading ruff from "${downloadUrl}" ...`);
|
core.debug(`Downloading ruff from "${downloadUrl}" ...`);
|
||||||
|
|
||||||
const downloadPath = await tc.downloadTool(
|
const downloadPath = await tc.downloadTool(
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
undefined,
|
undefined,
|
||||||
githubToken,
|
githubToken,
|
||||||
);
|
);
|
||||||
|
core.debug(`Downloaded ruff to "${downloadPath}"`);
|
||||||
await validateChecksum(checkSum, downloadPath, arch, platform, version);
|
await validateChecksum(checkSum, downloadPath, arch, platform, version);
|
||||||
|
|
||||||
|
const extractedDir = await extractDownloadedArtifact(
|
||||||
|
version,
|
||||||
|
downloadPath,
|
||||||
|
extension,
|
||||||
|
platform,
|
||||||
|
artifact,
|
||||||
|
);
|
||||||
|
|
||||||
|
const cachedToolDir = await tc.cacheDir(
|
||||||
|
extractedDir,
|
||||||
|
TOOL_CACHE_NAME,
|
||||||
|
version,
|
||||||
|
arch,
|
||||||
|
);
|
||||||
|
return { version: version, cachedToolDir };
|
||||||
|
}
|
||||||
|
|
||||||
|
function constructDownloadUrl(
|
||||||
|
version: string,
|
||||||
|
platform: Platform,
|
||||||
|
arch: Architecture,
|
||||||
|
): string {
|
||||||
|
const artifactVersionSuffix =
|
||||||
|
semver.lte(version, "v0.4.10") && semver.gte(version, "v0.1.8")
|
||||||
|
? `-${version}`
|
||||||
|
: "";
|
||||||
|
const artifact = `ruff${artifactVersionSuffix}-${arch}-${platform}`;
|
||||||
|
let extension = ".tar.gz";
|
||||||
|
if (platform === "pc-windows-msvc") {
|
||||||
|
extension = ".zip";
|
||||||
|
}
|
||||||
|
const versionPrefix = semver.lte(version, "v0.4.10") ? "v" : "";
|
||||||
|
return `https://github.com/${OWNER}/${REPO}/releases/download/${versionPrefix}${version}/${artifact}${extension}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function extractDownloadedArtifact(
|
||||||
|
version: string,
|
||||||
|
downloadPath: string,
|
||||||
|
extension: string,
|
||||||
|
platform: Platform,
|
||||||
|
artifact: string,
|
||||||
|
): Promise<string> {
|
||||||
let ruffDir: string;
|
let ruffDir: string;
|
||||||
if (platform === "pc-windows-msvc") {
|
if (platform === "pc-windows-msvc") {
|
||||||
const fullPathWithExtension = `${downloadPath}${extension}`;
|
const fullPathWithExtension = `${downloadPath}${extension}`;
|
||||||
@@ -55,16 +99,15 @@ export async function downloadVersion(
|
|||||||
ruffDir = await tc.extractZip(fullPathWithExtension);
|
ruffDir = await tc.extractZip(fullPathWithExtension);
|
||||||
// On windows extracting the zip does not create an intermediate directory
|
// On windows extracting the zip does not create an intermediate directory
|
||||||
} else {
|
} else {
|
||||||
const extractedDir = await tc.extractTar(downloadPath);
|
ruffDir = await tc.extractTar(downloadPath);
|
||||||
ruffDir = path.join(extractedDir, artifact);
|
if (semver.gte(version, "v0.5.0")) {
|
||||||
|
// Since v0.5.0 an intermediate directory is created
|
||||||
|
ruffDir = path.join(ruffDir, artifact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const cachedToolDir = await tc.cacheDir(
|
const files = await fs.readdir(ruffDir);
|
||||||
ruffDir,
|
core.debug(`Contents of ${ruffDir}: ${files.join(", ")}`);
|
||||||
TOOL_CACHE_NAME,
|
return ruffDir;
|
||||||
version,
|
|
||||||
arch,
|
|
||||||
);
|
|
||||||
return { version: version, cachedToolDir };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveVersion(
|
export async function resolveVersion(
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from "./utils/inputs";
|
} from "./utils/inputs";
|
||||||
import { getRuffVersionFromRequirementsFile } from "./utils/pyproject";
|
import { getRuffVersionFromRequirementsFile } from "./utils/pyproject";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
|
import * as semver from "semver";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
const platform = getPlatform();
|
const platform = getPlatform();
|
||||||
@@ -62,6 +63,11 @@ async function setupRuff(
|
|||||||
githubToken: string,
|
githubToken: string,
|
||||||
): Promise<{ ruffDir: string; version: string }> {
|
): Promise<{ ruffDir: string; version: string }> {
|
||||||
const resolvedVersion = await determineVersion();
|
const resolvedVersion = await determineVersion();
|
||||||
|
if (semver.lt(resolvedVersion, "v0.0.247")) {
|
||||||
|
throw Error(
|
||||||
|
"This action does not support ruff versions older than 0.0.247",
|
||||||
|
);
|
||||||
|
}
|
||||||
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
||||||
if (toolCacheResult.installedPath) {
|
if (toolCacheResult.installedPath) {
|
||||||
core.info(`Found ruffDir in tool-cache for ${toolCacheResult.version}`);
|
core.info(`Found ruffDir in tool-cache for ${toolCacheResult.version}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user