Skip to content

astral-sh/ruff-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

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, the action can do anything ruff can (ex, fix).

Contents

Usage

Input Description Default
version The version of Ruff to install. See 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

Basic

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

Specify a different source directory

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

Specify multiple files

- uses: astral-sh/ruff-action@v2
  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@v2
- run: ruff check --fix
- run: ruff format

Use ruff format

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

Install specific versions

Install the latest version (default)

- name: Install the latest version of ruff
  uses: astral-sh/ruff-action@v2
  with:
    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

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

Install a version by supplying a semver range

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

- name: Install a semver range of ruff
  uses: astral-sh/ruff-action@v2
  with:
    version: ">=0.4.0"
- name: Pinning a minor version of ruff
  uses: astral-sh/ruff-action@v2
  with:
    version: "0.4.x"

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@v2
  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@v2
  with:
    github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}

Outputs

Output Description
ruff-version The version of Ruff that was installed.