Skip to content

[CI] Add clang-format checker to pre-commit checks #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: clang-format-check

on:
pull_request:
branches:
- sycl
types: [open, edit, reopen, synchronize]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# checkout PR head
ref: '${{github.event.pull_request.head.sha}}'
- name: Fetch target branch
run: git fetch --no-tags --prune --depth=1 origin +refs/heads/${{github.base_ref}}:refs/remotes/origin/${{github.base_ref}}

- name: Get clang-format first
run: sudo apt-get install -yqq clang-format-9

- name: Run clang-format for the patch
run: |
git diff -U0 --no-color origin/${{github.base_ref}}..HEAD | ./clang/tools/clang-format/clang-format-diff.py -p1 -binary clang-format-9 > ./clang-format.patch

# Add patch with formatting fixes to CI job artifacts
- uses: actions/upload-artifact@v1
with:
name: clang-format-patch
path: ./clang-format.patch
Comment on lines +27 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose if this step? Would it be possible to download this patch-file somehow?

Copy link
Contributor Author

@bader bader Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You will be able to download the patch and apply it to your PR to fix formatting issues.
This feature was inspired by similar functionality of LLVM project pre-commit check.


- name: Check if clang-format patch is empty
run: bash -c "if [ -s ./clang-format.patch ]; then cat ./clang-format.patch; exit 1; fi"