mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-08-09 18:57:02 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdcb81f9c5 | ||
|
|
276e678697 |
@@ -35,7 +35,7 @@ jobs:
|
|||||||
- name: Compare the expected and actual dist/ directories
|
- name: Compare the expected and actual dist/ directories
|
||||||
run: |
|
run: |
|
||||||
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
||||||
echo "::error::Detected uncommitted changes after build. Run 'npm run build' and commit the changes."
|
echo "Detected uncommitted changes after build. See status below:"
|
||||||
git diff --text -v
|
git diff --text -v
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Actionlint
|
- name: Actionlint
|
||||||
uses: eifinger/actionlint-action@23c85443d840cd73bbecb9cddfc933cc21649a38 # v1.9.1
|
uses: eifinger/actionlint-action@8ebeb40569f3c15ca66fe36d1b75f9b70c6c4f6e # v1.9.0
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: "20"
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
npm run all
|
npm run all
|
||||||
- name: Make sure no changes from linters are detected
|
- name: Make sure no changes from linters are detected
|
||||||
run: |
|
run: |
|
||||||
git diff --exit-code || (echo "::error::Please run 'npm run all' to fix the issues" && exit 1)
|
git diff --exit-code
|
||||||
test-latest-version:
|
test-latest-version:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
@@ -51,23 +51,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: ${{ matrix.ruff-version }}
|
version: ${{ matrix.ruff-version }}
|
||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
test-version-from-version-file-pyproject:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Use version from pyproject.toml
|
|
||||||
id: ruff-action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
src: __tests__/fixtures/python-project
|
|
||||||
version-file: __tests__/fixtures/pyproject.toml
|
|
||||||
- name: Correct version gets installed
|
|
||||||
run: |
|
|
||||||
if [ "$RUFF_VERSION" != "0.9.3" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
|
||||||
test-default-version-from-pyproject:
|
test-default-version-from-pyproject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -101,57 +84,6 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
test-default-version-from-pyproject-dependency-groups:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Use default version from pyproject.toml dependency groups
|
|
||||||
id: ruff-action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
src: __tests__/fixtures/pyproject-dependency-groups-project
|
|
||||||
version-file: __tests__/fixtures/pyproject-dependency-groups-project/pyproject.toml
|
|
||||||
- name: Correct version gets installed
|
|
||||||
run: |
|
|
||||||
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
|
||||||
test-default-version-from-pyproject-optional-dependencies:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Use default version from pyproject.toml optional dependencies
|
|
||||||
id: ruff-action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
src: __tests__/fixtures/pyproject-optional-dependencies-project
|
|
||||||
version-file: __tests__/fixtures/pyproject-optional-dependencies-project/pyproject.toml
|
|
||||||
- name: Correct version gets installed
|
|
||||||
run: |
|
|
||||||
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
|
||||||
test-default-version-from-requirements:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Use default version from requirements.txt
|
|
||||||
id: ruff-action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
src: __tests__/fixtures/python-project
|
|
||||||
version-file: __tests__/fixtures/requirements.txt
|
|
||||||
- name: Correct version gets installed
|
|
||||||
run: |
|
|
||||||
if [ "$RUFF_VERSION" != "0.9.0" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
env:
|
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
|
||||||
test-semver-range:
|
test-semver-range:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
name: "Update known checksums"
|
name: "Update known checksums"
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
|
||||||
- cron: "0 4 * * *" # Run every day at 4am UTC
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
|
|||||||
|
|
||||||
By default this action looks for a pyproject.toml file in the root of the repository to determine
|
By default this action looks for a pyproject.toml file in the root of the repository to determine
|
||||||
the ruff version to install. If no pyproject.toml file is found, or no ruff version is defined in
|
the ruff version to install. If no pyproject.toml file is found, or no ruff version is defined in
|
||||||
`project.dependencies`, `project.optional-dependencies`, or `dependency-groups`,
|
either `dependencies` or `dependency-groups.dev` the latest version is installed.
|
||||||
the latest version is installed.
|
|
||||||
|
|
||||||
#### Install the latest version
|
#### Install the latest version
|
||||||
|
|
||||||
@@ -124,13 +123,13 @@ to install the latest version that satisfies the range.
|
|||||||
#### Install a version from a specified version file
|
#### Install a version from a specified version file
|
||||||
|
|
||||||
You can specify a file to read the version from.
|
You can specify a file to read the version from.
|
||||||
Currently `pyproject.toml` and `requirements.txt` are supported.
|
Currently `pyproject.toml` is supported.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a version from a specified version file
|
- name: Install a version from a specified version file
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
version-file: "my-path/to/pyproject.toml-or-requirements.txt"
|
version-file: "my-path/to/pyproject.toml"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Validate checksum
|
### Validate checksum
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "pyproject-dependency-groups-project"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Add your description here"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.12"
|
|
||||||
|
|
||||||
[dependency-groups]
|
|
||||||
dev = [
|
|
||||||
{ include-group = "docs" },
|
|
||||||
{ include-group = "lint" },
|
|
||||||
]
|
|
||||||
docs = [
|
|
||||||
"sphinx",
|
|
||||||
]
|
|
||||||
lint = [
|
|
||||||
"ruff==0.8.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["hatchling"]
|
|
||||||
build-backend = "hatchling.build"
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
def hello() -> str:
|
|
||||||
return "Hello from python-project!"
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
print("Hello world!")
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "pyproject-optional-dependencies-project"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Add your description here"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.12"
|
|
||||||
|
|
||||||
[project.optional-dependencies]
|
|
||||||
lint = [
|
|
||||||
"ruff==0.8.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["hatchling"]
|
|
||||||
build-backend = "hatchling.build"
|
|
||||||
-2
@@ -1,2 +0,0 @@
|
|||||||
def hello() -> str:
|
|
||||||
return "Hello from python-project!"
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
print("Hello world!")
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "pyython-project"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Add your description here"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.12"
|
|
||||||
dependencies = [
|
|
||||||
"ruff==0.9.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["hatchling"]
|
|
||||||
build-backend = "hatchling.build"
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ruff==0.9.0
|
|
||||||
+34
-43
@@ -30387,7 +30387,6 @@ async function downloadVersion(platform, arch, version, checkSum, githubToken) {
|
|||||||
return { version: version, cachedToolDir };
|
return { version: version, cachedToolDir };
|
||||||
}
|
}
|
||||||
async function resolveVersion(versionInput, githubToken) {
|
async function resolveVersion(versionInput, githubToken) {
|
||||||
core.debug(`Resolving ${versionInput}...`);
|
|
||||||
const version = versionInput === "latest"
|
const version = versionInput === "latest"
|
||||||
? await getLatestVersion(githubToken)
|
? await getLatestVersion(githubToken)
|
||||||
: versionInput;
|
: versionInput;
|
||||||
@@ -30400,20 +30399,22 @@ async function resolveVersion(versionInput, githubToken) {
|
|||||||
if (resolvedVersion === "") {
|
if (resolvedVersion === "") {
|
||||||
throw new Error(`No version found for ${version}`);
|
throw new Error(`No version found for ${version}`);
|
||||||
}
|
}
|
||||||
core.debug(`Resolved version: ${resolvedVersion}`);
|
|
||||||
return resolvedVersion;
|
return resolvedVersion;
|
||||||
}
|
}
|
||||||
async function getAvailableVersions(githubToken) {
|
async function getAvailableVersions(githubToken) {
|
||||||
try {
|
try {
|
||||||
const octokit = new PaginatingOctokit({
|
const octokit = new PaginatingOctokit({
|
||||||
auth: githubToken,
|
auth: githubToken,
|
||||||
|
baseUrl: constants_1.GITHUB_COM_API,
|
||||||
});
|
});
|
||||||
return await getReleaseTagNames(octokit);
|
return await getReleaseTagNames(octokit);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (err.message.includes("Bad credentials")) {
|
if (err.message.includes("Bad credentials")) {
|
||||||
core.info("No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.");
|
core.info("No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.");
|
||||||
const octokit = new PaginatingOctokit();
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: constants_1.GITHUB_COM_API,
|
||||||
|
});
|
||||||
return await getReleaseTagNames(octokit);
|
return await getReleaseTagNames(octokit);
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
@@ -30428,6 +30429,7 @@ async function getReleaseTagNames(octokit) {
|
|||||||
}
|
}
|
||||||
async function getLatestVersion(githubToken) {
|
async function getLatestVersion(githubToken) {
|
||||||
const octokit = new PaginatingOctokit({
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: constants_1.GITHUB_COM_API,
|
||||||
auth: githubToken,
|
auth: githubToken,
|
||||||
});
|
});
|
||||||
let latestRelease;
|
let latestRelease;
|
||||||
@@ -30437,7 +30439,9 @@ async function getLatestVersion(githubToken) {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
if (err.message.includes("Bad credentials")) {
|
if (err.message.includes("Bad credentials")) {
|
||||||
core.info("No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.");
|
core.info("No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.");
|
||||||
const octokit = new PaginatingOctokit();
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: constants_1.GITHUB_COM_API,
|
||||||
|
});
|
||||||
latestRelease = await getLatestRelease(octokit);
|
latestRelease = await getLatestRelease(octokit);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -30554,21 +30558,17 @@ async function determineVersion() {
|
|||||||
return await (0, download_version_1.resolveVersion)(inputs_1.version, inputs_1.githubToken);
|
return await (0, download_version_1.resolveVersion)(inputs_1.version, inputs_1.githubToken);
|
||||||
}
|
}
|
||||||
if (inputs_1.versionFile !== "") {
|
if (inputs_1.versionFile !== "") {
|
||||||
const versionFromPyproject = (0, pyproject_1.getRuffVersionFromRequirementsFile)(inputs_1.versionFile);
|
const versionFromPyproject = (0, pyproject_1.getRuffVersionFromPyproject)(inputs_1.versionFile);
|
||||||
if (versionFromPyproject === undefined) {
|
if (versionFromPyproject === undefined) {
|
||||||
core.warning(`Could not parse version from ${inputs_1.versionFile}. Using latest version.`);
|
core.warning("Could not parse version from supplied pyproject.toml. Using latest version.");
|
||||||
|
return await (0, download_version_1.resolveVersion)("latest", inputs_1.githubToken);
|
||||||
}
|
}
|
||||||
return await (0, download_version_1.resolveVersion)(versionFromPyproject || "latest", inputs_1.githubToken);
|
|
||||||
}
|
}
|
||||||
const pyProjectPath = path.join(inputs_1.src, "pyproject.toml");
|
const pyProjectPath = path.join(inputs_1.src, "pyproject.toml");
|
||||||
if (!fs.existsSync(pyProjectPath)) {
|
if (!fs.existsSync(pyProjectPath)) {
|
||||||
core.info(`Could not find ${pyProjectPath}. Using latest version.`);
|
|
||||||
return await (0, download_version_1.resolveVersion)("latest", inputs_1.githubToken);
|
return await (0, download_version_1.resolveVersion)("latest", inputs_1.githubToken);
|
||||||
}
|
}
|
||||||
const versionFromPyproject = (0, pyproject_1.getRuffVersionFromRequirementsFile)(pyProjectPath);
|
const versionFromPyproject = (0, pyproject_1.getRuffVersionFromPyproject)(pyProjectPath);
|
||||||
if (versionFromPyproject === undefined) {
|
|
||||||
core.warning(`Could not parse version from ${pyProjectPath}. Using latest version.`);
|
|
||||||
}
|
|
||||||
return await (0, download_version_1.resolveVersion)(versionFromPyproject || "latest", inputs_1.githubToken);
|
return await (0, download_version_1.resolveVersion)(versionFromPyproject || "latest", inputs_1.githubToken);
|
||||||
}
|
}
|
||||||
function addRuffToPath(cachedPath) {
|
function addRuffToPath(cachedPath) {
|
||||||
@@ -30599,10 +30599,11 @@ run();
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0;
|
exports.GITHUB_COM_API = exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0;
|
||||||
exports.REPO = "ruff";
|
exports.REPO = "ruff";
|
||||||
exports.OWNER = "astral-sh";
|
exports.OWNER = "astral-sh";
|
||||||
exports.TOOL_CACHE_NAME = "ruff";
|
exports.TOOL_CACHE_NAME = "ruff";
|
||||||
|
exports.GITHUB_COM_API = "https://api.github.com";
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -30731,12 +30732,29 @@ var __importStar = (this && this.__importStar) || (function () {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getRuffVersionFromRequirementsFile = getRuffVersionFromRequirementsFile;
|
exports.getRuffVersionFromPyproject = getRuffVersionFromPyproject;
|
||||||
const fs = __importStar(__nccwpck_require__(3024));
|
const fs = __importStar(__nccwpck_require__(3024));
|
||||||
const core = __importStar(__nccwpck_require__(7484));
|
const core = __importStar(__nccwpck_require__(7484));
|
||||||
const toml = __importStar(__nccwpck_require__(7106));
|
const toml = __importStar(__nccwpck_require__(7106));
|
||||||
function getRuffVersionFromAllDependencies(allDependencies) {
|
function getRuffVersionFromPyproject(filePath) {
|
||||||
const ruffVersionDefinition = allDependencies.find((dep) => dep.startsWith("ruff"));
|
if (!fs.existsSync(filePath)) {
|
||||||
|
core.warning(`Could not find file: ${filePath}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
||||||
|
let pyproject;
|
||||||
|
try {
|
||||||
|
pyproject = toml.parse(pyprojectContent);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
const message = err.message;
|
||||||
|
core.warning(`Error while parsing ${filePath}: ${message}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const dependencies = pyproject?.project?.dependencies || [];
|
||||||
|
const devDependencies = pyproject?.["dependency-groups"]?.dev || [];
|
||||||
|
const ruffVersionDefinition = dependencies.find((dep) => dep.startsWith("ruff")) ||
|
||||||
|
devDependencies.find((dep) => dep.startsWith("ruff"));
|
||||||
if (ruffVersionDefinition) {
|
if (ruffVersionDefinition) {
|
||||||
const ruffVersion = ruffVersionDefinition
|
const ruffVersion = ruffVersionDefinition
|
||||||
.match(/^ruff([^A-Z0-9._-]+.*)$/)?.[1]
|
.match(/^ruff([^A-Z0-9._-]+.*)$/)?.[1]
|
||||||
@@ -30749,33 +30767,6 @@ function getRuffVersionFromAllDependencies(allDependencies) {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
function parsePyproject(pyprojectContent) {
|
|
||||||
const pyproject = toml.parse(pyprojectContent);
|
|
||||||
const dependencies = pyproject?.project?.dependencies || [];
|
|
||||||
const optionalDependencies = Object.values(pyproject?.project?.["optional-dependencies"] || {}).flat();
|
|
||||||
const devDependencies = Object.values(pyproject?.["dependency-groups"] || {})
|
|
||||||
.flat()
|
|
||||||
.filter((item) => typeof item === "string");
|
|
||||||
return getRuffVersionFromAllDependencies(dependencies.concat(optionalDependencies, devDependencies));
|
|
||||||
}
|
|
||||||
function getRuffVersionFromRequirementsFile(filePath) {
|
|
||||||
if (!fs.existsSync(filePath)) {
|
|
||||||
core.warning(`Could not find file: ${filePath}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
|
||||||
if (filePath.endsWith(".txt")) {
|
|
||||||
return getRuffVersionFromAllDependencies(pyprojectContent.split("\n"));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return parsePyproject(pyprojectContent);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
const message = err.message;
|
|
||||||
core.warning(`Error while parsing ${filePath}: ${message}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
+2
-1
@@ -30383,10 +30383,11 @@ run();
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0;
|
exports.GITHUB_COM_API = exports.TOOL_CACHE_NAME = exports.OWNER = exports.REPO = void 0;
|
||||||
exports.REPO = "ruff";
|
exports.REPO = "ruff";
|
||||||
exports.OWNER = "astral-sh";
|
exports.OWNER = "astral-sh";
|
||||||
exports.TOOL_CACHE_NAME = "ruff";
|
exports.TOOL_CACHE_NAME = "ruff";
|
||||||
|
exports.GITHUB_COM_API = "https://api.github.com";
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
Generated
+16
-8
@@ -12,14 +12,13 @@
|
|||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@octokit/core": "^6.1.3",
|
|
||||||
"@octokit/plugin-paginate-rest": "^11.4.0",
|
"@octokit/plugin-paginate-rest": "^11.4.0",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^13.3.0",
|
"@octokit/plugin-rest-endpoint-methods": "^13.3.0",
|
||||||
"smol-toml": "^1.3.1"
|
"smol-toml": "^1.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
"@types/node": "^22.12.0",
|
"@types/node": "^22.10.10",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
@@ -237,6 +236,7 @@
|
|||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.2.tgz",
|
||||||
"integrity": "sha512-JcQDsBdg49Yky2w2ld20IHAlwr8d/d8N6NiOXbtuoPCqzbsiJgF633mVUw3x4mo0H5ypataQIX7SFu3yy44Mpw==",
|
"integrity": "sha512-JcQDsBdg49Yky2w2ld20IHAlwr8d/d8N6NiOXbtuoPCqzbsiJgF633mVUw3x4mo0H5ypataQIX7SFu3yy44Mpw==",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 18"
|
"node": ">= 18"
|
||||||
}
|
}
|
||||||
@@ -245,6 +245,7 @@
|
|||||||
"version": "6.1.3",
|
"version": "6.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.3.tgz",
|
||||||
"integrity": "sha512-z+j7DixNnfpdToYsOutStDgeRzJSMnbj8T1C/oQjB6Aa+kRfNjs/Fn7W6c8bmlt6mfy3FkgeKBRnDjxQow5dow==",
|
"integrity": "sha512-z+j7DixNnfpdToYsOutStDgeRzJSMnbj8T1C/oQjB6Aa+kRfNjs/Fn7W6c8bmlt6mfy3FkgeKBRnDjxQow5dow==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/auth-token": "^5.0.0",
|
"@octokit/auth-token": "^5.0.0",
|
||||||
"@octokit/graphql": "^8.1.2",
|
"@octokit/graphql": "^8.1.2",
|
||||||
@@ -262,6 +263,7 @@
|
|||||||
"version": "10.1.2",
|
"version": "10.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.2.tgz",
|
||||||
"integrity": "sha512-XybpFv9Ms4hX5OCHMZqyODYqGTZ3H6K6Vva+M9LR7ib/xr1y1ZnlChYv9H680y77Vd/i/k+thXApeRASBQkzhA==",
|
"integrity": "sha512-XybpFv9Ms4hX5OCHMZqyODYqGTZ3H6K6Vva+M9LR7ib/xr1y1ZnlChYv9H680y77Vd/i/k+thXApeRASBQkzhA==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/types": "^13.6.2",
|
"@octokit/types": "^13.6.2",
|
||||||
"universal-user-agent": "^7.0.2"
|
"universal-user-agent": "^7.0.2"
|
||||||
@@ -274,6 +276,7 @@
|
|||||||
"version": "8.1.2",
|
"version": "8.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.1.2.tgz",
|
||||||
"integrity": "sha512-bdlj/CJVjpaz06NBpfHhp4kGJaRZfz7AzC+6EwUImRtrwIw8dIgJ63Xg0OzV9pRn3rIzrt5c2sa++BL0JJ8GLw==",
|
"integrity": "sha512-bdlj/CJVjpaz06NBpfHhp4kGJaRZfz7AzC+6EwUImRtrwIw8dIgJ63Xg0OzV9pRn3rIzrt5c2sa++BL0JJ8GLw==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/request": "^9.1.4",
|
"@octokit/request": "^9.1.4",
|
||||||
"@octokit/types": "^13.6.2",
|
"@octokit/types": "^13.6.2",
|
||||||
@@ -320,6 +323,7 @@
|
|||||||
"version": "9.2.0",
|
"version": "9.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.2.0.tgz",
|
||||||
"integrity": "sha512-kXLfcxhC4ozCnAXy2ff+cSxpcF0A1UqxjvYMqNuPIeOAzJbVWQ+dy5G2fTylofB/gTbObT8O6JORab+5XtA1Kw==",
|
"integrity": "sha512-kXLfcxhC4ozCnAXy2ff+cSxpcF0A1UqxjvYMqNuPIeOAzJbVWQ+dy5G2fTylofB/gTbObT8O6JORab+5XtA1Kw==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/endpoint": "^10.0.0",
|
"@octokit/endpoint": "^10.0.0",
|
||||||
"@octokit/request-error": "^6.0.1",
|
"@octokit/request-error": "^6.0.1",
|
||||||
@@ -335,6 +339,7 @@
|
|||||||
"version": "6.1.6",
|
"version": "6.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.6.tgz",
|
||||||
"integrity": "sha512-pqnVKYo/at0NuOjinrgcQYpEbv4snvP3bKMRqHaD9kIsk9u1LCpb2smHZi8/qJfgeNqLo5hNW4Z7FezNdEo0xg==",
|
"integrity": "sha512-pqnVKYo/at0NuOjinrgcQYpEbv4snvP3bKMRqHaD9kIsk9u1LCpb2smHZi8/qJfgeNqLo5hNW4Z7FezNdEo0xg==",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/types": "^13.6.2"
|
"@octokit/types": "^13.6.2"
|
||||||
},
|
},
|
||||||
@@ -351,9 +356,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.12.0",
|
"version": "22.10.10",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.10.tgz",
|
||||||
"integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==",
|
"integrity": "sha512-X47y/mPNzxviAGY5TcYPtYL8JsY3kAq2n8fMmKoRCxq/c4v4pyGNCzM2R6+M5/umG4ZfHuT+sgqDYqWc9rJ6ww==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -384,7 +389,8 @@
|
|||||||
"node_modules/before-after-hook": {
|
"node_modules/before-after-hook": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz",
|
||||||
"integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A=="
|
"integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/fast-content-type-parse": {
|
"node_modules/fast-content-type-parse": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
@@ -399,7 +405,8 @@
|
|||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
"url": "https://opencollective.com/fastify"
|
"url": "https://opencollective.com/fastify"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/js-yaml": {
|
"node_modules/js-yaml": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
@@ -474,7 +481,8 @@
|
|||||||
"node_modules/universal-user-agent": {
|
"node_modules/universal-user-agent": {
|
||||||
"version": "7.0.2",
|
"version": "7.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz",
|
||||||
"integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q=="
|
"integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/uuid": {
|
"node_modules/uuid": {
|
||||||
"version": "3.4.0",
|
"version": "3.4.0",
|
||||||
|
|||||||
+2
-3
@@ -12,7 +12,7 @@
|
|||||||
"package": "ncc build -o dist/ruff-action src/ruff-action.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
|
"package": "ncc build -o dist/ruff-action src/ruff-action.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
|
||||||
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
||||||
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
|
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.js src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
|
||||||
"all": "npm install && npm run build && npm run format && npm run lint && npm run package"
|
"all": "npm run build && npm run format && npm run lint && npm run package"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -25,14 +25,13 @@
|
|||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@octokit/core": "^6.1.3",
|
|
||||||
"@octokit/plugin-paginate-rest": "^11.4.0",
|
"@octokit/plugin-paginate-rest": "^11.4.0",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^13.3.0",
|
"@octokit/plugin-rest-endpoint-methods": "^13.3.0",
|
||||||
"smol-toml": "^1.3.1"
|
"smol-toml": "^1.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
"@types/node": "^22.12.0",
|
"@types/node": "^22.10.10",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ 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 { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
|
import {
|
||||||
|
GITHUB_COM_API,
|
||||||
|
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";
|
||||||
import { Octokit } from "@octokit/core";
|
import { Octokit } from "@octokit/core";
|
||||||
@@ -71,7 +76,6 @@ export async function resolveVersion(
|
|||||||
versionInput: string,
|
versionInput: string,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.debug(`Resolving ${versionInput}...`);
|
|
||||||
const version =
|
const version =
|
||||||
versionInput === "latest"
|
versionInput === "latest"
|
||||||
? await getLatestVersion(githubToken)
|
? await getLatestVersion(githubToken)
|
||||||
@@ -85,7 +89,6 @@ export async function resolveVersion(
|
|||||||
if (resolvedVersion === "") {
|
if (resolvedVersion === "") {
|
||||||
throw new Error(`No version found for ${version}`);
|
throw new Error(`No version found for ${version}`);
|
||||||
}
|
}
|
||||||
core.debug(`Resolved version: ${resolvedVersion}`);
|
|
||||||
return resolvedVersion;
|
return resolvedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +96,7 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
|
|||||||
try {
|
try {
|
||||||
const octokit = new PaginatingOctokit({
|
const octokit = new PaginatingOctokit({
|
||||||
auth: githubToken,
|
auth: githubToken,
|
||||||
|
baseUrl: GITHUB_COM_API,
|
||||||
});
|
});
|
||||||
return await getReleaseTagNames(octokit);
|
return await getReleaseTagNames(octokit);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -100,7 +104,9 @@ async function getAvailableVersions(githubToken: string): Promise<string[]> {
|
|||||||
core.info(
|
core.info(
|
||||||
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
|
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
|
||||||
);
|
);
|
||||||
const octokit = new PaginatingOctokit();
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: GITHUB_COM_API,
|
||||||
|
});
|
||||||
return await getReleaseTagNames(octokit);
|
return await getReleaseTagNames(octokit);
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
@@ -119,6 +125,7 @@ async function getReleaseTagNames(
|
|||||||
|
|
||||||
async function getLatestVersion(githubToken: string) {
|
async function getLatestVersion(githubToken: string) {
|
||||||
const octokit = new PaginatingOctokit({
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: GITHUB_COM_API,
|
||||||
auth: githubToken,
|
auth: githubToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,7 +137,9 @@ async function getLatestVersion(githubToken: string) {
|
|||||||
core.info(
|
core.info(
|
||||||
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
|
"No (valid) GitHub token provided. Falling back to anonymous. Requests might be rate limited.",
|
||||||
);
|
);
|
||||||
const octokit = new PaginatingOctokit();
|
const octokit = new PaginatingOctokit({
|
||||||
|
baseUrl: GITHUB_COM_API,
|
||||||
|
});
|
||||||
latestRelease = await getLatestRelease(octokit);
|
latestRelease = await getLatestRelease(octokit);
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
+5
-13
@@ -21,7 +21,7 @@ import {
|
|||||||
version,
|
version,
|
||||||
versionFile as versionFileInput,
|
versionFile as versionFileInput,
|
||||||
} from "./utils/inputs";
|
} from "./utils/inputs";
|
||||||
import { getRuffVersionFromRequirementsFile } from "./utils/pyproject";
|
import { getRuffVersionFromPyproject } from "./utils/pyproject";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
@@ -93,27 +93,19 @@ async function determineVersion(): Promise<string> {
|
|||||||
return await resolveVersion(version, githubToken);
|
return await resolveVersion(version, githubToken);
|
||||||
}
|
}
|
||||||
if (versionFileInput !== "") {
|
if (versionFileInput !== "") {
|
||||||
const versionFromPyproject =
|
const versionFromPyproject = getRuffVersionFromPyproject(versionFileInput);
|
||||||
getRuffVersionFromRequirementsFile(versionFileInput);
|
|
||||||
if (versionFromPyproject === undefined) {
|
if (versionFromPyproject === undefined) {
|
||||||
core.warning(
|
core.warning(
|
||||||
`Could not parse version from ${versionFileInput}. Using latest version.`,
|
"Could not parse version from supplied pyproject.toml. Using latest version.",
|
||||||
);
|
);
|
||||||
|
return await resolveVersion("latest", githubToken);
|
||||||
}
|
}
|
||||||
return await resolveVersion(versionFromPyproject || "latest", githubToken);
|
|
||||||
}
|
}
|
||||||
const pyProjectPath = path.join(src, "pyproject.toml");
|
const pyProjectPath = path.join(src, "pyproject.toml");
|
||||||
if (!fs.existsSync(pyProjectPath)) {
|
if (!fs.existsSync(pyProjectPath)) {
|
||||||
core.info(`Could not find ${pyProjectPath}. Using latest version.`);
|
|
||||||
return await resolveVersion("latest", githubToken);
|
return await resolveVersion("latest", githubToken);
|
||||||
}
|
}
|
||||||
const versionFromPyproject =
|
const versionFromPyproject = getRuffVersionFromPyproject(pyProjectPath);
|
||||||
getRuffVersionFromRequirementsFile(pyProjectPath);
|
|
||||||
if (versionFromPyproject === undefined) {
|
|
||||||
core.warning(
|
|
||||||
`Could not parse version from ${pyProjectPath}. Using latest version.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return await resolveVersion(versionFromPyproject || "latest", githubToken);
|
return await resolveVersion(versionFromPyproject || "latest", githubToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export const REPO = "ruff";
|
export const REPO = "ruff";
|
||||||
export const OWNER = "astral-sh";
|
export const OWNER = "astral-sh";
|
||||||
export const TOOL_CACHE_NAME = "ruff";
|
export const TOOL_CACHE_NAME = "ruff";
|
||||||
|
export const GITHUB_COM_API = "https://api.github.com";
|
||||||
|
|||||||
+27
-47
@@ -2,12 +2,34 @@ import * as fs from "node:fs";
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as toml from "smol-toml";
|
import * as toml from "smol-toml";
|
||||||
|
|
||||||
function getRuffVersionFromAllDependencies(
|
export function getRuffVersionFromPyproject(
|
||||||
allDependencies: string[],
|
filePath: string,
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
const ruffVersionDefinition = allDependencies.find((dep: string) =>
|
if (!fs.existsSync(filePath)) {
|
||||||
dep.startsWith("ruff"),
|
core.warning(`Could not find file: ${filePath}`);
|
||||||
);
|
return undefined;
|
||||||
|
}
|
||||||
|
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
||||||
|
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 || [];
|
||||||
|
|
||||||
|
const ruffVersionDefinition =
|
||||||
|
dependencies.find((dep: string) => dep.startsWith("ruff")) ||
|
||||||
|
devDependencies.find((dep: string) => dep.startsWith("ruff"));
|
||||||
|
|
||||||
if (ruffVersionDefinition) {
|
if (ruffVersionDefinition) {
|
||||||
const ruffVersion = ruffVersionDefinition
|
const ruffVersion = ruffVersionDefinition
|
||||||
@@ -22,45 +44,3 @@ function getRuffVersionFromAllDependencies(
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsePyproject(pyprojectContent: string): string | undefined {
|
|
||||||
const pyproject: {
|
|
||||||
project?: {
|
|
||||||
dependencies?: string[];
|
|
||||||
"optional-dependencies"?: Map<string, string[]>;
|
|
||||||
};
|
|
||||||
"dependency-groups"?: Map<string, Array<string | object>>;
|
|
||||||
} = toml.parse(pyprojectContent);
|
|
||||||
const dependencies: string[] = pyproject?.project?.dependencies || [];
|
|
||||||
const optionalDependencies: string[] = Object.values(
|
|
||||||
pyproject?.project?.["optional-dependencies"] || {},
|
|
||||||
).flat();
|
|
||||||
const devDependencies: string[] = Object.values(
|
|
||||||
pyproject?.["dependency-groups"] || {},
|
|
||||||
)
|
|
||||||
.flat()
|
|
||||||
.filter((item: string | object) => typeof item === "string");
|
|
||||||
return getRuffVersionFromAllDependencies(
|
|
||||||
dependencies.concat(optionalDependencies, devDependencies),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRuffVersionFromRequirementsFile(
|
|
||||||
filePath: string,
|
|
||||||
): string | undefined {
|
|
||||||
if (!fs.existsSync(filePath)) {
|
|
||||||
core.warning(`Could not find file: ${filePath}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
|
|
||||||
if (filePath.endsWith(".txt")) {
|
|
||||||
return getRuffVersionFromAllDependencies(pyprojectContent.split("\n"));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return parsePyproject(pyprojectContent);
|
|
||||||
} catch (err) {
|
|
||||||
const message = (err as Error).message;
|
|
||||||
core.warning(`Error while parsing ${filePath}: ${message}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user