-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clang-format checker GitHub action. (#5617)
This action runs clang-format-diff on the difference between the head and the merge base to identify introductions of clang-format violtions in changed code.
- Loading branch information
1 parent
4d132f9
commit d4b3cb6
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 'PR clang-format checker' | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
- reopened | ||
jobs: | ||
check-pr-formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: install clang-format | ||
run: sudo apt install -y clang-format | ||
- run: | | ||
echo Comparing $GITHUB_BASE_REF vs HEAD | ||
git diff -U0 --no-color origin/$GITHUB_BASE_REF..HEAD | clang-format-diff -p1 | tee format.diff | ||
if [ -s "format.diff" ] | ||
then | ||
exit 1 | ||
fi | ||
- if: failure() | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'PR contains clang-format violations. See action log for diff.' | ||
}) |