-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
deploy
executable file
·123 lines (110 loc) · 2.45 KB
/
deploy
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
##################################################################
##
## Publish package to pub.dev
##
## 1. Run test case
## 2. Run code coverage
## 3. Analyze package scores
## 4. Local publish --dry-run
## 5. Deploy to pub.dev
##
## Author: Chaobin Wu
## Email : chaobinwu89@gmail.com
##
#################################################################
tag='[Deploy]'
error() {
echo -e "\033[1m$tag\033[0m \033[31m$*\033[0m"
}
info() {
echo -e "\033[1m$tag\033[0m \033[32m$*\033[0m"
}
warning() {
echo -e "\033[1m$tag\033[0m \033[33m$*\033[0m"
}
die() {
error "$*"
exit 1
}
confirm() {
read -r -p "Looks great! Are you ready to continue (y/n)? " input
if [[ $input != 'y' ]]; then
die "Workflow terminated"
fi
}
# $1 = # of seconds
# $@ = What to print before "in n seconds"
countdown() {
secs=$1
shift
msg=$*
# shellcheck disable=SC2086
while [ $secs -gt 0 ]; do
printf "\r\033[K$msg in %.d seconds" $((secs--))
sleep 1
done
echo
}
checkHost() {
host=$1
info "$host/#home"
output=$(curl -IX HEAD "$host/#home")
c=$(grep -c "OK" <"$output")
if [ ! "$c" = "0" ]; then
print "$host"
fi
}
info "Start process workflow"
info "Step 1 Run test case with code coverage"
flutter pub get
if ! flutter test --coverage; then
die "Test failed"
fi
genhtml coverage/lcov.info --output=coverage
info "Step 2 Review code coverage report"
countdown 3 "Will open browser"
open coverage/index.html
confirm
info "Step 3 Evaluate with panahtml(Skipped)"
#panahtml &
#pid=$!
#info "run in background #$pid"
#sleep 3
#
#secs=1
#shift
## shellcheck disable=SC2086
#while [ $secs -gt 0 ]; do
# printf "\r\033[KWait until panahtml completes: %.d" $((secs++))
# count=$(lsof -nP -iTCP -sTCP:LISTEN | grep dart | grep -c 'LISTEN')
# if [ "$count" = "0" ]; then
# sleep 1
# else
# secs=0
# fi
#done
#echo
#
#read -r -p "Are you ready to continue (y/n)? " input
#kill -0 $pid
#
#if [[ $input != 'y' ]]; then
# die "Workflow terminated"
#fi
info "Step 4 Run publish --dry-run"
flutter pub publish --dry-run
confirm
info "Format project"
flutter format .
info "read pub.dev mirror site"
hostUrl=$PUB_HOSTED_URL
warning "PUB_HOSTED_URL=$PUB_HOSTED_URL"
info "remove environment variables"
export PUB_HOSTED_URL="https://pub.dev"
warning "PUB_HOSTED_URL=$PUB_HOSTED_URL"
info "Step 5 Publish to pub.dev"
flutter pub publish
info "reset environment variables"
export PUB_HOSTED_URL=$hostUrl
warning "PUB_HOSTED_URL=$PUB_HOSTED_URL"