mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-08-08 10:17:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||||
@@ -5,12 +5,12 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- '.github/workflows/**'
|
- '.github/workflows/**'
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- '.github/workflows/**'
|
- '.github/workflows/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
actionlint:
|
actionlint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: reviewdog/action-actionlint@v1
|
- uses: reviewdog/action-actionlint@v1
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: CheckPython
|
name: Python
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
@@ -6,7 +6,11 @@ jobs:
|
|||||||
clean-python:
|
clean-python:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: psf/black@stable
|
- uses: chartboost/ruff-action@v1
|
||||||
- uses: chartboost/ruff-action@v0
|
with:
|
||||||
- uses: jakebailey/pyright-action@v1
|
args: 'check'
|
||||||
|
- uses: chartboost/ruff-action@v1
|
||||||
|
with:
|
||||||
|
args: 'format --check'
|
||||||
|
- uses: jakebailey/pyright-action@v2
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
issues: read
|
issues: read
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v7
|
- uses: actions/stale@v9
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
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."
|
stale-pr-message: "This pull request has been marked as stale. It will be closed in 14 days if no further activity occurs."
|
||||||
close-pr-message: "This pull request has been closed due to lack of activity."
|
close-pr-message: "This pull request has been closed due to lack of activity."
|
||||||
days-before-pr-stale: ${{ env.PR_STALE_DAYS }}
|
days-before-pr-stale: ${{ env.PR_STALE_DAYS }}
|
||||||
days-before-pr-close: ${{ env.PR_CLOSE_DAYS }}
|
days-before-pr-close: ${{ env.PR_CLOSE_DAYS }}
|
||||||
delete-branch: true
|
delete-branch: true
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.4.0
|
rev: v4.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- repo: https://github.com/rhysd/actionlint
|
- repo: https://github.com/rhysd/actionlint
|
||||||
rev: v1.6.23
|
rev: v1.6.26
|
||||||
hooks:
|
hooks:
|
||||||
- id: actionlint
|
- id: actionlint
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.3.0
|
rev: 24.1.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 'v0.0.260'
|
rev: 'v0.2.1'
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
- repo: https://github.com/RobertCraigie/pyright-python
|
- repo: https://github.com/RobertCraigie/pyright-python
|
||||||
rev: v1.1.301
|
rev: v1.1.350
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyright
|
- id: pyright
|
||||||
|
|||||||
@@ -1,2 +1,96 @@
|
|||||||
# ruff-action
|
# 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: chartboost/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: chartboost/ruff-action@v1
|
||||||
|
with:
|
||||||
|
version: 0.2.2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Specify a different source directory
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: chartboost/ruff-action@v1
|
||||||
|
with:
|
||||||
|
src: "./src"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use `ruff format`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: chartboost/ruff-action@v1
|
||||||
|
with:
|
||||||
|
args: "format --check"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Only run ruff on changed files
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: chartboost/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"
|
name: "ruff-action"
|
||||||
description: "A GH Action of Ruff, the extremely fast Python linter."
|
description: "A GitHub Action to run Ruff, an extremely fast Python linter and code formatter."
|
||||||
author: "Austin Bennett and the Ruff Community"
|
author: "astral-sh"
|
||||||
inputs:
|
inputs:
|
||||||
args:
|
args:
|
||||||
description:
|
description: "Arguments passed to Ruff. Use `ruff --help` to see available options. Defaults to `check`."
|
||||||
"Arguments passed to Ruff. Use `ruff --help` to see available options.
|
|
||||||
Default: 'check'"
|
|
||||||
required: false
|
required: false
|
||||||
default: "check"
|
default: "check"
|
||||||
src:
|
src:
|
||||||
description: "Source to run ruff. Default: '.'"
|
description: "Source to run Ruff. Defaults to the current directory."
|
||||||
required: false
|
required: false
|
||||||
default: "."
|
default: "."
|
||||||
version:
|
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
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
|
changed-files:
|
||||||
|
description: 'Whether to only run Ruff on changed files. Defaults to `false`.'
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
branding:
|
branding:
|
||||||
color: "black"
|
color: "black"
|
||||||
icon: "code"
|
icon: "code"
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
|
- name: Get changed files
|
||||||
|
id: changed-files
|
||||||
|
if: ${{ inputs.changed-files == 'true' }}
|
||||||
|
uses: tj-actions/changed-files@v45
|
||||||
|
with:
|
||||||
|
files: '**.py'
|
||||||
- run: |
|
- run: |
|
||||||
if [ "$RUNNER_OS" == "Windows" ]; then
|
if [ "$RUNNER_OS" == "Windows" ]; then
|
||||||
python $GITHUB_ACTION_PATH/action/main.py
|
python $GITHUB_ACTION_PATH/action/main.py
|
||||||
@@ -29,9 +37,11 @@ runs:
|
|||||||
python3 $GITHUB_ACTION_PATH/action/main.py
|
python3 $GITHUB_ACTION_PATH/action/main.py
|
||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
RUFF_FORMAT: github
|
RUFF_OUTPUT_FORMAT: github
|
||||||
INPUT_ARGS: ${{ inputs.args }}
|
INPUT_ARGS: ${{ inputs.args }}
|
||||||
INPUT_SRC: ${{ inputs.src }}
|
INPUT_SRC: ${{ inputs.src }}
|
||||||
INPUT_VERSION: ${{ inputs.version }}
|
INPUT_VERSION: ${{ inputs.version }}
|
||||||
|
IS_CHANGED_FILES_ENABLED: ${{ inputs.changed-files }}
|
||||||
|
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||||
pythonioencoding: utf-8
|
pythonioencoding: utf-8
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
+12
-1
@@ -1,4 +1,5 @@
|
|||||||
"""GitHub Action for Ruff."""
|
"""GitHub Action for Ruff."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
@@ -10,6 +11,8 @@ ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
|
|||||||
ARGS = os.getenv("INPUT_ARGS", default="")
|
ARGS = os.getenv("INPUT_ARGS", default="")
|
||||||
SRC = os.getenv("INPUT_SRC", default="")
|
SRC = os.getenv("INPUT_SRC", default="")
|
||||||
VERSION = os.getenv("INPUT_VERSION", 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 = ""
|
version_specifier = ""
|
||||||
if VERSION != "":
|
if VERSION != "":
|
||||||
@@ -20,6 +23,14 @@ if VERSION != "":
|
|||||||
|
|
||||||
req = f"ruff{version_specifier}"
|
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)
|
sys.exit(proc.returncode)
|
||||||
|
|||||||
+5
-41
@@ -1,46 +1,10 @@
|
|||||||
[tool.ruff]
|
[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"
|
target-version = "py311"
|
||||||
|
|
||||||
[tool.ruff.mccabe]
|
[tool.ruff.lint]
|
||||||
# Unlike Flake8, default to a complexity level of 10.
|
extend-select = ["B", "UP"]
|
||||||
max-complexity = 10
|
fixable = ["I", "RUF100"]
|
||||||
|
unfixable = []
|
||||||
|
|
||||||
[tool.pyright]
|
[tool.pyright]
|
||||||
typeCheckingMode = "lazy"
|
typeCheckingMode = "lazy"
|
||||||
@@ -51,4 +15,4 @@ reportMissingTypeStubs = false
|
|||||||
reportInvalidStringEscapeSequence = false
|
reportInvalidStringEscapeSequence = false
|
||||||
|
|
||||||
pythonVersion = "3.11"
|
pythonVersion = "3.11"
|
||||||
pythonPlatform = "Linux"
|
pythonPlatform = "Linux"
|
||||||
|
|||||||
Reference in New Issue
Block a user