Skip to content
Closed
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions .github/workflows/black-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Auto Black Formatter

on:
pull_request:
paths:
- "**.py"

jobs:
black-format:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Black
run: pip install black

- name: Run Black
run: black . --check --diff || black .

- name: Commit formatted code
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
BRANCH_NAME=black-formatting-pr-${{ github.event.pull_request.number }}
git checkout -b "$BRANCH_NAME" || git checkout "$BRANCH_NAME"
git add .
git commit -m "Apply Black code formatting" || echo "No changes to commit"
git push --set-upstream origin "$BRANCH_NAME"

- name: Push and create PR
uses: peter-evans/create-pull-request@v5
with:
commit-message: Apply Black code formatting
branch: black-formatting-pr-${{ github.event.pull_request.number }}
title: "Format code with Black"
body: "This PR auto-formats the code using [Black](https://github.com/psf/black)."
base: ${{ github.head_ref }}
Loading