Skip to content

Commit

Permalink
Default to ruff-version from pyproject.toml (#30)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eifinger authored Dec 23, 2024
1 parent cac2f10 commit 7a82f1f
Show file tree
Hide file tree
Showing 15 changed files with 4,335 additions and 53 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ jobs:
- name: Make sure no changes from linters are detected
run: |
git diff --exit-code
test-default-version:
test-latest-version:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Use default version
- name: Use latest version
uses: ./
with:
src: __tests__/fixtures/python-project
version: latest
test-specific-version:
runs-on: ubuntu-latest
strategy:
Expand All @@ -51,6 +52,39 @@ jobs:
with:
version: ${{ matrix.ruff-version }}
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:
runs-on: ubuntu-latest
steps:
Expand Down
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ fix).
- [Install the latest version (default)](#install-the-latest-version-default)
- [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 from a specified version file](#install-a-version-from-a-specified-version-file)
- [Validate checksum](#validate-checksum)
- [GitHub authentication token](#github-authentication-token)
- [Outputs](#outputs)

## Usage

| Input | Description | Default |
|----------------|---------------------------------------------------------------------------------------------|--------------------|
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | `latest` |
| `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] |
| `checksum` | The sha256 checksum of the downloaded executable. | None |
| `github-token` | The GitHub token to use for authentication. | `GITHUB_TOKEN` |
| Input | Description | Default |
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
| `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` |
| `src` | The directory or single files to run `ruff` on. | [github.workspace] |
| `checksum` | The sha256 checksum of the downloaded executable. | None |
| `github-token` | The GitHub token to use for authentication. | `GITHUB_TOKEN` |

### Basic

Expand Down Expand Up @@ -77,7 +79,11 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.

### 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
- name: Install the latest version of ruff
Expand All @@ -86,13 +92,7 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
version: "latest"
```

> [!TIP]
>
> 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
#### Install a specific version

```yaml
- name: Install a specific version of ruff
Expand All @@ -101,7 +101,7 @@ This action adds ruff to the PATH, so you can use it in subsequent steps.
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)
to install the latest version that satisfies the range.
Expand All @@ -120,6 +120,18 @@ to install the latest version that satisfies the range.
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

You can specify a checksum to validate the downloaded executable. Checksums up to the default version
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions __tests__/fixtures/pyproject-dependency-dev-project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def hello() -> str:
return "Hello from python-project!"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")
2 changes: 1 addition & 1 deletion __tests__/fixtures/python-project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"ruff>=0.6.2",
"ruff==0.6.2",
]

[build-system]
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ inputs:
required: false
default: ${{ github.workspace }}
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
default: "latest"
checksum:
description: "The checksum of the ruff version to install"
required: false
Expand Down
Loading

0 comments on commit 7a82f1f

Please sign in to comment.