Skip to content

Commit 15b9b85

Browse files
committed
ci: automate code formatting and linting with git hooks
1 parent 22b4975 commit 15b9b85

9 files changed

Lines changed: 122 additions & 94 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ concurrency:
2323
cancel-in-progress: true
2424

2525
jobs:
26-
SwiftLint:
27-
runs-on: ubuntu-latest
28-
steps:
29-
- uses: actions/checkout@v5
30-
- name: GitHub Action for SwiftLint
31-
uses: norio-nomura/action-swiftlint@3.2.1
32-
with:
33-
args: --strict
34-
env:
35-
DIFF_BASE: ${{ github.base_ref }}
3626
macOS:
3727
name: ${{ matrix.name }}
3828
runs-on: ${{ matrix.runsOn }}
@@ -205,23 +195,3 @@ jobs:
205195
with:
206196
name: MergedResult
207197
path: test_output/final
208-
209-
discover-typos:
210-
name: Discover Typos
211-
runs-on: macos-15
212-
env:
213-
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
214-
steps:
215-
- uses: actions/checkout@v5
216-
217-
- name: Set up Python environment
218-
run: |
219-
python3 -m venv .venv
220-
source .venv/bin/activate
221-
pip install --upgrade pip
222-
pip install codespell
223-
224-
- name: Discover typos
225-
run: |
226-
source .venv/bin/activate
227-
codespell --ignore-words-list="hart,inout,msdos,sur" --skip="./.build/*,./.git/*"

.github/workflows/lint.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
- "Sources/**"
10+
- ".github/workflows/ci.yml"
11+
- "Tests/**"
12+
13+
concurrency:
14+
group: lint-${{ github.head_ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
lint:
19+
name: Lint
20+
runs-on: macos-15
21+
steps:
22+
- uses: actions/checkout@v5
23+
- uses: jdx/mise-action@v3
24+
- name: Run
25+
run: mise run lint
26+
27+
discover-typos:
28+
name: discover-typos
29+
runs-on: macos-15
30+
env:
31+
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
32+
steps:
33+
- uses: actions/checkout@v5
34+
35+
- name: Set up Python environment
36+
run: |
37+
python3 -m venv .venv
38+
source .venv/bin/activate
39+
pip install --upgrade pip
40+
pip install codespell
41+
42+
- name: Discover typos
43+
run: |
44+
source .venv/bin/activate
45+
codespell --ignore-words-list="hart,inout,msdos,sur" --skip="./.build/*,./.git/*"

Makefile

Lines changed: 0 additions & 19 deletions
This file was deleted.

Mintfile

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ dependencies: [
259259
Bootstrapping development environment
260260

261261
```
262-
make bootstrap
262+
mise install
263263
```
264264

265265
Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!

hooks/pre-commit

Lines changed: 0 additions & 38 deletions
This file was deleted.

mise.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[tools]
22
git-cliff = "2.9.1"
3-
4-
[hooks]
5-
postinstall = "mise run install"
3+
swiftlint = "0.62.2"
4+
swiftformat = "0.58.6"
65

76
[settings]
8-
experimental = true
7+
experimental = true
8+
9+
[hooks]
10+
postinstall = "mise run install"

mise/tasks/install.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "🔧 Installing git hooks..."
6+
7+
# Find git repository root
8+
GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
9+
10+
if [ -z "$GIT_ROOT" ]; then
11+
echo "❌ Error: Not a git repository"
12+
exit 1
13+
fi
14+
15+
echo "📁 Git root: $GIT_ROOT"
16+
17+
# Create hooks directory if it doesn't exist
18+
mkdir -p "$GIT_ROOT/.git/hooks"
19+
20+
# Create pre-commit hook
21+
cat > "$GIT_ROOT/.git/hooks/pre-commit" <<'HOOK_EOF'
22+
#!/bin/bash
23+
24+
echo "🔍 Running linters..."
25+
26+
echo "📝 Formatting staged Swift files..."
27+
git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do
28+
if [[ $line == *"/Generated"* ]]; then
29+
echo "⏭️ Skipping generated file: $line"
30+
else
31+
echo "✨ Formatting: $line"
32+
mise exec swiftformat -- swiftformat "${line}"
33+
git add "$line"
34+
fi
35+
done
36+
37+
if ! mise run lint; then
38+
echo "❌ Lint failed. Please fix the issues before committing."
39+
echo "💡 Tip: Run 'mise run format' to auto-fix some issues"
40+
echo "⚠️ To skip this hook, use: git commit --no-verify"
41+
exit 1
42+
fi
43+
44+
echo "✅ All checks passed!"
45+
exit 0
46+
HOOK_EOF
47+
48+
chmod +x "$GIT_ROOT/.git/hooks/pre-commit"
49+
50+
echo "✅ Git hooks installed successfully!"
51+
echo "📍 Hook location: $GIT_ROOT/.git/hooks/pre-commit"
52+
echo ""
53+
echo "Pre-commit hook will:"
54+
echo " 1. Format staged Swift files (except /Generated)"
55+
echo " 2. Run mise lint"
56+
echo ""
57+
echo "To skip the hook, use: git commit --no-verify"

mise/tasks/lint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
#MISE description="Lint the validator package using SwiftLint and SwiftFormat"
3+
#MISE usage flag "-f --fix" help="Fix the fixable issues"
4+
5+
set -eo pipefail
6+
7+
if [ "$usage_fix" = "true" ]; then
8+
swiftformat Sources
9+
swiftlint lint --fix --quiet --config .swiftlint.yml Sources
10+
else
11+
swiftformat Sources --lint
12+
swiftlint lint --quiet --config .swiftlint.yml Sources
13+
fi

0 commit comments

Comments
 (0)