Merge pull request #323 from smash-transport/roch/fix_formatter_WF2 #76
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: Code Formatting Check and Fix | |
on: | |
push: | |
branches: | |
- main | |
- sparkx_devel # Run on any push to these branches | |
jobs: | |
code-formatting: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install black==24.8.0 | |
- name: Check code formatting | |
id: black-check | |
run: | | |
black --check --line-length 80 src/sparkx tests/ | |
continue-on-error: true # Allow the workflow to continue even if this step fails | |
- name: Format code (if needed) | |
if: steps.black-check.outcome == 'failure' # Only run if the 'Check code formatting' step failed | |
run: | | |
black --line-length 80 src/sparkx tests/ | |
- name: Commit and push changes (if any) | |
if: steps.black-check.outcome == 'failure' # Only commit changes if formatting was needed | |
run: | | |
git config --local user.name "GitHub Action" | |
git config --local user.email "[email protected]" | |
git add src/sparkx tests/ | |
git commit -m "Automatically format code using black" || echo "No changes to commit" | |
git push origin ${{ github.ref_name }} |