make-release.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # Release management script for Wire Cell Toolkit.
4 
5 # Note, this is meant to create and operate on a throw-away source
6 # area. Do NOT use this on real working areas. Do NOT reuse this on
7 # areas used for past releases. If you do, all that you love will be
8 # torn and rent asunder and laid waste.
9 
10 # 1) Create release source area. This leaves the main repo and each
11 # submodule sitting at the tip of the given branch. This has many
12 # steps which can also be done individually. Warning: this hard-codes
13 # a list of submodules to purge out of the release so edit it in
14 # master before staring a release..
15 #
16 # $ ./make-release.sh bring-forward 0.5.x
17 #
18 # 2) If the master tips of each submodule are what is needed then tag
19 # everything and make a top level commit. Note, this commit is not
20 # pushed. Note: the source area is left in a slightly inconsistent
21 # state in that the submodule URLs are changed to HTTPS but no "git
22 # submodule sysnc" is done. This is so the push step can still go via
23 # SSH.
24 #
25 # $ ./make-release.sh apply-tags 0.5.x 0.5.0 "Some useful one liner describing major changes."
26 #
27 # 3) If happy, push all the changes
28 #
29 # $ ./make-release.sh push-everything 0.5.x
30 #
31 
32 #set -x
33 
34 function get-source
35 {
36  local target=$1 ; shift
37  if [ -d "$target" ] ; then
38  echo "source target exists in: $target"
39  return
40  fi
41  git clone git@github.com:WireCell/wire-cell-build.git $target
42 }
43 
44 function goto
45 {
46  local dir=${1?no directory given} ; shift
47  if [ ! -d $dir ] ; then
48  echo "No such directory: $dir"
49  exit 1
50  fi
51  pushd $dir >/dev/null
52 }
53 function goback
54 {
55  popd >/dev/null
56 }
57 
58 function make-branch
59 {
60  local branch=${1?must provide branch} ; shift
61  goto $branch
62 
63  if [ -n "$(git show-ref refs/heads/$branch)" ] ; then
64  echo "Already have local: $branch"
65  git checkout $branch
66  elif [ -n "$(git show-ref remotes/origin/$branch)" ] ; then
67  echo "Branch on origin: $branch"
68  git checkout -b $branch origin/$branch
69  else
70  echo "Initial creation of branch: $branch"
71  git checkout -b $branch origin/master
72  fi
73  goback
74 }
75 
76 function purge-submodules
77 {
78  local branch=${1?must provide branch} ; shift
79  goto $branch
80  local submodules=$@
81 
82  for sm in $submodules ; do
83  if [ -d $sm ] ; then
84  git submodule deinit $sm || exit 1
85  git rm $sm || exit 1
86  fi
87  done
88  goback
89 }
90 # alg bio dfp rio riodata rootdict rootvis tbb
91 
92 function branch-submodules
93 {
94  local branch=${1?must provide branch} ; shift
95  goto $branch
96 
97  git submodule init || exit 1
98  git submodule update || exit 1
99 
100  git submodule foreach "git checkout $branch || git checkout -b $branch --track origin/master"
101 
102  goback
103 }
104 
105 function update-submodules
106 {
107  local branch=${1?must provide branch} ; shift
108  goto $branch
109  git pull --recurse-submodules
110  goback
111 }
112 
113 function fix-dotgitmodules
114 {
115  local branch=${1?must provide branch} ; shift
116 
117  local org="WireCell"
118  local dev_url="git@github.com:$org"
119  local usr_url="https://github.com/$org"
120 
121  goto $branch
122 
123  # move to anon-friend URL for releases
124  sed -i -e 's|'$dev_url'|'$usr_url'|'g .gitmodules
125 
126  # Crazy hack to make sure .gitmodules is updated with new branch
127  # for each surviving submodule. There is probably a better way to
128  # do this!
129  git submodule foreach 'branch="$(git --git-dir=../.git rev-parse --abbrev-ref HEAD)"; sm="$(basename $(pwd))"; git config -f ../.gitmodules submodule.$sm.branch $branch'
130 
131  # Do NOT actually sync
132  #git submodule sync
133 
134  goback
135 }
136 
137 
138 # kitchen sink function
139 function bring-forward
140 {
141  local branch=${1?must give branch} ; shift
142 
143  echo -e "\ngetting source\n"
144  get-source $branch || exit 1
145 
146  echo -e "\nmaking top branch\n"
147  make-branch $branch ||exit 1
148 
149  unwanted_submodules="alg bio dfp rio riodata rootdict rootvis tbb"
150  echo -e "\npurging submodules: $unwanted_submodules\n"
151  purge-submodules $branch $unwanted_submodules
152 
153  echo -e "\nbranching submodules\n"
154  branch-submodules $branch
155 
156  echo -e "\nupdating submodules\n"
157  update-submodules $branch
158 
159  echo -e "\nswitch submodule URLs\n"
160  fix-dotgitmodules $branch
161 
162 
163  # fixme: specify which submodules to keep, purge all others
164  # fixme bonus1: hard code some (waftools, util, iface)
165  # fixme bonus2: figure out dependencies!
166 
167 }
168 # now do tag-submodules, push-submodules, submodule-urls, push-main
169 
170 function apply-submodule-tags
171 {
172  local branch=${1?must provide branch} ; shift
173  local tag=${1?must give branch} ; shift
174  local message="$@"
175 
176  goto $branch
177  git submodule foreach git tag -a -m "$message" $tag
178  goback
179 }
180 
181 
182 function commit-tag-main
183 {
184  local branch=${1?must provide branch} ; shift
185  local tag=${1?must give branch} ; shift
186  local message=${1?must give message} ; shift
187 
188  goto $branch
189  git commit -a -m "$message"
190  git tag -a -m "$message" "$tag"
191  goback
192 }
193 # now by hand: git push origin $branch
194 
195 
196 # kitchen sink function
197 function apply-tags
198 {
199  local branch=${1?must provide branch} ; shift
200  local tag=${1?must give tag} ; shift
201  local message="$@"
202 
203  echo -e "\napplying submodule tags\n"
204  apply-submodule-tags $branch $tag "$message"
205 
206  echo -e "\ncommitting and tagging top\n"
207  commit-tag-main $branch $tag "$message"
208 
209 }
210 
211 
212 # warning this pushes!
213 function push-everything
214 {
215  local branch=${1?must provide source directory aka branch} ; shift
216  goto $branch
217 
218  git submodule foreach git push origin $branch
219  git submodule foreach git push --tags
220 
221  git push origin $branch
222  git push --tags
223 
224  goback
225 }
226 
227 function tarball
228 {
229  local branch=${1?must give branch} ; shift
230  local tag=${1?must give tag} ; shift
231  local base=${1:-wire-cell-toolkit} ; shift
232  local name="${base}-${tag}"
233  local tarfile="${name}.tar.gz"
234 
235  if [ -f "$tarfile" ] ; then
236  echo "target tarball file exists, remove to continue: $tarfile"
237  return
238  fi
239  if [ -f "$name" ] ; then
240  echo "target directory exists, remove to continue: $name"
241  return;
242  fi
243 
244  git clone --recurse-submodules --branch=$branch \
245  git@github.com:WireCell/wire-cell-build.git \
246  $name
247 
248  cd $name
249  git checkout $tag
250  git submodule init
251  git submodule update
252  cd ..
253 
254  tar --exclude=.git* -czf $tarfile $name
255 
256  echo "when happy:"
257  echo "cp $tarfile /var/www/lar/software/releases"
258 }
259 
260 
261 "$@"
262