From 9d578b8cbc0e3cfcc984d21e9c137278484012b5 Mon Sep 17 00:00:00 2001 From: Mayank Kumar <103447831+mayank-Pareek@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:31:01 -0500 Subject: [PATCH] Create clang-format.yml (#987) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Cieślar --- .github/workflows/clang-format.yml | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..d3847d8bd --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,49 @@ +name: clang-format Check + +on: + push: + branches: + - 'main' + paths: + - 'src/**/*.cpp' + - 'src/**/*.h' + - 'include/**/*.h' + workflow_dispatch: + pull_request: + paths: + - 'src/**/*.cpp' + - 'src/**/*.h' + - 'include/**/*.h' + +jobs: + check_formatting: + name: Check Code Formatting + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cache clang-format dependencies + uses: actions/cache@v3 + with: + path: /tmp/apt-cache + key: clang-format-${{ runner.os }}-${{ hashFiles('**/apt-packages.txt') }} + restore-keys: | + clang-format-${{ runner.os }}- + + - name: Install clang-format + run: | + if [ ! -f /tmp/apt-cache/clang-format-18 ]; then + sudo apt-get update + sudo apt-get install -y clang-format-18 + touch /tmp/apt-cache/clang-format-18 + fi + + - name: Run clang-format + run: | + clang-format src/**/*.cpp src/**/*.h include/**/*.h -i -style=file + + - name: Check for unformatted files + run: | + git diff --exit-code || (echo "Code is not formatted correctly" && exit 1)