-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
executable file
·96 lines (75 loc) · 1.82 KB
/
release.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
96
#!/bin/bash
usage () {
cat <<EOM
Usage:
$(basename $0) [tag-name] [deploy]
EOM
# exit 0
}
print_command_header () {
printf "\n##\n# LIGHT-MESSENGER: $1\n##\n"
}
check_command_success () {
if [ $? -ne 0 ]
then
print_command_header "$1 failed"
exit 1
fi
}
release_tag () {
tag=$1
print_command_header "push changes"
git push origin
check_command_success "push"
print_command_header "tagging $tag"
git tag $tag
check_command_success "creating git tag"
print_command_header "pushing git tag"
git push origin $tag
check_command_success "pushing git tag"
}
release_deploy () {
print_command_header "stop service"
ssh nofasy@radmon 'sudo systemctl stop light-messenger'
check_command_success "stop current service"
print_command_header "copy binary"
scp ./light-messenger.exec nofasy@radmon:~/light-messenger-dist/
check_command_success "scp"
print_command_header "start service"
ssh nofasy@radmon 'sudo systemctl start light-messenger'
check_command_success "start service"
print_command_header "status service"
ssh nofasy@radmon 'sudo systemctl status light-messenger'
check_command_success "status service"
}
##
# - check for any modified / untracked files
# - check that all tests pass
# - check release tag is provided and tag release if yes
# - check if deploy tag is provided and deploy if yes
##
if [[ $(git diff --stat) != '' ]]; then
printf "modified / untracked files\n"
exit 1
fi
print_command_header "run tests"
make test
check_command_success "tests"
arg_tag=$1
arg_deploy=$2
if [[ $arg_tag ]]
then
release_tag "$arg_tag"
print_command_header "build"
make build
check_command_success "build"
if [[ $arg_deploy ]]
then
release_deploy
else
printf "No deploy tag provided\n"
fi
else
printf "require tag name\n"
fi
printf "done\n"