@cryptotaxi247 / netdata-1 / commits / 6e8eee92b

Add basic clang-format checking to PR review. (#13951)

* Add basic clang-format checking to PR review. * Fix CI errors.

Austin S. Hemmelgarn committed Apr 5, 2023 at 06:54 UTC 6e8eee92b97db12bd0e52d23144154ca43a6d73d
1 file changed +46 -1
.github/workflows/review.yml
+46 -1
@@ -1,5 +1,5 @@
1 ---
2 -# Runs various ReviewDog based checks against PR with suggested changes to improve quality
2 +# Runs various linter checks against PR with suggested changes to improve quality
3 name: Review
4 on:
5 pull_request:
@@ -15,6 +15,7 @@ jobs:
15 runs-on: ubuntu-latest
16 outputs:
17 actionlint: ${{ steps.actionlint.outputs.run }}
18 + clangformat: ${{ steps.clangformat.outputs.run }}
19 eslint: ${{ steps.eslint.outputs.run }}
20 flake8: ${{ steps.flake8.outputs.run }}
21 hadolint: ${{ steps.hadolint.outputs.run }}
@@ -37,6 +38,17 @@ jobs:
38 else
39 echo "run=false" >> "${GITHUB_OUTPUT}"
40 fi
41 + - name: Check files for clang-format
42 + id: clangformat
43 + run: |
44 + if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
45 + echo "run=true" >> "${GITHUB_OUTPUT}"
46 + elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.\(cpp|cxx|c|hpp|hxx|h\)$' ; then
47 + echo "run=true" >> "${GITHUB_OUTPUT}"
48 + echo 'C/C++ code has changed, need to run clang-format.'
49 + else
50 + echo "run=false" >> "${GITHUB_OUTPUT}"
51 + fi
52 - name: Check files for eslint
53 id: eslint
54 run: |
@@ -110,6 +122,39 @@ jobs:
122 github_token: ${{ secrets.GITHUB_TOKEN }}
123 reporter: github-pr-check
124
125 + clang-format:
126 + name: clang-format
127 + needs: prep-review
128 + if: needs.prep-review.outputs.clangformat == 'true'
129 + runs-on: ubuntu-latest
130 + steps:
131 + - name: Git clone repository
132 + uses: actions/checkout@v3
133 + with:
134 + submodules: false
135 + fetch-depth: 0
136 + - name: Check for label
137 + id: label
138 + run: |
139 + if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
140 + echo 'check-all=true' >> "${GITHUB_OUTPUT}"
141 + else
142 + echo 'check-all=false' >> "${GITHUB_OUTPUT}"
143 + fi
144 + - name: Run clang-format
145 + run: |
146 + if [ "${{ steps.label.outputs.check-all }}" == 'true' ]; then
147 + find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \;
148 + else
149 + git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E '.*\.\(cpp|cxx|c|hpp|hxx|h\)$' | \
150 + xargs -n 1 -r clang-format -i --style=file
151 + fi
152 + git status --porcelain=v1 > /tmp/porcelain
153 + if [ -s /tmp/porcelain ]; then
154 + cat /tmp/porcelain
155 + exit 1
156 + fi
157 +
158 eslint:
159 name: eslint
160 needs: prep-review