CI: add code style check

Introduce a GitHub Actions workflow that automatically runs
devtools/format-code.sh on every pull request touching source files.
If formatting changes are detected, the check fails and provides clear
instructions for contributors—run the formatter locally and enable
“Allow edits from maintainers” so fixes can be applied.

This prevents code‑style drift and eliminates style‑only update noise.
This commit is contained in:
Rainer Gerhards 2025-07-30 12:32:40 +02:00
parent 7170e7a40f
commit 3ddd711ddb
No known key found for this signature in database
GPG Key ID: 0CB6B2A8BE80B499

View File

@ -0,0 +1,39 @@
name: "Code Style Check"
on:
pull_request:
jobs:
style-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Detect changed files
id: code_changes
uses: tj-actions/changed-files@v46
with:
files: |
**/*.c
**/*.h
devtools/format-code.sh
- name: Enforce code style
run: |
if [ "${{ steps.code_changes.outputs.any_changed }}" != "true" ]; then
echo "No code changes detected; skipping style check."
exit 0
fi
chmod +x devtools/format-code.sh
./devtools/format-code.sh
if ! git diff --exit-code; then
echo "::error ::Code style violations detected."
echo "Contributors: to fix this, run './devtools/format-code.sh' locally"
echo "and push the updated commit to your branch."
echo "Ensure 'Allow edits from maintainers' is enabled on this PR so maintainers"
echo "can help apply formatting fixes if needed."
exit 1
fi