Skip to content

Commit 36fba37

Browse files
Enforce code formatting in PR via git-clang-client (#1383)
In #946 the codebase was reformatted for consistency, but as this was not enforced the codebase has drifted since then. To avoid this happening again, enforce this at the PR stage. Testing: - [example failure](https://github.com/hazelcast/hazelcast-cpp-client/actions/runs/20455944532/job/58777930370) - [example success ](https://github.com/hazelcast/hazelcast-cpp-client/actions/runs/20455961135/job/58777982668) This is alternative implementation addressing feedback from #1342 (comment) Closes #1342 --------- Co-authored-by: ihsan demir <[email protected]>
1 parent fc2689d commit 36fba37

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

.github/workflows/build-pr.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
outputs:
7474
ref: ${{ steps.get-refs.outputs.ref }}
7575
merged-ref: ${{ steps.get-refs.outputs.merged-ref }}
76+
base-sha: ${{ steps.get-refs.outputs.base-sha }}
7677

7778
steps:
7879
- name: Get Refs
@@ -85,11 +86,15 @@ jobs:
8586
echo "PR_COMMIT: ${{ inputs.pr_commit }}"
8687
echo "ref=refs/pull/${{ inputs.pr_number }}/merge" >> $GITHUB_OUTPUT
8788
echo "merged-ref=${{ inputs.pr_commit }}" >> $GITHUB_OUTPUT
89+
echo "base-sha=$(gh api repos/${GITHUB_REPOSITORY}/pulls/${{ inputs.pr_number }} --jq '.base.sha')" >> "$GITHUB_OUTPUT"
8890
else
8991
echo "PR_NUMBER: ${{ github.event.pull_request.number }}"
9092
echo "ref=refs/pull/${{ github.event.pull_request.number }}/merge" >> $GITHUB_OUTPUT
9193
echo "merged-ref=''" >> $GITHUB_OUTPUT
94+
echo "base-sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
9295
fi
96+
env:
97+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
9398

9499
# run for code-coverage and upload the result as an artifact.
95100
code-coverage:
@@ -231,3 +236,33 @@ jobs:
231236
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
232237
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
233238
HZ_TEST_AWS_INSTANCE_PRIVATE_IP: ${{ secrets.HZ_TEST_AWS_INSTANCE_PRIVATE_IP }}
239+
240+
enforce-code-formatting:
241+
runs-on: ubuntu-latest
242+
needs: get-refs
243+
244+
steps:
245+
- name: Install Necessary Packages
246+
run: |
247+
sudo apt-get update
248+
sudo apt-get install -y clang-format
249+
250+
- uses: actions/checkout@v5
251+
with:
252+
ref: ${{ needs.get-refs.outputs.ref }}
253+
token: ${{ secrets.GH_TOKEN }}
254+
fetch-depth: 0
255+
256+
- name: Check formatting
257+
run: |
258+
source /dev/stdin <<< "$(curl --silent https://raw.githubusercontent.com/hazelcast/github-actions-common-scripts/main/logging.functions.sh)"
259+
260+
git-clang-format \
261+
${{ needs.get-refs.outputs.base-sha }} \
262+
-- \
263+
hazelcast
264+
265+
if ! git --no-pager diff; then
266+
echoerr "Code not formatted as expected"
267+
exit 1
268+
fi

0 commit comments

Comments
 (0)