From b5e1cf5da3a763268c407fbf9541266ca240c1da Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 12 Feb 2024 18:13:01 +0100 Subject: [PATCH] Create ClangFormat.yml --- .github/workflows/ClangFormat.yml | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/ClangFormat.yml diff --git a/.github/workflows/ClangFormat.yml b/.github/workflows/ClangFormat.yml new file mode 100644 index 0000000..29db349 --- /dev/null +++ b/.github/workflows/ClangFormat.yml @@ -0,0 +1,43 @@ +name: Clang Format Checker and Auto-Fixer +on: + push: + branches: + - '*' + workflow_run: + workflows: ["Clang Format Checker and Auto-Fixer"] + types: + - completed + +jobs: + clang-format-checking: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - name: Install Clang + run: sudo apt-get update && sudo apt-get install -y clang + + - name: Install GitHub CLI + run: | + type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && sudo apt update \ + && sudo apt install gh -y + + - name: Check and Auto-Fix Formatting + run: | + find . \( -name "*.h" -or -name "*.c" -or -name "*.cpp" -or -name "*.hpp" -or -name "*.cc" -or -name "*.cxx" -or -name "*.hxx" -or -name "*.inl" -or -name "*.ipp" \) \ + | xargs clang-format -i -style=file + + - name: Commit changes (if any) + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git diff --exit-code || (git add -A && git commit -m "Auto-fix formatting issues") + + # Push changes to the current branch + git push origin HEAD