summaryrefslogtreecommitdiffstats
path: root/.github
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2023-04-05 06:54:28 -0400
committerGitHub <noreply@github.com>2023-04-05 06:54:28 -0400
commit6e8eee92b97db12bd0e52d23144154ca43a6d73d (patch)
treee9fcd6e97836fa90bc7af0b7212f858c517ab581 /.github
parent743b202ac39a7f31ffc884662785c2f80cc7ebea (diff)
Add basic clang-format checking to PR review. (#13951)
* Add basic clang-format checking to PR review. * Fix CI errors.
Diffstat (limited to '.github')
-rw-r--r--.github/workflows/review.yml47
1 files changed, 46 insertions, 1 deletions
diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml
index e6f74886f4..624ffb803c 100644
--- a/.github/workflows/review.yml
+++ b/.github/workflows/review.yml
@@ -1,5 +1,5 @@
---
-# Runs various ReviewDog based checks against PR with suggested changes to improve quality
+# Runs various linter checks against PR with suggested changes to improve quality
name: Review
on:
pull_request:
@@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
actionlint: ${{ steps.actionlint.outputs.run }}
+ clangformat: ${{ steps.clangformat.outputs.run }}
eslint: ${{ steps.eslint.outputs.run }}
flake8: ${{ steps.flake8.outputs.run }}
hadolint: ${{ steps.hadolint.outputs.run }}
@@ -37,6 +38,17 @@ jobs:
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
+ - name: Check files for clang-format
+ id: clangformat
+ run: |
+ if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
+ echo "run=true" >> "${GITHUB_OUTPUT}"
+ elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.\(cpp|cxx|c|hpp|hxx|h\)$' ; then
+ echo "run=true" >> "${GITHUB_OUTPUT}"
+ echo 'C/C++ code has changed, need to run clang-format.'
+ else
+ echo "run=false" >> "${GITHUB_OUTPUT}"
+ fi
- name: Check files for eslint
id: eslint
run: |
@@ -110,6 +122,39 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
+ clang-format:
+ name: clang-format
+ needs: prep-review
+ if: needs.prep-review.outputs.clangformat == 'true'
+ runs-on: ubuntu-latest
+ steps:
+ - name: Git clone repository
+ uses: actions/checkout@v3
+ with:
+ submodules: false
+ fetch-depth: 0
+ - name: Check for label
+ id: label
+ run: |
+ if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
+ echo 'check-all=true' >> "${GITHUB_OUTPUT}"
+ else
+ echo 'check-all=false' >> "${GITHUB_OUTPUT}"
+ fi
+ - name: Run clang-format
+ run: |
+ if [ "${{ steps.label.outputs.check-all }}" == 'true' ]; then
+ find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \;
+ else
+ git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E '.*\.\(cpp|cxx|c|hpp|hxx|h\)$' | \
+ xargs -n 1 -r clang-format -i --style=file
+ fi
+ git status --porcelain=v1 > /tmp/porcelain
+ if [ -s /tmp/porcelain ]; then
+ cat /tmp/porcelain
+ exit 1
+ fi
+
eslint:
name: eslint
needs: prep-review