forked from JeffersonLab/coatjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-coatjava.sh
More file actions
executable file
·221 lines (195 loc) · 6.25 KB
/
deploy-coatjava.sh
File metadata and controls
executable file
·221 lines (195 loc) · 6.25 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
# deploy a new release of coatjava
set -euo pipefail
# constants
src_dir=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd -P)
deploy_dir=$src_dir/myLocalMvnRepo
main_branch=development
deployment_user=clas12
deployment_host=jlabl1
# printouts for this script (different from Maven printouts)
log() { echo ">>> $@"; }
# arguments
ver_deploy=''
snap_deploy=false
dry_run=false
use_git=true
# usage guide
usage() {
echo """
USAGE: $0 [OPTIONS]...
CHECKLIST BEFORE RUNNING:
- [ ] be on git branch '$main_branch'
- [ ] be up-to-date ('git pull')
- [ ] have no local changes ('git status')
REQUIRED OPTIONS:
-v VERSION set the version number to deploy
OPTIONAL OPTIONS:
--no-git do not involve 'git' and ignore CHECKLIST satisfaction
--dry-run do not deploy to remote servers; applies '--no-git'
--snap deploy as 'VERSION-SNAPSHOT'; applies '--no-git'
-h,--help show this usage guide
EFFECT (default):
- deploys new release as version 'VERSION'
- bumps repo version number to 'VERSION-SNAPSHOT'
- creates git branch and commit for bump
"""
}
# parse arguments
if [ $# -eq 0 ]; then
usage
exit 2
fi
while getopts "v:h-:" opt; do
case $opt in
v)
ver_deploy=$OPTARG
;;
h)
usage
exit 2
;;
-)
case $OPTARG in
no-git)
use_git=false
;;
snap)
snap_deploy=true
use_git=false
;;
dry-run)
dry_run=true
use_git=false
;;
help)
usage
exit 2
;;
*)
echo "ERROR: unknown option '$OPTARG'" >&2
exit 1
esac
;;
*)
exit 1
;;
esac
done
# be in the top-level source directory
cd $src_dir
# make sure the deployment directory is empty
if [ -d "$deploy_dir" ]; then
echo "ERROR: deployment directory already exists: $deploy_dir" >&2
echo " please remove it (so the deployment will be clean)" >&2
exit 1
fi
# handle version number
[ -z "$ver_deploy" ] && echo "ERROR: version number not specified" >&2 && exit 1
ver_deploy=$(echo $ver_deploy | sed 's;-SNAPSHOT;;g')
ver_snapshot=$ver_deploy-SNAPSHOT
if $snap_deploy; then ver_deploy=$ver_snapshot; fi
ver_current=$($src_dir/libexec/version.sh)
log "========================"
log "CURRENT VERSION = $ver_current"
log "SNAPSHOT VERSION = $ver_snapshot"
log "DEPLOY VERSION = $ver_deploy"
log "========================"
# if using git, make a new branch
new_branch=version/$ver_deploy
if $use_git; then
log "create git branch '$new_branch'"
# verify user is on the main branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "$main_branch" ]; then
echo """ERROR: you are currently on branch '$current_branch', but you should be on branch '$main_branch'.
Please switch to branch '$main_branch' and (preferably) run 'git pull'.""" >&2
exit 1
fi
# switch to a new branch for this new version
git switch -c $new_branch
fi
# change the version number, if different
# NOTE: `maven-release-plugin` could be used to better automate the versioning
# here, but since this deployment is _only_ done in the `coat-libs` POM (the
# shaded JAR), and we also want to make a tarball with _all_ of the POMs at the
# correct version number, we may as well do the version bump here
if [ "$ver_current" != "$ver_deploy" ]; then
log "change version number $ver_current -> $ver_deploy"
$src_dir/libexec/version-bump.sh $ver_deploy
fi
# rebuild coatjava, cleanly, to be sure we deploy the correct version
log "cleanly rebuild coatjava"
$src_dir/build-coatjava.sh --clean
$src_dir/build-coatjava.sh
# deploy locally; no need to `clean deploy`, since we have already cleaned and re-built
log "local deployment of coatjava version $ver_deploy"
pom_files=(
$src_dir/common-tools/coat-libs/pom.xml
$src_dir/reconstruction/pom.xml
)
for pom_file in ${pom_files[@]}; do
mvn deploy -Dmaven.test.skip=true -f $pom_file
done
# make a tarball too
deploy_tarball=coatjava-${ver_deploy}.tar.gz
tar czf $deploy_tarball coatjava
# say what we did
print_deployment() {
log "========================"
log "local deployments:"
log " $deploy_dir"
log " $deploy_tarball"
log "========================"
}
print_deployment
# deploy remotely
if ! $dry_run; then
log "now deploying..."
scp -r $deploy_dir/org/jlab/coat/coat-libs/* $deployment_user@$deployment_host:/group/clas/www/clasweb/html/clas12maven/org/jlab/coat/coat-libs/.
scp -r $deploy_dir/org/jlab/clas12/detector/* $deployment_user@$deployment_host:/group/clas/www/clasweb/html/clas12maven/org/jlab/clas12/detector/.
scp $deploy_tarball $deployment_user@$deployment_host:/group/clas/www/clasweb/html/clas12offline/distribution/coatjava/.
log "...done"
else
log "dry run, not doing remote deployment"
fi
# change the version number to snapshot version
if ! $dry_run; then
if [ "$ver_deploy" != "$ver_snapshot" ]; then
log "change version number $ver_deploy -> $ver_snapshot"
$src_dir/libexec/version-bump.sh $ver_snapshot
fi
else # revert the version number, if this was a dry run
# FIXME: it won't really be a dry run if some step above failed...
# just use git to fix that
if [ "$ver_deploy" != "$ver_current" ]; then
log "since this is a dry run, revert version number $ver_deploy -> $ver_current"
$src_dir/libexec/version-bump.sh $ver_current
fi
fi
# print what was done, and remove your local deployment directory so the next
# deployment doesn't clobber old deployments
print_deployment
if $dry_run; then
log "this was just a dry run"
log " - nothing was deployed remotely"
log " - the version number was NOT bumped"
else
log "version $ver_deploy has been deployed!"
fi
# git commit
if $use_git; then
echo """
============================================"""
git commit -am "build: bump version number to $ver_deploy"
echo """Done.
Currently on branch $new_branch
Now run your usual 'git push' command, which is probably:
git push -u origin $new_branch
============================================
"""
elif ! $dry_run; then
log "Option '--no-git' was used and this is not a dry run;"
log "the version number may have been changed (run 'git status')."
log "Use 'libexec/version-bump.sh' if you need to revert the version number."
fi