This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·95 lines (75 loc) · 1.56 KB
/
deploy.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
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
#!/usr/bin/env bash
status=$(git status --porcelain -b 2> /dev/null)
Red="\e[0;31m"
Green="\e[0;32m"
Color_Off="\e[0m"
log_error() {
echo
echo -e "[${Red}ERR${Color_Off}] $1"
}
log_info() {
echo
echo -e "[${Green}LOG${Color_Off}] $1"
}
check_updated() {
local updated=$($1 | grep -q '^## .*behind')
if [ -n "$updated" ]; then
log_error "Your branch is out of date; Please make"
echo " git pull"
exit 1;
fi
}
get_branch() {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
restore() {
git checkout $branch
}
build() {
npm run build
}
commit() {
log_info "go to master"
git checkout master
git pull --rebase origin master
log_info "prepare files"
move_files
log_info "commit"
committed=$(git commit -m ':up:' | grep '^nothing to commit')
if [ -z "$committed" ]; then
git show HEAD --stat
else
log_error "nothing to commit"
exit 1
fi
}
move_files() {
for i in build/dist/*; do
local here=$(echo "${i#build/dist/}")
rm -Rf $here
mv $i .
git add $here
done
}
# Check if this branch is up-to-date
check_updated $status
# Save branch
branch=$(get_branch)
# Stash changes
git stash
# Prepare to build
build
commit
read -p "Deploy this changes? [Y/N]:" -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
log_error "You've canceled the deploy"
restore
exit 1
fi
git push
log_info "Deployed"
echo
restore