Skip to content

Commit ca1383a

Browse files
committed
Fix workflow; hooks
1 parent d7968a8 commit ca1383a

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

.github/workflows/swiftformat-check.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v4
1919

20+
- name: Install Swift
21+
uses: swift-actions/setup-swift@v1
22+
with:
23+
swift-version: '5.9'
24+
2025
- name: Install SwiftFormat
2126
run: |
22-
wget -O swiftformat.zip https://github.com/nicklockwood/SwiftFormat/archive/0.55.6.zip
23-
unzip swiftformat.zip
24-
cd SwiftFormat-0.55.6
27+
git clone https://github.com/nicklockwood/SwiftFormat
28+
cd SwiftFormat
2529
swift build -c release
2630
sudo cp .build/release/swiftformat /usr/local/bin/
2731

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ The Split team monitors all issues submitted to this [issue tracker](https://git
5757
## Contributing
5858
Please see [Contributors Guide](CONTRIBUTORS-GUIDE.md) to find all you need to submit a Pull Request (PR).
5959

60+
## Development
61+
62+
### Code Formatting
63+
64+
This project uses [SwiftFormat](https://github.com/nicklockwood/SwiftFormat) to maintain consistent code formatting.
65+
66+
#### Installation
67+
68+
Install SwiftFormat using Homebrew:
69+
70+
```bash
71+
brew install swiftformat
72+
```
73+
74+
#### Pre-commit Hook Setup
75+
76+
To automatically format your code before each commit, set up the pre-commit hook:
77+
78+
```bash
79+
# Navigate to the repository root
80+
cd /path/to/ios-client
81+
82+
# Make the pre-commit hook executable
83+
chmod +x scripts/git-hooks/pre-commit
84+
85+
# Create a symbolic link to the pre-commit hook
86+
git config core.hooksPath scripts/git-hooks
87+
```
88+
6089
## License
6190
Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).
6291

scripts/git-hooks/pre-commit

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Path to SwiftFormat binary
4+
SWIFT_FORMAT=$(which swiftformat)
5+
6+
# Check if SwiftFormat is installed
7+
if [ -z "$SWIFT_FORMAT" ]; then
8+
echo "error: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat"
9+
echo "or install via brew: brew install swiftformat"
10+
exit 1
11+
fi
12+
13+
# Get list of Swift files that are staged for commit
14+
FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep "\.swift$")
15+
16+
if [ -n "$FILES" ]; then
17+
echo "Running SwiftFormat on staged Swift files..."
18+
echo "$FILES" | xargs "$SWIFT_FORMAT" --config .swiftformat
19+
20+
# Add back the formatted files to staging
21+
echo "$FILES" | xargs git add
22+
fi
23+
24+
exit 0

0 commit comments

Comments
 (0)