Skip to content

Commit 93ca4a9

Browse files
authored
[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](#16800): See how the fuzzer and formatter steps, and the linter ecosystem checks are skipped * [Formatter only change](#16799): See how the fuzzer and linter ecosystem checks are skipped
1 parent 38bfda9 commit 93ca4a9

File tree

1 file changed

+49
-57
lines changed

1 file changed

+49
-57
lines changed

.github/workflows/ci.yaml

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,66 @@ jobs:
2626
runs-on: ubuntu-latest
2727
outputs:
2828
# Flag that is raised when any code that affects parser is changed
29-
parser: "true"
29+
parser: ${{ steps.check_parser.outputs.changed }}
3030
# Flag that is raised when any code that affects linter is changed
31-
linter: "true"
31+
linter: ${{ steps.check_linter.outputs.changed }}
3232
# Flag that is raised when any code that affects formatter is changed
33-
formatter: "true"
33+
formatter: ${{ steps.check_formatter.outputs.changed }}
3434
# Flag that is raised when any code is changed
3535
# This is superset of the linter and formatter
36-
code: "true"
36+
code: ${{ steps.check_code.outputs.changed }}
3737
# Flag that is raised when any code that affects the fuzzer is changed
38-
fuzz: "true"
38+
fuzz: ${{ steps.check_fuzzer.outputs.changed }}
3939
steps:
4040
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
4141
with:
4242
fetch-depth: 0
4343
persist-credentials: false
4444

45-
# TODO: Replace with plain git command?
46-
# files_yaml: |
47-
# parser:
48-
# - Cargo.toml
49-
# - Cargo.lock
50-
# - crates/ruff_python_trivia/**
51-
# - crates/ruff_source_file/**
52-
# - crates/ruff_text_size/**
53-
# - crates/ruff_python_ast/**
54-
# - crates/ruff_python_parser/**
55-
# - python/py-fuzzer/**
56-
# - .github/workflows/ci.yaml
57-
#
58-
# linter:
59-
# - Cargo.toml
60-
# - Cargo.lock
61-
# - crates/**
62-
# - "!crates/red_knot*/**"
63-
# - "!crates/ruff_python_formatter/**"
64-
# - "!crates/ruff_formatter/**"
65-
# - "!crates/ruff_dev/**"
66-
# - scripts/*
67-
# - python/**
68-
# - .github/workflows/ci.yaml
69-
#
70-
# formatter:
71-
# - Cargo.toml
72-
# - Cargo.lock
73-
# - crates/ruff_python_formatter/**
74-
# - crates/ruff_formatter/**
75-
# - crates/ruff_python_trivia/**
76-
# - crates/ruff_python_ast/**
77-
# - crates/ruff_source_file/**
78-
# - crates/ruff_python_index/**
79-
# - crates/ruff_text_size/**
80-
# - crates/ruff_python_parser/**
81-
# - crates/ruff_dev/**
82-
# - scripts/*
83-
# - python/**
84-
# - .github/workflows/ci.yaml
85-
#
86-
# fuzz:
87-
# - fuzz/Cargo.toml
88-
# - fuzz/Cargo.lock
89-
# - fuzz/fuzz_targets/**
90-
#
91-
# code:
92-
# - "**/*"
93-
# - "!**/*.md"
94-
# - "crates/red_knot_python_semantic/resources/mdtest/**/*.md"
95-
# - "!docs/**"
96-
# - "!assets/**"
45+
- name: Check if the parser code changed
46+
id: check_parser
47+
run: |
48+
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
49+
echo "changed=false" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "changed=true" >> "$GITHUB_OUTPUT"
52+
fi
53+
54+
- name: Check if the linter code changed
55+
id: check_linter
56+
run: |
57+
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
58+
echo "changed=false" >> "$GITHUB_OUTPUT"
59+
else
60+
echo "changed=true" >> "$GITHUB_OUTPUT"
61+
fi
62+
63+
- name: Check if the formatter code changed
64+
id: check_formatter
65+
run: |
66+
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
67+
echo "changed=false" >> "$GITHUB_OUTPUT"
68+
else
69+
echo "changed=true" >> "$GITHUB_OUTPUT"
70+
fi
71+
72+
- name: Check if the fuzzer code changed
73+
id: check_fuzzer
74+
run: |
75+
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
76+
echo "changed=false" >> "$GITHUB_OUTPUT"
77+
else
78+
echo "changed=true" >> "$GITHUB_OUTPUT"
79+
fi
80+
81+
- name: Check if there was any code related change
82+
id: check_code
83+
run: |
84+
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
85+
echo "changed=false" >> "$GITHUB_OUTPUT"
86+
else
87+
echo "changed=true" >> "$GITHUB_OUTPUT"
88+
fi
9789
9890
cargo-fmt:
9991
name: "cargo fmt"

0 commit comments

Comments
 (0)