From 4676fdbdd18a0b1460bf231ad8b5ab678e779b1c Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 9 Apr 2022 20:25:23 +0530 Subject: [PATCH 1/4] 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 --- .github/workflows/linters.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index e5eff5ee4474eb..d2f5e5055df50a 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -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 + 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 )" 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 From acfed4058001c3c8657d8b17f515636ea81f7c18 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 10 Apr 2022 15:18:48 +0530 Subject: [PATCH 2/4] src: trigger a clang-format linting error Signed-off-by: Darshan Sen --- src/crypto/crypto_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index 739b559c3b7b22..4faff290cfee75 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -55,7 +55,7 @@ static bool extra_root_certs_loaded = false; BIOPointer LoadBIO(Environment* env, Local v) { HandleScope scope(env->isolate()); - if (v->IsString()) { + if (v-> IsString()) { Utf8Value s(env->isolate(), v); return NodeBIO::NewFixed(*s, s.length()); } From abfa1031ff45019f58ba5a93370caf724cc7fb39 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sun, 10 Apr 2022 15:20:17 +0530 Subject: [PATCH 3/4] src: accept the suggested change from clang-format Signed-off-by: Darshan Sen --- src/crypto/crypto_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index 4faff290cfee75..739b559c3b7b22 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -55,7 +55,7 @@ static bool extra_root_certs_loaded = false; BIOPointer LoadBIO(Environment* env, Local v) { HandleScope scope(env->isolate()); - if (v-> IsString()) { + if (v->IsString()) { Utf8Value s(env->isolate(), v); return NodeBIO::NewFixed(*s, s.length()); } From 6c0957c00a75e1ba2617eeb409841976747255ed Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Wed, 13 Apr 2022 21:04:18 +0530 Subject: [PATCH 4/4] Update .github/workflows/linters.yml --- .github/workflows/linters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index d2f5e5055df50a..312ba0b3c9706a 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -50,7 +50,7 @@ jobs: - name: Lint C/C++ files run: make lint-cpp format-cpp: - if: github.event.pull_request.draft == false + if: ${{ github.event.pull_request.draft == false && github.base_ref == 'master' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3