Skip to content

ci: fail spider formatters and skip deleted prettier files #12311

ci: fail spider formatters and skip deleted prettier files

ci: fail spider formatters and skip deleted prettier files #12311

Workflow file for this run

name: black-linter
on:
push:
branches: [main]
paths:
- '**/*.py'
- requirements.txt
- .github/workflows/black-lint.yml
pull_request:
paths:
- '**/*.py'
- requirements.txt
- .github/workflows/black-lint.yml
concurrency:
group: ${{ github.workflow }} - ${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: '3.x'
- 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[@]}"