forked from jeremiahlukus/flutter_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
precommit
62 lines (49 loc) · 1.49 KB
/
precommit
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
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
printf "\e[33;1m%s\e[0m\n" 'Pre-Commit'
# Undo the stash of the files
pop_stash_files () {
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" '=== Applying git stash changes ==='
git stash pop
fi
}
# Stash unstaged files
hasChanges=$(git diff)
if [ -n "$hasChanges" ]; then
printf "\e[33;1m%s\e[0m\n" 'Stashing unstaged changes'
git stash push --keep-index
fi
# Flutter formatter
printf "\e[33;1m%s\e[0m\n" '=== Running Flutter Formatter ==='
flutter format lib test -l 120
# Flutter formatter
printf "\e[33;1m%s\e[0m\n" '=== Running Import Sorter ==='
flutter pub run import_sorter:main
hasNewFilesFormatted=$(git diff)
if [ -n "$hasNewFilesFormatted" ]; then
git add .
printf "\e[33;1m%s\e[0m\n" 'Formmated files added to git stage'
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter Formatter'
printf '%s\n' "${avar}"
# Flutter Analyzer
printf "\e[33;1m%s\e[0m\n" '=== Running Flutter analyzer ==='
flutter analyze
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Flutter analyzer error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Flutter analyzer'
printf '%s\n' "${avar}"
# Unit tests
printf "\e[33;1m%s\e[0m\n" '=== Running Unit Tests ==='
flutter test --test-randomize-ordering-seed random
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" '=== Unit tests error ==='
pop_stash_files
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running Unit Tests'
printf '%s\n' "${avar}"
pop_stash_files