This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto-format with Black and isort | |
on: | |
push: | |
branches: | |
- main | |
- patch | |
- dev # Add additional branches here as needed | |
pull_request: | |
branches: | |
- main | |
- patch | |
- dev # Ensure formatting is applied for PRs targeting these branches | |
jobs: | |
autoformat: | |
name: Auto-format Code with Black and isort | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install Black and isort | |
run: | | |
python -m pip install --upgrade pip | |
pip install black isort | |
- name: Run isort | |
run: isort . | |
- name: Run Black Formatter | |
run: black --line-length 119 . | |
- name: Check for Changes | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
if [ -n "$(git status --porcelain)" ]; then | |
git add . | |
git commit -m "Automatically sorted imports with isort" | |
git push | |
else | |
echo "No changes to commit." |