forked from ROCm/rocRAND
-
Notifications
You must be signed in to change notification settings - Fork 0
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-check workflow for GitHub Action (ROCm#493)
* 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
Showing
2 changed files
with
46 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,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 }} |
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,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 |