Skip to content

Commit 97e4f67

Browse files
author
chen
committed
Add git precommit hook and github actions
1 parent 54be723 commit 97e4f67

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

.githooks/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
echo "Running spotlessApply..."
4+
./gradlew spotlessApply
5+
6+
# Check if spotlessApply was successful
7+
if [ $? -ne 0 ]; then
8+
echo "❌ spotlessApply failed. Please fix the formatting issues and try again."
9+
exit 1
10+
fi
11+
12+
# Add the changes made by spotlessApply
13+
git add .
14+
15+
echo "✅ spotlessApply completed successfully"
16+
exit 0

.github/workflows/pr-checks.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
cache: gradle
22+
23+
- name: Cache clang-format
24+
uses: actions/cache@v3
25+
id: clang-cache
26+
with:
27+
path: /usr/local/clang-20.1.5
28+
key: clang-format-20.1.5
29+
30+
- name: Install clang-format 20.1.5
31+
if: steps.clang-cache.outputs.cache-hit != 'true'
32+
run: |
33+
echo "Installing clang-format 20.1.5..."
34+
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.5/clang+llvm-20.1.5-x86_64-linux-gnu-ubuntu-22.04.tar.xz
35+
tar xf clang+llvm-20.1.5-x86_64-linux-gnu-ubuntu-22.04.tar.xz
36+
sudo mv clang+llvm-20.1.5-x86_64-linux-gnu-ubuntu-22.04 /usr/local/clang-20.1.5
37+
echo "/usr/local/clang-20.1.5/bin" >> $GITHUB_PATH
38+
39+
- name: Verify clang-format installation
40+
run: |
41+
clang-format --version
42+
if [ $? -ne 0 ]; then
43+
echo "❌ clang-format installation failed"
44+
exit 1
45+
fi
46+
47+
- name: Grant execute permission for gradlew
48+
run: chmod +x gradlew
49+
50+
- name: Run spotlessCheck
51+
run: |
52+
echo "Running spotlessCheck..."
53+
./gradlew spotlessCheck
54+
if [ $? -ne 0 ]; then
55+
echo "❌ spotlessCheck failed. Please run './gradlew spotlessApply' locally to fix formatting issues."
56+
exit 1
57+
fi
58+
59+
- name: Run detekt
60+
run: |
61+
echo "Running detekt..."
62+
./gradlew detekt
63+
if [ $? -ne 0 ]; then
64+
echo "❌ detekt found code style issues. Please fix them locally."
65+
exit 1
66+
fi
67+
68+
- name: Run unit tests
69+
run: |
70+
echo "Running unit tests..."
71+
./gradlew testDebugUnitTest
72+
if [ $? -ne 0 ]; then
73+
echo "❌ Unit tests failed. Please fix the failing tests locally."
74+
exit 1
75+
fi

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,32 @@ With `all` option, it will conduct deep clean including open source components.
230230

231231
WhisperKit Android is currently in the beta stage. We are actively developing the project and welcome contributions from the community.
232232

233+
## Git Hooks
234+
235+
This project uses Git hooks to maintain code quality. These hooks help ensure consistent code formatting and quality standards.
236+
237+
### Setup
238+
239+
To use the Git hooks, run the following command in your repository root:
240+
241+
```bash
242+
git config core.hooksPath .githooks
243+
```
244+
245+
### Available Hooks
246+
247+
#### pre-commit
248+
- Runs `spotlessApply` to automatically fix code formatting issues
249+
- If formatting fixes are applied, they are automatically staged
250+
- The commit will be blocked if `spotlessApply` fails
251+
252+
### Troubleshooting
253+
254+
If you need to bypass the hooks temporarily (not recommended), you can use:
255+
```bash
256+
git commit --no-verify
257+
```
258+
233259
# License
234260

235261
- We release WhisperKit Android under [MIT License](LICENSE).

0 commit comments

Comments
 (0)