From dde775999aa0a840fa503628da692363e8b6d0fe Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 4 Feb 2025 09:37:12 +0100 Subject: [PATCH] Add contrib/checkformat.bash to check for clang-formatting --- .github/workflows/checkdiff.yml | 2 +- .github/workflows/checkformat.yml | 12 ++++++++++++ contrib/checkformat.bash | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/checkformat.yml create mode 100755 contrib/checkformat.bash diff --git a/.github/workflows/checkdiff.yml b/.github/workflows/checkdiff.yml index feb450616..c2504f2a9 100644 --- a/.github/workflows/checkdiff.yml +++ b/.github/workflows/checkdiff.yml @@ -11,7 +11,7 @@ jobs: cd rgbds git remote add upstream "${{ github.event.pull_request.base.repo.clone_url }}" git fetch upstream - - name: Checkdiff + - name: Check diff working-directory: rgbds run: | make checkdiff "BASE_REF=${{ github.event.pull_request.base.sha }}" Q= | tee log diff --git a/.github/workflows/checkformat.yml b/.github/workflows/checkformat.yml new file mode 100644 index 000000000..857a32567 --- /dev/null +++ b/.github/workflows/checkformat.yml @@ -0,0 +1,12 @@ +name: Code format checking +on: pull_request + +jobs: + checkformat: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Check format + run: | + ./contrib/checkformat.bash diff --git a/contrib/checkformat.bash b/contrib/checkformat.bash new file mode 100755 index 000000000..f2f357caa --- /dev/null +++ b/contrib/checkformat.bash @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# SPDX-License-Identifier: MIT + +clang-format --version + +find . -type f \( -iname '*.hpp' -o -iname '*.cpp' \) -exec clang-format -i {} + + +if ! git diff-index --quiet HEAD --; then + echo 'Unformatted files:' + git diff-index --name-only HEAD -- + echo + git diff HEAD -- + return 1 +fi