This repository has been archived by the owner on Jan 29, 2025. It is now read-only.
i think this should work #13
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: Black Code Formatter | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
format-code: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install Black | |
run: pip install black | |
- name: Run Black Formatter | |
id: action_black | |
run: | | |
black package/ tests/ | |
git diff --exit-code || echo "Files have been formatted by Black." | |
- name: Check for changes | |
id: check_changes | |
run: | | |
git diff --exit-code || echo "Changes detected." | |
- name: Commit and push changes | |
if: steps.check_changes.outputs.changes != '' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "style: format code with Black" || echo "No changes to commit." | |
git push || echo "Failed to push changes." |