mirror of https://github.com/astral-sh/ruff
Use the correct base commit for change determination (#16857)
`base.sha` appears to be the commit of the base branch when the pull request was opened, not the base commit that's used to construct the test merge commit — which can lead to incorrect "determine changes" results where commits made to the base ref since the pull request are opened are included in the results. We use `git merge-base` to find the correct sha, as I don't think that GitHub provides this. They provide `merge_commit_sha` but my understanding is that is equivalent to the actual merge commit we're testing in CI. I tested this locally on an example pull request. I don't think it's worth trying to reproduce a specific situation here. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
parent
47c4ccff5d
commit
9d72685f8d
|
|
@ -45,10 +45,20 @@ jobs:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Determine merge base
|
||||||
|
id: merge_base
|
||||||
|
env:
|
||||||
|
BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }}
|
||||||
|
run: |
|
||||||
|
sha=$(git merge-base HEAD "origin/${BASE_REF}")
|
||||||
|
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Check if the parser code changed
|
- name: Check if the parser code changed
|
||||||
id: check_parser
|
id: check_parser
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
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
|
if git diff --quiet "${MERGE_BASE}...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
|
||||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
@ -56,8 +66,10 @@ jobs:
|
||||||
|
|
||||||
- name: Check if the linter code changed
|
- name: Check if the linter code changed
|
||||||
id: check_linter
|
id: check_linter
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
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
|
if git diff --quiet "${MERGE_BASE}...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"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
@ -65,8 +77,10 @@ jobs:
|
||||||
|
|
||||||
- name: Check if the formatter code changed
|
- name: Check if the formatter code changed
|
||||||
id: check_formatter
|
id: check_formatter
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
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
|
if git diff --quiet "${MERGE_BASE}...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"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
@ -74,8 +88,10 @@ jobs:
|
||||||
|
|
||||||
- name: Check if the fuzzer code changed
|
- name: Check if the fuzzer code changed
|
||||||
id: check_fuzzer
|
id: check_fuzzer
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
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
|
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':Cargo.toml' ':Cargo.lock' ':fuzz/fuzz_targets/**' ':.github/workflows/ci.yaml'; then
|
||||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
@ -83,8 +99,10 @@ jobs:
|
||||||
|
|
||||||
- name: Check if there was any code related change
|
- name: Check if there was any code related change
|
||||||
id: check_code
|
id: check_code
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
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
|
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':**/*' ':!**/*.md' ':crates/red_knot_python_semantic/resources/mdtest/**/*.md' ':!docs/**' ':!assets/**' ':.github/workflows/ci.yaml'; then
|
||||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
@ -92,8 +110,10 @@ jobs:
|
||||||
|
|
||||||
- name: Check if there was any playground related change
|
- name: Check if there was any playground related change
|
||||||
id: check_playground
|
id: check_playground
|
||||||
|
env:
|
||||||
|
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
|
||||||
run: |
|
run: |
|
||||||
if git diff --quiet ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD -- ':playground/**'; then
|
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':playground/**'; then
|
||||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue