-
Notifications
You must be signed in to change notification settings - Fork 15
/
swiftlint.sh
executable file
·53 lines (42 loc) · 1.72 KB
/
swiftlint.sh
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
53
#!/bin/bash
if [ -z "$CI" ]; then
export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
set -e
BASEDIR=$(dirname "$0") # Sets the folder to WeTransfer-iOS-CI/BuildTools/
MINT_FILE_PATH=$BASEDIR/Mintfile
SWIFT_LINT=SwiftLint
SWIFT_LINT_VERSION=$(grep -F $SWIFT_LINT $MINT_FILE_PATH)
if ! xcrun --sdk macosx mint which -s $SWIFT_LINT_VERSION > /dev/null; then
xcrun --sdk macosx mint bootstrap -m $MINT_FILE_PATH
fi
execution_directory="$(pwd)"
count=0
export SRCROOT="$(pwd)"
printf "\nExecuting SwiftLint from ${execution_directory}\n"
# Unstaged files
while read filename; do
export SCRIPT_INPUT_FILE_$count="${filename}"
echo "Found '${filename}'"
count=$((count + 1))
done < <(git diff --relative --name-only $SRCROOT | grep ".swift$")
# Staged files
while read filename; do
export SCRIPT_INPUT_FILE_$count="${filename}"
echo "Found '${filename}'"
count=$((count + 1))
done < <(git diff --relative --diff-filter=d --cached --name-only $SRCROOT | grep ".swift$")
# Committed files
while read filename; do
export SCRIPT_INPUT_FILE_$count="${filename}"
echo "Found '${filename}'"
count=$((count + 1))
done < <(git diff develop... --relative --diff-filter=d --name-only $SRCROOT | grep ".swift$")
export SCRIPT_INPUT_FILE_COUNT=$count
if (( $count > 0 )); then
echo "Found ${count} lintable files! Linting..."
xcrun --sdk macosx mint run -m $MINT_FILE_PATH $SWIFT_LINT lint --use-script-input-files --config "$BASEDIR/.swiftlint.yml" --force-exclude || true;
else
echo "No files to lint, the number of files found is $count"
exit 0
fi
fi