Skip to content

Commit 96673bc

Browse files
authored
build: run clang-format on CI
We already include the tool inside tools/clang-format, so we should start using it on CI. This attempts to run the linter only on the commits present in an opened PR. Signed-off-by: Darshan Sen <[email protected]> PR-URL: #42681 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f825341 commit 96673bc

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/linters.yml

+34
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ jobs:
4949
run: npx envinfo
5050
- name: Lint C/C++ files
5151
run: make lint-cpp
52+
format-cpp:
53+
if: ${{ github.event.pull_request.draft == false && github.base_ref == 'master' }}
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v3
57+
with:
58+
fetch-depth: 0
59+
persist-credentials: false
60+
- name: Use Node.js ${{ env.NODE_VERSION }}
61+
uses: actions/setup-node@v3
62+
with:
63+
node-version: ${{ env.NODE_VERSION }}
64+
- name: Set up Python ${{ env.PYTHON_VERSION }}
65+
uses: actions/setup-python@v3
66+
with:
67+
python-version: ${{ env.PYTHON_VERSION }}
68+
- name: Environment Information
69+
run: npx envinfo
70+
- name: Format C/C++ files
71+
run: |
72+
make format-cpp-build
73+
CLANG_FORMAT_START="$(git merge-base HEAD refs/remotes/origin/$GITHUB_BASE_REF)" \
74+
make format-cpp
75+
git --no-pager diff --exit-code && EXIT_CODE="$?" || EXIT_CODE="$?"
76+
if [ "$EXIT_CODE" != "0" ]
77+
then
78+
echo
79+
echo 'ERROR: Please run:'
80+
echo
81+
echo ' CLANG_FORMAT_START="$(git merge-base HEAD <target-branch-name>)" make format-cpp'
82+
echo
83+
echo 'to format the commits in your branch.'
84+
exit "$EXIT_CODE"
85+
fi
5286
lint-js-and-md:
5387
if: github.event.pull_request.draft == false
5488
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)