Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 49 additions & 57 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,66 @@ jobs:
runs-on: ubuntu-latest
outputs:
# 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
linter: "true"
linter: ${{ steps.check_linter.outputs.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
# 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
fuzz: "true"
fuzz: ${{ steps.check_fuzzer.outputs.changed }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
persist-credentials: false

# TODO: Replace with plain git command?
# files_yaml: |
# parser:
# - 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
#
# linter:
# - Cargo.toml
# - Cargo.lock
# - crates/**
# - "!crates/red_knot*/**"
# - "!crates/ruff_python_formatter/**"
# - "!crates/ruff_formatter/**"
# - "!crates/ruff_dev/**"
# - scripts/*
# - python/**
# - .github/workflows/ci.yaml
#
# formatter:
# - 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_text_size/**
# - crates/ruff_python_parser/**
# - crates/ruff_dev/**
# - scripts/*
# - python/**
# - .github/workflows/ci.yaml
#
# fuzz:
# - fuzz/Cargo.toml
# - fuzz/Cargo.lock
# - fuzz/fuzz_targets/**
#
# code:
# - "**/*"
# - "!**/*.md"
# - "crates/red_knot_python_semantic/resources/mdtest/**/*.md"
# - "!docs/**"
# - "!assets/**"
- name: Check if the parser code changed
id: check_parser
run: |
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to put the pathspecs on newlines or in an expanded variable for readability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and did this in #16869

echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Check if the linter code changed
id: check_linter
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
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Check if the formatter code changed
id: check_formatter
run: |
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
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Check if the fuzzer code changed
id: check_fuzzer
run: |
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
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Check if there was any code related change
id: check_code
run: |
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"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

cargo-fmt:
name: "cargo fmt"
Expand Down
Loading