Skip to content

Commit

Permalink
ci: add code style lint to commit ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Bambooin authored and fxliang committed Feb 28, 2024
1 parent b470145 commit 30ae76b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .exclude_pattern.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
stdafx
targetver
resource.h
winapifamily
winpackagefamily
winsparkle
immdev.h
SystemTraySDK.h
ctffunc.h
7 changes: 7 additions & 0 deletions .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
with:
submodules: recursive

- name: Install llvm
run: choco install llvm --version=17.0.6

- name: Code style lint
shell: bash
run: ./clang-format.sh -i

- name: Configure build environment
shell: bash
run: |
Expand Down
21 changes: 21 additions & 0 deletions clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

WEASEL_SOURCE_PATH="RimeWithWeasel WeaselDeployer WeaselIME WeaselIPC WeaselIPCServer WeaselServer WeaselSetup WeaselTSF WeaselUI include test"

# clang format options
method="-i"

while getopts "in" option; do
case "${option}" in
n) # format code
find ${WEASEL_SOURCE_PATH} -name '*.cpp' -o -name '*.h' ! -path "include/wtl/*" | grep -wiv -f .exclude_pattern.txt | xargs clang-format --verbose -i
;;
i) # dry run and changes formatting warnings to errors
find ${WEASEL_SOURCE_PATH} -name '*.cpp' -o -name '*.h' ! -path "include/wtl/*" | grep -wiv -f .exclude_pattern.txt | xargs clang-format --verbose -Werror --dry-run || { echo Please lint your code by '"'"./clang-format.sh -n"'"'.; false; }
;;
\?) # invalid option
echo "invalid option, please use -i or -n."
exit 1
;;
esac
done
18 changes: 18 additions & 0 deletions install-clang-format.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off

if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
rem 64 bit system
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/LLVM-17.0.6-win64.exe', 'LLVM-17.0.6-win64.exe')"
rem LLVM-17.0.6-win64.exe /S
rem or maybe
rem output/7z.exe e LLVM-17.0.6-win64.exe bin/clang-format.exe -o.
rem rm LLVM-17.0.6-win64.exe
) else (
rem 32 bit system
rem powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/LLVM-17.0.6-win32.exe', 'LLVM-17.0.6-win32.exe')"
rem LLVM-17.0.6-win32.exe /S
rem or maybe
rem output/7z.exe e LLVM-17.0.6-win32.exe bin/clang-format.exe -o.
rem rm LLVM-17.0.6-win32.exe
)
pause

0 comments on commit 30ae76b

Please sign in to comment.