-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathprocess.sh
executable file
·43 lines (37 loc) · 1.38 KB
/
process.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
#!/bin/sh
#
# Based on https://merowing.info/2021/01/improve-build-times-by-extracting-3rd-party-tooling-to-processing-script./
cd "$(dirname "$0")/.."
if [[ "$1" == "--staged" ]]; then
staged_mode=true
echo "Running in --staged mode"
else
echo "Running in full mode"
fi
final_status=0
function process_output() {
printf '\n# Running %s\n' "$1"
local start=$(date +%s)
local output=$(eval "$2" 2>&1)
local cleaned_output=$(echo "$output" | sed '/.*xcodebuild.*/d')
if [[ ! -z "$cleaned_output" ]]; then
printf -- '---\n%s\n---\n' "$cleaned_output"
final_status=1
fi
local end=$(date +%s)
printf 'Execution time was %s seconds.\n' "$((end - start))"
}
if [ "$staged_mode" = true ]; then
process_output "SwiftFormat" "python3 ./Scripts/git-format-staged.py -f 'swiftformat stdin --stdinpath \"{}\" --quiet' '*.swift'"
process_output "SwiftLint" "python3 ./Scripts/git-format-staged.py --no-write -f 'swiftlint --use-stdin --quiet >&2' '*.swift'"
if [[ "$final_status" -gt 0 ]]; then
printf '\nChanges werde made or are required. Please review the output above for further details.\n'
fi
else
process_output "SwiftFormat" "swiftformat --lint --quiet ."
process_output "SwiftLint" "swiftlint --quiet ."
if [[ "$final_status" -gt 0 ]]; then
printf '\nChanges are required. Please review the output above for further details.\n'
fi
fi
exit $final_status