Skip to content

Commit

Permalink
Fix changed-files for cases where no python files changed (#4)
Browse files Browse the repository at this point in the history
## Problem
When a PR contains no changed python files, but changed-files is set to
true, ruff will run on all files, including ones not changed.

## Solution
Pass the input through to the script and short circuit to success in
cases where both the flag is set and no python files were changed.
  • Loading branch information
DavidJFelix authored Sep 30, 2024
1 parent 701f39c commit 61703ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ runs:
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
6 changes: 6 additions & 0 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 != "":
Expand All @@ -25,6 +26,11 @@
# 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)

0 comments on commit 61703ed

Please sign in to comment.