Reject unformatted PRs #8
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: Clang Format Check | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| clang-format-check: | |
| name: Check PR formatting with clang-format-15 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Need full history to compare with main branch | |
| - name: Install clang-format-15 | |
| run: | | |
| sudo apt-get install -y clang-format-15 | |
| - name: Fetch main branch | |
| run: | | |
| git fetch origin main:main | |
| - name: Check formatting | |
| run: | | |
| echo "Running git-clang-format-15 to check for formatting issues..." | |
| echo "Comparing against main branch..." | |
| # Create a temporary file for the diff and ensure cleanup | |
| DIFF_FILE="$(mktemp)" | |
| trap 'rm -f "$DIFF_FILE"' EXIT | |
| # Run git-clang-format and capture status safely under set -e | |
| if git-clang-format-15 --diff main --binary clang-format-15 > "$DIFF_FILE"; then | |
| status=0 | |
| else | |
| status=$? | |
| fi | |
| if [ "$status" -eq 0 ]; then | |
| echo "✅ Code is properly formatted!" | |
| exit 0 | |
| elif [ "$status" -eq 1 ]; then | |
| echo "❌ Code formatting issues detected!" | |
| echo "" | |
| echo "The following changes would be made by clang-format-15:" | |
| echo "==================================================" | |
| cat "$DIFF_FILE" | |
| echo "==================================================" | |
| echo "" | |
| echo "Please run the following command locally on your feature branch and commit the changes:" | |
| echo " git-clang-format-15 main --binary clang-format-15" | |
| exit 1 | |
| else | |
| echo "❌ git-clang-format-15 failed with exit code $status" | |
| echo "Output (if any):" | |
| cat "$DIFF_FILE" | |
| exit 1 | |
| fi |