Add clang-format configuration and format check workflow #1
Workflow file for this run
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: Formatting check | |
on: [pull_request] | |
jobs: | |
formatting-check: | |
name: Formatting check | |
runs-on: ubuntu-24.04 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# To get a diff from the PR we need to fetch 2 commits. | |
# The checkout action will create a merge commit as {{ github.sha }}. | |
fetch-depth: 2 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -yqq clang-format | |
- name: Format check | |
id: format-check | |
run: | | |
git diff -U0 --no-color ${{ github.sha }}^ -- '*.cpp' '*.c' '*.h' '*.hpp' | | |
/usr/share/clang/clang-format-16/clang-format-diff.py -p1 > clang-format.patch | |
# Check if patch is not empty | |
if [ -s clang-format.patch ]; then | |
echo "###############################################################" | |
echo "# Format checks failed!" | |
echo "# A patch has been uploaded as an artifact and is shown below." | |
echo "###############################################################" | |
# Show patch | |
cat clang-format.patch | |
exit 1 | |
fi | |
- name: Upload format fixes patch | |
uses: actions/upload-artifact@v4 | |
if: ${{ failure() && steps.format-check.outcome == 'failure' }} | |
with: | |
name: clang-format.patch | |
path: clang-format.patch | |
if-no-files-found: ignore |