mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-08-08 18:27:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0a0e814ec | ||
|
|
61703ed12e | ||
|
|
701f39cb3f | ||
|
|
ad8ad9ec2e | ||
|
|
beb1d37bb7 | ||
|
|
7e5f451d8a | ||
|
|
e88ca0d813 | ||
|
|
7388145ba9 | ||
|
|
491342200c | ||
|
|
79eabade54 | ||
|
|
0df4a95686 | ||
|
|
a9c46eeb9c | ||
|
|
992901c201 | ||
|
|
47bc0821f5 | ||
|
|
6e7156986b | ||
|
|
88d6702e4e | ||
|
|
e31dbd6695 | ||
|
|
f8abd91ecb | ||
|
|
17a2e52c32 | ||
|
|
38ef108542 | ||
|
|
42fd10b26e | ||
|
|
32ddb6ca80 | ||
|
|
0cf49cc7a3 | ||
|
|
4c93cf060a | ||
|
|
d1154b06e8 | ||
|
|
06460f5390 | ||
|
|
c0661673e2 | ||
|
|
41f0574bbd | ||
|
|
5619897516 | ||
|
|
b22a8e1c0d | ||
|
|
58ed8ddf37 | ||
|
|
a0f145b455 | ||
|
|
98cc4a4345 | ||
|
|
2bc585f125 | ||
|
|
1c2f7b23b4 | ||
|
|
9a777ad092 | ||
|
|
ed9d6e65a4 | ||
|
|
403a32e32b |
@@ -0,0 +1,13 @@
|
||||
# Keep GitHub Actions up to date with GitHub's Dependabot...
|
||||
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
|
||||
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
groups:
|
||||
github-actions:
|
||||
patterns:
|
||||
- "*" # Group all Actions updates into a single larger pull request
|
||||
schedule:
|
||||
interval: weekly
|
||||
@@ -12,5 +12,5 @@ jobs:
|
||||
actionlint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: reviewdog/action-actionlint@v1
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: CheckPython
|
||||
name: Python
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
@@ -6,7 +6,11 @@ jobs:
|
||||
clean-python:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: psf/black@stable
|
||||
- uses: chartboost/ruff-action@v0
|
||||
- uses: jakebailey/pyright-action@v1
|
||||
- uses: actions/checkout@v4
|
||||
- uses: chartboost/ruff-action@v1
|
||||
with:
|
||||
args: 'check'
|
||||
- uses: chartboost/ruff-action@v1
|
||||
with:
|
||||
args: 'format --check'
|
||||
- uses: jakebailey/pyright-action@v2
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
issues: read
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/stale@v7
|
||||
- uses: actions/stale@v9
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-pr-message: "This pull request has been marked as stale. It will be closed in 14 days if no further activity occurs."
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v4.5.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/rhysd/actionlint
|
||||
rev: v1.6.23
|
||||
rev: v1.6.26
|
||||
hooks:
|
||||
- id: actionlint
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.3.0
|
||||
rev: 24.1.1
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
rev: 'v0.0.260'
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: 'v0.2.1'
|
||||
hooks:
|
||||
- id: ruff
|
||||
- repo: https://github.com/RobertCraigie/pyright-python
|
||||
rev: v1.1.301
|
||||
rev: v1.1.350
|
||||
hooks:
|
||||
- id: pyright
|
||||
@@ -1,2 +1,96 @@
|
||||
# ruff-action
|
||||
A GitHub Action for Ruff
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> This Action is a fork of
|
||||
> [chartboost/ruff-action](https://github.com/ChartBoost/ruff-action), which is
|
||||
> no longer maintained. The Action is largely unchanged, but will be overhauled
|
||||
> in a future major release.
|
||||
|
||||
A [GitHub Action](https://github.com/features/actions) to run
|
||||
[Ruff](https://github.com/astral-sh/ruff).
|
||||
|
||||
This action is commonly used as a pass/fail test to ensure your repository stays
|
||||
clean, abiding the [Rules](https://docs.astral.sh/ruff/rules/) specified in your
|
||||
configuration. Though it runs `ruff`, the action can do anything `ruff` can (ex,
|
||||
fix).
|
||||
|
||||
## Compatibility
|
||||
|
||||
This action is known to support all GitHub-hosted runner OSes. It likely can run
|
||||
on self-hosted runners, but might need specific dependencies. Only published
|
||||
versions of Ruff are supported (i.e., whatever is available on
|
||||
[PyPI](https://pypi.org/project/ruff/)).
|
||||
|
||||
## Basic Usage
|
||||
|
||||
Create a file (ex: `.github/workflows/ruff.yml`) inside your repository with:
|
||||
|
||||
```yaml
|
||||
name: Ruff
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
ruff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: astral-sh/ruff-action@v1
|
||||
```
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
The Ruff action can be customized via optional configuration parameters passed
|
||||
to Ruff (using `with:`):
|
||||
|
||||
- `version`: Must be a Ruff release available on
|
||||
[PyPI](https://pypi.org/project/ruff/). Defaults to the latest Ruff release.
|
||||
You can pin a version, or use any valid version specifier.
|
||||
- `args`: The arguments to pass to the `ruff` command. Defaults to `check`,
|
||||
which lints the current directory.
|
||||
- `src`: The directory to run `ruff` in. Defaults to the root of the repository.
|
||||
|
||||
See
|
||||
[Configuring Ruff](https://github.com/astral-sh/ruff/blob/main/docs/configuration.md)
|
||||
for details
|
||||
|
||||
### Use a different ruff version
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/ruff-action@v1
|
||||
with:
|
||||
version: 0.2.2
|
||||
```
|
||||
|
||||
### Specify a different source directory
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/ruff-action@v1
|
||||
with:
|
||||
src: "./src"
|
||||
```
|
||||
|
||||
### Use `ruff format`
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/ruff-action@v1
|
||||
with:
|
||||
args: "format --check"
|
||||
```
|
||||
|
||||
### Only run ruff on changed files
|
||||
|
||||
```yaml
|
||||
- uses: astral-sh/ruff-action@v1
|
||||
with:
|
||||
changed-files: "true"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Apache
|
||||
|
||||
<div align="center">
|
||||
<a target="_blank" href="https://astral.sh" style="background:none">
|
||||
<img src="https://raw.githubusercontent.com/astral-sh/uv/main/assets/svg/Astral.svg" alt="Made by Astral">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
+19
-9
@@ -1,27 +1,35 @@
|
||||
name: "Ruff GH Action"
|
||||
description: "A GH Action of Ruff, the extremely fast Python linter."
|
||||
author: "Austin Bennett and the Ruff Community"
|
||||
name: "ruff-action"
|
||||
description: "A GitHub Action to run Ruff, an extremely fast Python linter and code formatter."
|
||||
author: "astral-sh"
|
||||
inputs:
|
||||
args:
|
||||
description:
|
||||
"Arguments passed to Ruff. Use `ruff --help` to see available options.
|
||||
Default: 'check'"
|
||||
description: "Arguments passed to Ruff. Use `ruff --help` to see available options. Defaults to `check`."
|
||||
required: false
|
||||
default: "check"
|
||||
src:
|
||||
description: "Source to run ruff. Default: '.'"
|
||||
description: "Source to run Ruff. Defaults to the current directory."
|
||||
required: false
|
||||
default: "."
|
||||
version:
|
||||
description: 'The version of ruff to use, e.g. "0.0.259"'
|
||||
description: 'The version of Ruff to use, e.g., `0.6.0` Defaults to the latest version.'
|
||||
required: false
|
||||
default: ""
|
||||
changed-files:
|
||||
description: 'Whether to only run Ruff on changed files. Defaults to `false`.'
|
||||
required: false
|
||||
default: "false"
|
||||
branding:
|
||||
color: "black"
|
||||
icon: "code"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
if: ${{ inputs.changed-files == 'true' }}
|
||||
uses: tj-actions/changed-files@v45
|
||||
with:
|
||||
files: '**.py'
|
||||
- run: |
|
||||
if [ "$RUNNER_OS" == "Windows" ]; then
|
||||
python $GITHUB_ACTION_PATH/action/main.py
|
||||
@@ -29,9 +37,11 @@ runs:
|
||||
python3 $GITHUB_ACTION_PATH/action/main.py
|
||||
fi
|
||||
env:
|
||||
RUFF_FORMAT: github
|
||||
RUFF_OUTPUT_FORMAT: github
|
||||
INPUT_ARGS: ${{ inputs.args }}
|
||||
INPUT_SRC: ${{ inputs.src }}
|
||||
INPUT_VERSION: ${{ inputs.version }}
|
||||
IS_CHANGED_FILES_ENABLED: ${{ inputs.changed-files }}
|
||||
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||
pythonioencoding: utf-8
|
||||
shell: bash
|
||||
|
||||
+12
-1
@@ -1,4 +1,5 @@
|
||||
"""GitHub Action for Ruff."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
@@ -10,6 +11,8 @@ ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
|
||||
ARGS = os.getenv("INPUT_ARGS", default="")
|
||||
SRC = os.getenv("INPUT_SRC", default="")
|
||||
VERSION = os.getenv("INPUT_VERSION", default="")
|
||||
CHANGED_FILES = os.getenv("CHANGED_FILES", "")
|
||||
IS_CHANGED_FILES_ENABLED = os.getenv("IS_CHANGED_FILES_ENABLED", default="false")
|
||||
|
||||
version_specifier = ""
|
||||
if VERSION != "":
|
||||
@@ -20,6 +23,14 @@ if VERSION != "":
|
||||
|
||||
req = f"ruff{version_specifier}"
|
||||
|
||||
proc = run(["pipx", "run", req, *shlex.split(ARGS), *shlex.split(SRC)])
|
||||
# If `CHANGED_FILES` is not empty, split it into a list; otherwise, use `SRC`.
|
||||
files_to_check = shlex.split(CHANGED_FILES or SRC)
|
||||
|
||||
# If IS_CHANGED_FILES_ENABLED is true and CHANGED_FILES was empty, there were no files to check
|
||||
# Short circuit to prevent ruff from running on all files because it got no file argument
|
||||
if IS_CHANGED_FILES_ENABLED == "true" and not CHANGED_FILES:
|
||||
sys.exit(0)
|
||||
|
||||
proc = run(["pipx", "run", req, *shlex.split(ARGS), *files_to_check])
|
||||
|
||||
sys.exit(proc.returncode)
|
||||
|
||||
+4
-40
@@ -1,46 +1,10 @@
|
||||
[tool.ruff]
|
||||
|
||||
select = ["A", "ANN", "B", "C90", "D", "E", "F", "I", "N", "COM", "DTZ", "PD", "RUF", "TID", "UP", "W"]
|
||||
ignore = ["D203", "D212"]
|
||||
|
||||
fixable = ["I", "RUF100"]
|
||||
unfixable = []
|
||||
|
||||
# Exclude a variety of commonly ignored directories.
|
||||
exclude = [
|
||||
".bzr",
|
||||
".direnv",
|
||||
".eggs",
|
||||
".git",
|
||||
".hg",
|
||||
".mypy_cache",
|
||||
".nox",
|
||||
".pants.d",
|
||||
".pytype",
|
||||
".ruff_cache",
|
||||
".svn",
|
||||
".tox",
|
||||
".venv",
|
||||
"__pypackages__",
|
||||
"_build",
|
||||
"buck-out",
|
||||
"build",
|
||||
"dist",
|
||||
"node_modules",
|
||||
"venv",
|
||||
]
|
||||
|
||||
line-length = 88
|
||||
|
||||
# Allow unused variables when underscore-prefixed.
|
||||
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||
|
||||
target-version = "py311"
|
||||
|
||||
[tool.ruff.mccabe]
|
||||
# Unlike Flake8, default to a complexity level of 10.
|
||||
max-complexity = 10
|
||||
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["B", "UP"]
|
||||
fixable = ["I", "RUF100"]
|
||||
unfixable = []
|
||||
|
||||
[tool.pyright]
|
||||
typeCheckingMode = "lazy"
|
||||
|
||||
Reference in New Issue
Block a user