Skip to content

Update black to the latest version incrementally #2

Update black to the latest version incrementally

Update black to the latest version incrementally #2

Workflow file for this run

name: Isort and Black Formatting
# Incrementally reformat only changed files instead of all
# Adapted solution from https://stackoverflow.com/a/72088304
# Replaces pre-commit.ci, since it reformats all the files
on:
pull_request:
branches:
- main
paths:
- '**.py'
permissions:
contents: write
jobs:
reformat_with_isort_and_black:
runs-on: ubuntu-latest
permissions:
# write permissions required to commit changes
contents: write
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
# https://github.com/tj-actions/changed-files
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: |
**.py
- name: Setup Python env
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install black and isort
run: pip install black~=24.2 isort>5.1.0,<6.0.0
- name: black
uses: psf/black@stable
with:
options: "--verbose"
src: "${{ steps.changed-files.outputs.all_changed_files }}"
version: "~= 24.2"
# - name: Apply black to changed files and isort to all files
# run: |
# if [[ -z "${{ steps.changed-files.outputs.all_changed_files }}" ]]; then exit 0; fi
# isort .
# black ${{ steps.changed-files.outputs.all_changed_files }}
# - name: isort
# uses: isort/isort-action@v1
# with:
# isort-version: ">5.1.0,<6.0.0"
# configuration: ""
- uses: EndBug/add-and-commit@v9
if: steps.auto-commit-action.outputs.changes_detected == 'true'
with:
message: Apply isort and black reformatting
# - name: Commit changed files
# run: |
# if [[ -z $(git status -s) ]]; then exit 0; fi
# git config user.name github-actions
# git config user.email github-actions@github.com
# git add .
# git commit -m "Reformatted on CI"
# git push