/
deploy.sh
executable file
·77 lines (63 loc) · 1.88 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
#!/bin/bash
function check_git() {
print_step "Checking git"
git --version \
|| print_error "Git is not installed"
}
function check_maven() {
print_step "Checking Apache Maven"
mvn --version \
|| print_error "Apache Maven is not installed"
}
function check_directory_is_clean() {
print_step "Check directory is clean"
local changed_files_count
changed_files_count=$(git status --porcelain | wc --lines)
test "$changed_files_count" -eq 0 \
|| print_error "Working directory is not clean (contains uncommited changes)"
}
function check_branch_is_master() {
print_step "Check branch is master"
local current_branch
current_branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
test "$current_branch" = "master" \
|| print_error "Current branch is not master"
}
function ask_confirmation_on_deploy() {
printf "\nAre you sure you want to perform deploy? (yes/no):\n"
local answer
read answer
test "$answer" = "yes" \
|| print_error "Deploy canceled"
}
function perform_deploy() {
echo "Starting deployment"
mvn -B -P release,api-javadoc release:clean release:prepare
publish_online_javadoc
mvn -B -P release release:perform
}
function publish_online_javadoc() {
print_step "Publish online Javadoc"
cd processor/target/apidocs
git init
git remote add javadoc git@github.com:alex-zuy/boilerplate-generator.git
git fetch --depth=1 javadoc gh-pages
git add --all
git commit -m "Update javadoc"
git merge --no-edit -s ours remotes/javadoc/gh-pages
git push javadoc master:gh-pages
cd -
}
function print_step() {
printf "\n# $1\n"
}
function print_error() {
echo "Error: " $1
false
}
check_git \
&& check_maven \
&& check_directory_is_clean \
&& check_branch_is_master \
&& ask_confirmation_on_deploy \
&& perform_deploy