Skip to content

fix: return lists from the 2363 Python merge (#5798) #12986

fix: return lists from the 2363 Python merge (#5798)

fix: return lists from the 2363 Python merge (#5798) #12986

Workflow file for this run

name: black-lint
on:
push:
branches: [main]
paths:
- '**/*.py'
- requirements.txt
- .github/workflows/black-lint.yml
- .github/scripts/fetch-diff-base.sh
pull_request:
paths:
- '**/*.py'
- requirements.txt
- .github/workflows/black-lint.yml
- .github/scripts/fetch-diff-base.sh
concurrency:
# Prefer PR number: github.ref can be the base branch and collide with push.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 1
- name: Fetch diff base
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GIT_BEFORE: ${{ github.event.before }}
run: bash .github/scripts/fetch-diff-base.sh
- uses: actions/setup-python@v7
with:
python-version: '3.13'
cache: pip
cache-dependency-path: requirements.txt
- name: Install black
run: |
set -euo pipefail
pin="$(grep '^black==' requirements.txt || true)"
if [ -z "$pin" ]; then
echo "requirements.txt must contain a black== version pin."
exit 1
fi
python -m pip install "$pin"
- name: Check black
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "pull_request" ]; then
mapfile -t files < <(git diff --name-only --diff-filter=ACMR "${{ github.event.pull_request.base.sha }}" -- '*.py' || true)
else
before="${{ github.event.before }}"
if [ -z "$before" ] || [[ "$before" =~ ^0+$ ]]; then
echo "No previous commit; skip black."
exit 0
fi
mapfile -t files < <(git diff --name-only --diff-filter=ACMR "$before" "${{ github.sha }}" -- '*.py' || true)
fi
if [ ${#files[@]} -eq 0 ]; then
echo "No Python files changed."
exit 0
fi
python -m black -S --check "${files[@]}"