Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from ma-sadeghi/feature/changed-only
Browse files Browse the repository at this point in the history
Provide support to lint/format changed files only
  • Loading branch information
ffernandez92 authored May 30, 2024
2 parents 47bc082 + 79eabad commit 4913422
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ See [Configuring Ruff](https://github.com/astral-sh/ruff/blob/main/docs/configur
with:
args: 'format --check'
```

### Only run ruff on changed files
```yaml
- uses: chartboost/ruff-action@v1
with:
changed-files: 'true'
```
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ inputs:
description: 'The version of ruff to use, e.g. "0.0.259"'
required: false
default: ""
changed-files:
description: 'Whether to only run ruff on changed files. Default: 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@v44
with:
files: '**.py'
- run: |
if [ "$RUNNER_OS" == "Windows" ]; then
python $GITHUB_ACTION_PATH/action/main.py
Expand All @@ -33,5 +43,6 @@ runs:
INPUT_ARGS: ${{ inputs.args }}
INPUT_SRC: ${{ inputs.src }}
INPUT_VERSION: ${{ inputs.version }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
pythonioencoding: utf-8
shell: bash
6 changes: 5 additions & 1 deletion action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ARGS = os.getenv("INPUT_ARGS", default="")
SRC = os.getenv("INPUT_SRC", default="")
VERSION = os.getenv("INPUT_VERSION", default="")
CHANGED_FILES = os.getenv("CHANGED_FILES", "")

version_specifier = ""
if VERSION != "":
Expand All @@ -21,6 +22,9 @@

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)

proc = run(["pipx", "run", req, *shlex.split(ARGS), *files_to_check])

sys.exit(proc.returncode)

0 comments on commit 4913422

Please sign in to comment.