-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·52 lines (43 loc) · 1.6 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
branch="$(git rev-parse --abbrev-ref HEAD)"
#----------------------------------------------------------------
# RESTRICT BRANCHES FROM DIRECT PUSH
#----------------------------------------------------------------
if [ "$branch" = "main" ]; then
echo "You can't commit directly to $branch"
exit 1
fi
#----------------------------------------------------------------
# RUN SWIFTLINT
#----------------------------------------------------------------
# Run SwiftLint
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
# Run SwiftLint for given filename
run_swiftlint() {
local filename="${1}"
if [[ "${filename##*.}" == "swift" ]]; then
${SWIFT_LINT} lint --path "${filename}"
fi
}
if [[ -e "${SWIFT_LINT}" ]]; then
echo "SwiftLint version: $(${SWIFT_LINT} version)"
# Run for both staged and unstaged files
git diff --name-only | while read filename; do run_swiftlint "${filename}"; done
git diff --cached --name-only | while read filename; do run_swiftlint "${filename}"; done
else
echo "${SWIFT_LINT} is not installed. Please install it first from https://www.github.com/realm/SwiftLint"
exit 0
fi
END_DATE=$(date +"%s")
DIFF=$(($END_DATE - $START_DATE))
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete."
#----------------------------------------------------------------
# BUILD XCODE PROJECT & VALIDATE
#----------------------------------------------------------------
xcodebuild -quiet build -workspace DEV.xcworkspace -scheme "Build (iOS and macOS)"
if test $? -eq 0
then echo "Successful build"
else
echo "Your XCode build is Failed, for scheme "
exit 1
fi