Skip to content

Commit

Permalink
support ruff mode Argument
Browse files Browse the repository at this point in the history
Users can now specify the mode of ruff to be 'check' or 'format' using the mode input.
  • Loading branch information
yosmoc committed Mar 12, 2024
1 parent 42fd10b commit 17a2e52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ can be included as a step in any other workflow file.
The Ruff action can be customized via optional configuration parameters passed to Ruff (using `with:`):

- version: Must be a Ruff release available on PyPI. By default, latest release of Ruff. You can pin a version, or use any valid version specifier.
- args: default, `check`
- mode: 'check' or 'format', default, 'check'
- args: default, ''
- src: default, '.'

```yaml
- uses: chartboost/ruff-action@v1
with:
src: "./src"
mode: "check"
version: 0.2.2
args: --select B
```
Expand Down
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ name: "Ruff GH Action"
description: "A GH Action of Ruff, the extremely fast Python linter."
author: "The Ruff Community"
inputs:
mode:
description:
"Specify ruff mode 'check' or 'format'"
required: false
default: "check"
args:
description:
"Arguments passed to Ruff. Use `ruff --help` to see available options.
Default: 'check'"
Default: ''"
required: false
default: "check"
default: ""
src:
description: "Source to run ruff. Default: '.'"
required: false
Expand All @@ -30,6 +35,7 @@ runs:
fi
env:
RUFF_OUTPUT_FORMAT: github
INPUT_MODE: ${{ inputs.mode }}
INPUT_ARGS: ${{ inputs.args }}
INPUT_SRC: ${{ inputs.src }}
INPUT_VERSION: ${{ inputs.version }}
Expand Down
17 changes: 16 additions & 1 deletion action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
ARGS = os.getenv("INPUT_ARGS", default="")
MODE = os.getenv("INPUT_MODE", default="")
SRC = os.getenv("INPUT_SRC", default="")
VERSION = os.getenv("INPUT_VERSION", default="")

Expand All @@ -21,6 +22,20 @@

req = f"ruff{version_specifier}"

proc = run(["pipx", "run", req, *shlex.split(ARGS), *shlex.split(SRC)])
command = (
["pipx", "run", req, MODE, *shlex.split(ARGS), *shlex.split(SRC)]
if MODE == "check"
else [
"pipx",
"run",
req,
MODE,
"--check",
*shlex.split(ARGS),
*shlex.split(SRC),
]
)

proc = run(command)

sys.exit(proc.returncode)

0 comments on commit 17a2e52

Please sign in to comment.