A GitHub Action that runs Black code formatter on your Python code and provides formatting feedback directly in your pull requests.
- Runs Black code formatter on Python files
- Flexible comment modes (replace, append, or none)
- Configurable paths to check
- Optional failure on formatting issues
- Automatic Python setup
- Detailed formatting instructions in comments
- Customizable Black arguments
Add this to your GitHub workflow:
name: Black Code Format Check
on:
pull_request:
branches: [ main, develop ]
paths:
- '**.py'
permissions:
contents: read
pull-requests: write
jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: baobabsoluciones/check-formatting-python@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
python-version: '3.x' # optional, default is '3.x' which uses latest Python 3 stable version
black-version: 'latest' # optional, default is 'latest'
black-args: '--check' # optional, default is '--check'
paths: 'src tests' # optional, default is '.', As space-separated paths
fail-on-error: 'true' # optional, default is 'true'
comment-mode: 'replace' # optional, default is 'replace'| Input | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for PR comments | Yes | ${{ github.token }} |
python-version |
Python version to use | No | '3.x' |
black-version |
Black version to use | No | '23.12.0' |
black-args |
Space-separated Black arguments | No | '--check --verbose' |
paths |
Space-separated paths to check | No | '.' |
fail-on-error |
Whether to fail on formatting issues | No | 'true' |
comment-mode |
Mode of commenting (append/replace/none) | No | 'replace' |
- uses: baobabsoluciones/check-formatting-python@v1
with:
paths: 'src tests scripts'- uses: baobabsoluciones/check-formatting-python@v1
with:
fail-on-error: 'false'# Replace existing comments (default)
- uses: baobabsoluciones/check-formatting-python@v1
with:
comment-mode: 'replace'
# Append new comments
- uses: baobabsoluciones/check-formatting-python@v1
with:
comment-mode: 'append'
# No comments
- uses: baobabsoluciones/check-formatting-python@v1
with:
comment-mode: 'none'MIT