๐Ÿ“ฆ astral-sh / ruff-action

A GitHub Action to run Ruff

โ˜… 216 stars โ‘‚ 22 forks ๐Ÿ‘ 216 watching โš–๏ธ Apache License 2.0
๐Ÿ“ฅ Clone https://github.com/astral-sh/ruff-action.git
HTTPS git clone https://github.com/astral-sh/ruff-action.git
SSH git clone git@github.com:astral-sh/ruff-action.git
CLI gh repo clone astral-sh/ruff-action
Kevin Stillhammer Kevin Stillhammer ignore environment markers in dep specs (#295) deb6320 4 days ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ __tests__
๐Ÿ“ .github
๐Ÿ“ .vscode
๐Ÿ“ dist
๐Ÿ“ src
๐Ÿ“„ .editorconfig
๐Ÿ“„ .gitattributes
๐Ÿ“„ .gitignore
๐Ÿ“„ action.yml
๐Ÿ“„ biome.json
๐Ÿ“„ CODEOWNERS
๐Ÿ“„ jest.config.js
๐Ÿ“„ LICENSE
๐Ÿ“„ package-lock.json
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

ruff-action

A GitHub Action to run ruff.

This action is commonly used as a pass/fail test to ensure your repository stays clean, abiding the rules specified in your configuration. Though it runs ruff check by default, the action can do anything ruff can (ex, fix).

Contents

Usage

InputDescriptionDefault
versionThe version of Ruff to install. See Install specific versionslatest
version-fileThe file to read the version from. See Install a version from a specified version fileNone
argsThe arguments to pass to the ruff command. See [Configuring Ruff]check
srcThe directory or single files to run ruff on.[github.workspace]
checksumThe sha256 checksum of the downloaded executable.None
github-tokenThe GitHub token to use for authentication.GITHUB_TOKEN

Basic

- uses: astral-sh/ruff-action@v3

Specify a different source directory

- uses: astral-sh/ruff-action@v3
  with:
    src: "./src"

Specify multiple files

- uses: astral-sh/ruff-action@v3
  with:
    src: >-
      path/to/file1.py
      path/to/file2.py

Use to install ruff

This action adds ruff to the PATH, so you can use it in subsequent steps.

- uses: astral-sh/ruff-action@v3
- run: ruff check --fix
- run: ruff format

By default, this action runs ruff check after installation. If you do not want to run any ruff command but only install it, you can use the args input to overwrite the default value (check):

- name: Install ruff without running check or format
  uses: astral-sh/ruff-action@v3
  with:
    args: "--version"

Use ruff format

- uses: astral-sh/ruff-action@v3
  with:
    args: "format --check --diff"

Install specific versions

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 project.dependencies, project.optional-dependencies, or dependency-groups, the latest version is installed.

[!NOTE]
This action does only support ruff versions v0.0.247 and above.

Install the latest version

- name: Install the latest version of ruff
  uses: astral-sh/ruff-action@v3
  with:
    version: "latest"

Install a specific version

- name: Install a specific version of ruff
  uses: astral-sh/ruff-action@v3
  with:
    version: "0.4.4"

Install a version by supplying a semver range or pep440 specifier

You can specify a semver range or pep440 specifier to install the latest version that satisfies the range.

- name: Install a semver range of ruff
  uses: astral-sh/ruff-action@v3
  with:
    version: ">=0.4.0"

- name: Pinning a minor version of ruff
  uses: astral-sh/ruff-action@v3
  with:
    version: "0.4.x"

- name: Install a pep440-specifier-satisfying version of ruff
  uses: astral-sh/ruff-action@v3
  with:
    version: ">=0.11.10,<0.12.0"

Install a version from a specified version file

You can specify a file to read the version from. Currently pyproject.toml and requirements.txt are supported.

- name: Install a version from a specified version file
  uses: astral-sh/ruff-action@v3
  with:
    version-file: "my-path/to/pyproject.toml-or-requirements.txt"

Validate checksum

You can specify a checksum to validate the downloaded executable. Checksums up to the default version are automatically verified by this action. The sha256 hashes can be found on the releases page of the ruff repo.

- name: Install a specific version and validate the checksum
  uses: astral-sh/ruff-action@v3
  with:
    version: "0.7.4"
    checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"

GitHub authentication token

This action uses the GitHub API to fetch the ruff release artifacts. To avoid hitting the GitHub API rate limit too quickly, an authentication token can be provided via the github-token input. By default, the GITHUB_TOKEN secret is used, which is automatically provided by GitHub Actions.

If the default permissions for the GitHub token are not sufficient, you can provide a custom GitHub token with the necessary permissions.

- name: Install the latest version of ruff with a custom GitHub token
  uses: astral-sh/ruff-action@v3
  with:
    github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}

Outputs

OutputDescription
ruff-versionThe version of Ruff that was installed.
Made by Astral