Add a clang format file and a CI that checks formatting issues #2
Workflow file for this run
This file contains hidden or 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: Python Formatting Check | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| python-black-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Black | |
| run: pip install black | |
| - name: Run Black and extract offending files | |
| id: black_check | |
| continue-on-error: true | |
| run: | | |
| set +e | |
| OUTPUT=$(black --check . 2>&1) | |
| EXIT_CODE=$? | |
| echo "$OUTPUT" > black_output.txt | |
| grep '^would reformat' black_output.txt | awk '{print $3}' | sort -u > black_files.txt | |
| if [[ -s black_files.txt ]]; then | |
| echo "py_failed=true" >> $GITHUB_ENV | |
| echo "black_files<<EOF" >> $GITHUB_OUTPUT | |
| cat black_files.txt >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| else | |
| echo "py_failed=false" >> $GITHUB_ENV | |
| echo "black_files=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Comment on PR if Black failed | |
| if: env.py_failed == 'true' | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body: | | |
| ⚠️ **Black formatting check failed** | |
| The following Python files need formatting: | |
| ``` | |
| ${{ steps.black_check.outputs.black_files }} | |
| ``` | |
| Please run: | |
| ```bash | |
| black . | |
| ``` | |
| And commit the changes before merging. | |
| - name: Fail if Black failed | |
| if: env.py_failed == 'true' | |
| run: | | |
| echo "❌ Python formatting issues found." | |
| exit 1 |