Compare commits

..
8 Commits
Author SHA1 Message Date
Kevin StillhammerandGitHub 7a82f1f7e4 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
2024-12-23 11:07:46 +01:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
cac2f108b2 Bump @types/node from 22.10.1 to 22.10.2 (#29)
Bumps
[@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node)
from 22.10.1 to 22.10.2.
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@types/node&package-manager=npm_and_yarn&previous-version=22.10.1&new-version=22.10.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-16 17:23:51 +01:00
Kevin StillhammerandGitHub 35619fdbcc Add problem matchers (#26)
Closes: #12
2024-12-08 12:17:50 +01:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
c9185454fa Bump @types/node from 22.9.3 to 22.10.1 (#20)
Bumps
[@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node)
from 22.9.3 to 22.10.1.
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@types/node&package-manager=npm_and_yarn&previous-version=22.9.3&new-version=22.10.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-12-08 11:38:39 +01:00
Kevin StillhammerandGitHub a2d5d1ffa4 Set output format to github (#24)
This was accidentally removed in the v2 release
2024-12-08 11:36:31 +01:00
Kevin StillhammerandGitHub ec9ad4417f Add lint error in malformed python project (#25) 2024-12-08 11:31:53 +01:00
Kevin StillhammerandGitHub efef6ba8fa Move release-drafter.yml to .github (#22)
Fixes `Configuration file .github/release-drafter.yml is not found. The
configuration file must reside in your default branch.`
2024-12-06 13:17:45 +01:00
Christian ClaussandGitHub e5ab5d43a6 README.md: astral-sh/ruff-action@v1 --> v2 (#21)
README.md upgraded to match
https://github.com/astral-sh/ruff-action/releases
```diff
- - uses: astral-sh/ruff-action@v1
+ - uses: astral-sh/ruff-action@v2
```
2024-12-06 08:49:52 +01:00
19 changed files with 4426 additions and 70 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "ruff-check",
"pattern": [
{
"regexp": "^Error: (.*):(\\d+):(\\d+): (\\w+) (.*)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
+14
View File
@@ -0,0 +1,14 @@
{
"problemMatcher": [
{
"owner": "ruff-format",
"pattern": [
{
"regexp": "^(Would reformat):\\s*(.+)$",
"message": 1,
"file": 2
}
]
}
]
}
+50 -5
View File
@@ -28,17 +28,18 @@ jobs:
- name: Make sure no changes from linters are detected - name: Make sure no changes from linters are detected
run: | run: |
git diff --exit-code git diff --exit-code
test-default-version: test-latest-version:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest] os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use default version - name: Use latest version
uses: ./ uses: ./
with: with:
src: __tests__/fixtures/python-project src: __tests__/fixtures/python-project
version: latest
test-specific-version: test-specific-version:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@@ -51,6 +52,39 @@ jobs:
with: with:
version: ${{ matrix.ruff-version }} version: ${{ matrix.ruff-version }}
src: __tests__/fixtures/python-project src: __tests__/fixtures/python-project
test-default-version-from-pyproject:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use default version from pyproject.toml
id: ruff-action
uses: ./
with:
src: __tests__/fixtures/python-project
- name: Correct version gets installed
run: |
if [ "$RUFF_VERSION" != "0.6.2" ]; then
exit 1
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-default-version-from-pyproject-dev-group:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use default version from pyproject.toml dev group
id: ruff-action
uses: ./
with:
src: __tests__/fixtures/pyproject-dependency-dev-project
version-file: __tests__/fixtures/pyproject-dependency-dev-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-semver-range: test-semver-range:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -114,8 +148,8 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use args - name: Format should fail
id: should-fail id: format-should-fail
continue-on-error: true continue-on-error: true
uses: ./ uses: ./
with: with:
@@ -123,7 +157,18 @@ jobs:
src: __tests__/fixtures/malformed-python-project src: __tests__/fixtures/malformed-python-project
- name: Check if the action failed - name: Check if the action failed
run: | run: |
if [ ${{ steps.should-fail.outcome }} == "success" ]; then if [ ${{ steps.format-should-fail.outcome }} == "success" ]; then
exit 1
fi
- name: Check should fail
id: check-should-fail
continue-on-error: true
uses: ./
with:
src: __tests__/fixtures/malformed-python-project
- name: Check if the action failed
run: |
if [ ${{ steps.check-should-fail.outcome }} == "success" ]; then
exit 1 exit 1
fi fi
test-multiple-src: test-multiple-src:
+26 -14
View File
@@ -19,6 +19,7 @@ fix).
- [Install the latest version (default)](#install-the-latest-version-default) - [Install the latest version (default)](#install-the-latest-version-default)
- [Install a specific version](#install-a-specific-version) - [Install a specific version](#install-a-specific-version)
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range) - [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
- [Install a version from a specified version file](#install-a-version-from-a-specified-version-file)
- [Validate checksum](#validate-checksum) - [Validate checksum](#validate-checksum)
- [GitHub authentication token](#github-authentication-token) - [GitHub authentication token](#github-authentication-token)
- [Outputs](#outputs) - [Outputs](#outputs)
@@ -26,8 +27,9 @@ fix).
## Usage ## Usage
| Input | Description | Default | | Input | Description | Default |
|----------------|---------------------------------------------------------------------------------------------|--------------------| |----------------|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | `latest` | | `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | `latest` |
| `version-file` | The file to read the version from. See [Install a version from a specified version file](#install-a-version-from-a-specified-version-file) | None |
| `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` | | `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` |
| `src` | The directory or single files to run `ruff` on. | [github.workspace] | | `src` | The directory or single files to run `ruff` on. | [github.workspace] |
| `checksum` | The sha256 checksum of the downloaded executable. | None | | `checksum` | The sha256 checksum of the downloaded executable. | None |
@@ -42,7 +44,7 @@ fix).
### Specify a different source directory ### Specify a different source directory
```yaml ```yaml
- uses: astral-sh/ruff-action@v1 - uses: astral-sh/ruff-action@v2
with: with:
src: "./src" src: "./src"
``` ```
@@ -50,7 +52,7 @@ fix).
### Specify multiple files ### Specify multiple files
```yaml ```yaml
- uses: astral-sh/ruff-action@v1 - uses: astral-sh/ruff-action@v2
with: with:
src: >- src: >-
path/to/file1.py path/to/file1.py
@@ -62,7 +64,7 @@ fix).
This action adds ruff to the PATH, so you can use it in subsequent steps. This action adds ruff to the PATH, so you can use it in subsequent steps.
```yaml ```yaml
- uses: astral-sh/ruff-action@v1 - uses: astral-sh/ruff-action@v2
- run: ruff check --fix - run: ruff check --fix
- run: ruff format - run: ruff format
``` ```
@@ -70,14 +72,18 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
### Use `ruff format` ### Use `ruff format`
```yaml ```yaml
- uses: astral-sh/ruff-action@v1 - uses: astral-sh/ruff-action@v2
with: with:
args: "format --check" args: "format --check"
``` ```
### Install specific versions ### Install specific versions
#### Install the latest version (default) 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
either `dependencies` or `dependency-groups.dev` the latest version is installed.
#### Install the latest version
```yaml ```yaml
- name: Install the latest version of ruff - name: Install the latest version of ruff
@@ -86,13 +92,7 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
version: "latest" version: "latest"
``` ```
> [!TIP] #### Install a specific version
>
> Using `latest` requires to download the ruff executable on every run, which incurs a cost
> (especially on self-hosted runners). As a best practice, consider pinning the version to a
> specific release.
### Install a specific version
```yaml ```yaml
- name: Install a specific version of ruff - name: Install a specific version of ruff
@@ -101,7 +101,7 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
version: "0.4.4" version: "0.4.4"
``` ```
### Install a version by supplying a semver range #### Install a version by supplying a semver range
You can specify a [semver range](https://github.com/npm/node-semver?tab=readme-ov-file#ranges) You can specify a [semver range](https://github.com/npm/node-semver?tab=readme-ov-file#ranges)
to install the latest version that satisfies the range. to install the latest version that satisfies the range.
@@ -120,6 +120,18 @@ to install the latest version that satisfies the range.
version: "0.4.x" version: "0.4.x"
``` ```
#### Install a version from a specified version file
You can specify a file to read the version from.
Currently `pyproject.toml` is supported.
```yaml
- name: Install a version from a specified version file
uses: astral-sh/ruff-action@v2
with:
version-file: "my-path/to/pyproject.toml"
```
### Validate checksum ### Validate checksum
You can specify a checksum to validate the downloaded executable. Checksums up to the default version You can specify a checksum to validate the downloaded executable. Checksums up to the default version
@@ -1,2 +1,4 @@
import sys
print("Hello world!") print("Hello world!")
print('How are you?') print('How are you?')
@@ -0,0 +1,15 @@
[project]
name = "pyproject-dependency-dev-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
[dependency-groups]
dev = [
"ruff==0.8.3"
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -0,0 +1,2 @@
def hello() -> str:
return "Hello from python-project!"
@@ -5,7 +5,7 @@ description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"
dependencies = [ dependencies = [
"ruff>=0.6.2", "ruff==0.6.2",
] ]
[build-system] [build-system]
+5 -2
View File
@@ -11,9 +11,12 @@ inputs:
required: false required: false
default: ${{ github.workspace }} default: ${{ github.workspace }}
version: version:
description: "The version of Ruff to use, e.g., `0.6.0` Defaults to the latest version." description: "The version of Ruff to use, e.g., `0.6.0` Defaults to the version in pyproject.toml or 'latest'."
required: false
default: ""
version-file:
description: "Path to a pyproject.toml or requirements.txt file to read the version from."
required: false required: false
default: "latest"
checksum: checksum:
description: "The checksum of the ruff version to install" description: "The checksum of the ruff version to install"
required: false required: false
Generated Vendored
+4178 -9
View File
File diff suppressed because it is too large Load Diff
+17 -10
View File
@@ -12,11 +12,12 @@
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1" "@actions/tool-cache": "^2.0.1",
"toml": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
"@types/node": "^22.9.1", "@types/node": "^22.10.2",
"@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",
@@ -386,12 +387,12 @@
} }
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "22.9.3", "version": "22.10.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.3.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz",
"integrity": "sha512-F3u1fs/fce3FFk+DAxbxc78DF8x0cY09RRL8GnXLmkJ1jvx3TtPdWoTT5/NiYfI5ASqXBmfqJi9dZ3gxMx4lzw==", "integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"undici-types": "~6.19.8" "undici-types": "~6.20.0"
} }
}, },
"node_modules/@types/semver": { "node_modules/@types/semver": {
@@ -453,6 +454,11 @@
"semver": "bin/semver.js" "semver": "bin/semver.js"
} }
}, },
"node_modules/toml": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
},
"node_modules/tunnel": { "node_modules/tunnel": {
"version": "0.0.6", "version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
@@ -486,10 +492,11 @@
} }
}, },
"node_modules/undici-types": { "node_modules/undici-types": {
"version": "6.19.8", "version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true "dev": true,
"license": "MIT"
}, },
"node_modules/universal-user-agent": { "node_modules/universal-user-agent": {
"version": "6.0.1", "version": "6.0.1",
+3 -2
View File
@@ -25,11 +25,12 @@
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1" "@actions/tool-cache": "^2.0.1",
"toml": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4", "@biomejs/biome": "1.9.4",
"@types/node": "^22.9.1", "@types/node": "^22.10.2",
"@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",
+4 -11
View File
@@ -29,13 +29,12 @@ export async function downloadVersion(
checkSum: string | undefined, checkSum: string | undefined,
githubToken: string, githubToken: string,
): Promise<{ version: string; cachedToolDir: string }> { ): Promise<{ version: string; cachedToolDir: string }> {
const resolvedVersion = await resolveVersion(version, githubToken);
const artifact = `ruff-${arch}-${platform}`; const artifact = `ruff-${arch}-${platform}`;
let extension = ".tar.gz"; let extension = ".tar.gz";
if (platform === "pc-windows-msvc") { if (platform === "pc-windows-msvc") {
extension = ".zip"; extension = ".zip";
} }
const downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${resolvedVersion}/${artifact}${extension}`; const downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}${extension}`;
core.info(`Downloading ruff from "${downloadUrl}" ...`); core.info(`Downloading ruff from "${downloadUrl}" ...`);
const downloadPath = await tc.downloadTool( const downloadPath = await tc.downloadTool(
@@ -43,13 +42,7 @@ export async function downloadVersion(
undefined, undefined,
githubToken, githubToken,
); );
await validateChecksum( await validateChecksum(checkSum, downloadPath, arch, platform, version);
checkSum,
downloadPath,
arch,
platform,
resolvedVersion,
);
let ruffDir: string; let ruffDir: string;
if (platform === "pc-windows-msvc") { if (platform === "pc-windows-msvc") {
@@ -64,10 +57,10 @@ export async function downloadVersion(
const cachedToolDir = await tc.cacheDir( const cachedToolDir = await tc.cacheDir(
ruffDir, ruffDir,
TOOL_CACHE_NAME, TOOL_CACHE_NAME,
resolvedVersion, version,
arch, arch,
); );
return { version: resolvedVersion, cachedToolDir }; return { version: version, cachedToolDir };
} }
export async function resolveVersion( export async function resolveVersion(
+54 -10
View File
@@ -13,7 +13,16 @@ import {
getPlatform, getPlatform,
type Platform, type Platform,
} from "./utils/platforms"; } 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> { async function run(): Promise<void> {
const platform = getPlatform(); const platform = getPlatform();
@@ -26,15 +35,11 @@ async function run(): Promise<void> {
if (arch === undefined) { if (arch === undefined) {
throw new Error(`Unsupported architecture: ${process.arch}`); throw new Error(`Unsupported architecture: ${process.arch}`);
} }
const setupResult = await setupRuff( const setupResult = await setupRuff(platform, arch, checkSum, githubToken);
platform,
arch,
version,
checkSum,
githubToken,
);
addRuffToPath(setupResult.ruffDir); addRuffToPath(setupResult.ruffDir);
setOutputFormat();
addMatchers();
core.setOutput("ruff-version", setupResult.version); core.setOutput("ruff-version", setupResult.version);
core.info(`Successfully installed ruff version ${setupResult.version}`); core.info(`Successfully installed ruff version ${setupResult.version}`);
@@ -53,11 +58,10 @@ async function run(): Promise<void> {
async function setupRuff( async function setupRuff(
platform: Platform, platform: Platform,
arch: Architecture, arch: Architecture,
versionInput: string,
checkSum: string | undefined, checkSum: string | undefined,
githubToken: string, githubToken: string,
): Promise<{ ruffDir: string; version: string }> { ): Promise<{ ruffDir: string; version: string }> {
const resolvedVersion = await resolveVersion(versionInput, githubToken); const resolvedVersion = await determineVersion();
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}`);
@@ -81,11 +85,51 @@ 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 { function addRuffToPath(cachedPath: string): void {
core.addPath(cachedPath); core.addPath(cachedPath);
core.info(`Added ${cachedPath} to the path`); core.info(`Added ${cachedPath} to the path`);
} }
function setOutputFormat() {
core.exportVariable("RUFF_OUTPUT_FORMAT", "github");
core.info("Set RUFF_OUTPUT_FORMAT to github");
}
function addMatchers(): void {
const matchersPath = path.join(
__dirname,
`..${path.sep}..`,
".github",
"matchers",
);
core.info(`##[add-matcher]${path.join(matchersPath, "check.json")}`);
core.info(`##[add-matcher]${path.join(matchersPath, "format.json")}`);
}
async function runRuff( async function runRuff(
ruffExecutablePath: string, ruffExecutablePath: string,
args: string[], args: string[],
+1
View File
@@ -5,3 +5,4 @@ export const checkSum = core.getInput("checksum");
export const githubToken = core.getInput("github-token"); export const githubToken = core.getInput("github-token");
export const args = core.getInput("args"); export const args = core.getInput("args");
export const src = core.getInput("src"); export const src = core.getInput("src");
export const versionFile = core.getInput("version-file");
+30
View 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;
}