Skip to content

Commit

Permalink
build: run clang-format on CI
Browse files Browse the repository at this point in the history
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: nodejs/node#42681
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
RaisinTen authored and guangwong committed Oct 10, 2022
1 parent 8fa9e60 commit 759f047
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,40 @@ jobs:
run: npx envinfo
- name: Lint C/C++ files
run: make lint-cpp
format-cpp:
if: ${{ github.event.pull_request.draft == false && github.base_ref == 'master' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Environment Information
run: npx envinfo
- name: Format C/C++ files
run: |
make format-cpp-build
CLANG_FORMAT_START="$(git merge-base HEAD refs/remotes/origin/$GITHUB_BASE_REF)" \
make format-cpp
git --no-pager diff --exit-code && EXIT_CODE="$?" || EXIT_CODE="$?"
if [ "$EXIT_CODE" != "0" ]
then
echo
echo 'ERROR: Please run:'
echo
echo ' CLANG_FORMAT_START="$(git merge-base HEAD <target-branch-name>)" make format-cpp'
echo
echo 'to format the commits in your branch.'
exit "$EXIT_CODE"
fi
lint-js-and-md:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
Expand Down

0 comments on commit 759f047

Please sign in to comment.