Skip to content

Commit

Permalink
Add clang-format-check workflow for GitHub Action (ROCm#493)
Browse files Browse the repository at this point in the history
* Add clang-format-check workflow for GitHub Action

* Update to clang-format version 17

* Apply clang-format on diff

* Modify diff script

* Run clang-format instead of using Python script

* Update format script

* Update format script

* Update format script

* Use clang-format 17

* Add llvm repo

* Add gpg key

* Compare branches
  • Loading branch information
samjwu authored May 22, 2024
1 parent 6cb85aa commit a1a36a8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check Clang-Format on Diff

on: [push, pull_request]

jobs:
clang-format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Import LLVM GPG Key
run: |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
- name: Add LLVM Repository
run: |
sudo add-apt-repository "deb http://apt.llvm.org/jammy llvm-toolchain-jammy-17 main"
sudo apt-get update
- name: Install clang-format 17
run: |
sudo apt-get install clang-format-17
- name: Check Clang-Format on Diff
run: |
./clang-format-diff.sh ${{ github.base_ref }} ${{ github.ref }}
18 changes: 18 additions & 0 deletions clang-format-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

BASE_BRANCH=$1
CURRENT_BRANCH=$2

# Save unified diff with 0 context
git diff -U0 --name-only $BASE_BRANCH...$CURRENT_BRANCH > changes.diff

# Apply clang-format on diff
FORMAT_DIFF=$(clang-format -style=file changes.diff)

if [ ! -z "$FORMAT_DIFF" ]; then
echo "The following formatting errors were found:"
echo "$FORMAT_DIFF"
exit 1
else
echo "All code is properly formatted."
fi

0 comments on commit a1a36a8

Please sign in to comment.