[ci] Use `git diff` instead of `changed-files` GH action (#16796)

## Summary

Use bash and `git diff` to determine which steps need to run. 

We previously used the `changed-files` github actions but using `git`
directly seems simple enough.

All credit for the bash magic goes to @zanieb and @geofft. All I did was
replace the paths arguments.


## Test Plan

* [Linter only change](https://github.com/astral-sh/ruff/pull/16800):
See how the fuzzer and formatter steps, and the linter ecosystem checks
are skipped
* [Formatter only change](https://github.com/astral-sh/ruff/pull/16799):
See how the fuzzer and linter ecosystem checks are skipped
This commit is contained in:
Micha Reiser 2025-03-17 12:40:34 +01:00 committed by GitHub
parent 38bfda94ce
commit 93ca4a96e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 49 additions and 57 deletions

View File

@ -26,74 +26,66 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
# Flag that is raised when any code that affects parser is changed # Flag that is raised when any code that affects parser is changed
parser: "true" parser: ${{ steps.check_parser.outputs.changed }}
# Flag that is raised when any code that affects linter is changed # Flag that is raised when any code that affects linter is changed
linter: "true" linter: ${{ steps.check_linter.outputs.changed }}
# Flag that is raised when any code that affects formatter is changed # Flag that is raised when any code that affects formatter is changed
formatter: "true" formatter: ${{ steps.check_formatter.outputs.changed }}
# Flag that is raised when any code is changed # Flag that is raised when any code is changed
# This is superset of the linter and formatter # This is superset of the linter and formatter
code: "true" code: ${{ steps.check_code.outputs.changed }}
# Flag that is raised when any code that affects the fuzzer is changed # Flag that is raised when any code that affects the fuzzer is changed
fuzz: "true" fuzz: ${{ steps.check_fuzzer.outputs.changed }}
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with: with:
fetch-depth: 0 fetch-depth: 0
persist-credentials: false persist-credentials: false
# TODO: Replace with plain git command? - name: Check if the parser code changed
# files_yaml: | id: check_parser
# parser: run: |
# - Cargo.toml if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':Cargo.toml' ':Cargo.lock' ':crates/ruff_python_trivia/**' ':crates/ruff_source_file/**' ':crates/ruff_text_size/**' ':crates/ruff_python_ast/**' ':crates/ruff_python_parser/**' ':python/py-fuzzer/**' ':.github/workflows/ci.yaml'; then
# - Cargo.lock echo "changed=false" >> "$GITHUB_OUTPUT"
# - crates/ruff_python_trivia/** else
# - crates/ruff_source_file/** echo "changed=true" >> "$GITHUB_OUTPUT"
# - crates/ruff_text_size/** fi
# - crates/ruff_python_ast/**
# - crates/ruff_python_parser/** - name: Check if the linter code changed
# - python/py-fuzzer/** id: check_linter
# - .github/workflows/ci.yaml run: |
# if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':Cargo.toml' ':Cargo.lock' ':crates/**' ':!crates/red_knot*/**' ':!crates/ruff_python_formatter/**' ':!crates/ruff_formatter/**' ':!crates/ruff_dev/**' ':!crates/ruff_db/**' ':scripts/*' ':python/**' ':.github/workflows/ci.yaml'; then
# linter: echo "changed=false" >> "$GITHUB_OUTPUT"
# - Cargo.toml else
# - Cargo.lock echo "changed=true" >> "$GITHUB_OUTPUT"
# - crates/** fi
# - "!crates/red_knot*/**"
# - "!crates/ruff_python_formatter/**" - name: Check if the formatter code changed
# - "!crates/ruff_formatter/**" id: check_formatter
# - "!crates/ruff_dev/**" run: |
# - scripts/* if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':Cargo.toml' ':Cargo.lock' ':crates/ruff_python_formatter/**' ':crates/ruff_formatter/**' ':crates/ruff_python_trivia/**' ':crates/ruff_python_ast/**' ':crates/ruff_source_file/**' ':crates/ruff_python_index/**' ':crates/ruff_python_index/**' ':crates/ruff_text_size/**' ':crates/ruff_python_parser/**' ':scripts/*' ':python/**' ':.github/workflows/ci.yaml'; then
# - python/** echo "changed=false" >> "$GITHUB_OUTPUT"
# - .github/workflows/ci.yaml else
# echo "changed=true" >> "$GITHUB_OUTPUT"
# formatter: fi
# - Cargo.toml
# - Cargo.lock - name: Check if the fuzzer code changed
# - crates/ruff_python_formatter/** id: check_fuzzer
# - crates/ruff_formatter/** run: |
# - crates/ruff_python_trivia/** if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':Cargo.toml' ':Cargo.lock' ':fuzz/fuzz_targets/**' ':.github/workflows/ci.yaml'; then
# - crates/ruff_python_ast/** echo "changed=false" >> "$GITHUB_OUTPUT"
# - crates/ruff_source_file/** else
# - crates/ruff_python_index/** echo "changed=true" >> "$GITHUB_OUTPUT"
# - crates/ruff_text_size/** fi
# - crates/ruff_python_parser/**
# - crates/ruff_dev/** - name: Check if there was any code related change
# - scripts/* id: check_code
# - python/** run: |
# - .github/workflows/ci.yaml if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':**/*' ':!**/*.md' ':crates/red_knot_python_semantic/resources/mdtest/**/*.md' ':!docs/**' ':!assets/**' ':.github/workflows/ci.yaml'; then
# echo "changed=false" >> "$GITHUB_OUTPUT"
# fuzz: else
# - fuzz/Cargo.toml echo "changed=true" >> "$GITHUB_OUTPUT"
# - fuzz/Cargo.lock fi
# - fuzz/fuzz_targets/**
#
# code:
# - "**/*"
# - "!**/*.md"
# - "crates/red_knot_python_semantic/resources/mdtest/**/*.md"
# - "!docs/**"
# - "!assets/**"
cargo-fmt: cargo-fmt:
name: "cargo fmt" name: "cargo fmt"