GitHub Actions has everything you need to run Ruff out-of-the-box:
Ruff can also be used as a GitHub Action via ruff-action.
By default, ruff-action runs as a pass-fail test to ensure that a given repository doesn't contain any lint rule violations as per its configuration. However, under-the-hood, ruff-action installs and runs ruff directly, so it can be used to execute any supported ruff command (e.g., ruff check --fix).
ruff-action supports all GitHub-hosted runners, and can be used with any published Ruff version (i.e., any version available on PyPI).
To use ruff-action, create a file (e.g., .github/workflows/ruff.yml) inside your repository with:
Alternatively, you can include ruff-action as a step in any other workflow file:
ruff-action accepts optional configuration parameters via with:, including:
For example, to run ruff check --select B ./src using Ruff version 0.8.0:
You can add the following configuration to .gitlab-ci.yml to run a ruff format in parallel with a ruff check compatible with GitLab's codequality report.
Ruff can be used as a pre-commit hook via ruff-pre-commit:
To enable lint fixes, add the --fix argument to the lint hook:
To avoid running on Jupyter Notebooks, remove jupyter from the list of allowed filetypes:
When running with --fix, Ruff's lint hook should be placed before Ruff's formatter hook, and before Black, isort, and other formatting tools, as Ruff's fix behavior can output code changes that require reformatting.
When running without --fix, Ruff's formatter hook can be placed before or after Ruff's lint hook.
(As long as your Ruff configuration avoids any linter-formatter incompatibilities, ruff format should never introduce new lint errors, so it's safe to run Ruff's format hook after ruff check --fix.)
mdformat is capable of formatting code blocks within Markdown. The mdformat-ruff plugin enables mdformat to format Python code blocks with Ruff.
Ruff provides a distroless Docker image including the ruff binary. The following tags are published:
In addition, ruff publishes the following images:
As with the distroless image, each image is published with ruff version tags as ruff:{major}.{minor}.{patch}-{base} and ruff:{major}.{minor}-{base}, e.g., ruff:0.6.6-alpine.