build_release.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. #!/bin/bash
  2. # error out if any statements fail
  3. set -e
  4. #set -x
  5. function usage() {
  6. echo "$0 [options] <tag> <user> <email>"
  7. echo
  8. echo " tag : Release tag (eg: 2.14.4, 2.15-beta1, ...)"
  9. echo " user: Git username"
  10. echo " email: Git email"
  11. echo
  12. echo "Options:"
  13. echo " -h : Print usage"
  14. echo " -b <branch> : Branch to release from (eg: trunk, 2.14.x, ...)"
  15. echo " -r <rev> : Revision to release (eg: 12345)"
  16. echo " -g <ver> : GeoTools version/revision (eg: 20.4, master:12345)"
  17. echo " -w <ver> : GeoWebCache version/revision (eg: 1.14.4, 1.14.x:abcd)"
  18. echo
  19. echo "Environment variables:"
  20. echo " SKIP_BUILD : Skips main release build"
  21. echo " SKIP_COMMUNITY : Skips community release build"
  22. echo " SKIP_TAG : Skips tag on release branch"
  23. echo " SKIP_GT : Skips the GeoTools build, as used to build revision"
  24. echo " SKIP_GWC : Skips the GeoWebCache build, as used to build revision"
  25. echo " MAVEN_FLAGS : Used to supply additional option, like -U or -X to build process."
  26. }
  27. # parse options
  28. while getopts "hb:r:g:w:" opt; do
  29. case $opt in
  30. h)
  31. usage
  32. exit
  33. ;;
  34. b)
  35. branch=$OPTARG
  36. ;;
  37. r)
  38. rev=$OPTARG
  39. ;;
  40. g)
  41. gt_ver=$OPTARG
  42. ;;
  43. w)
  44. gwc_ver=$OPTARG
  45. ;;
  46. \?)
  47. usage
  48. exit 1
  49. ;;
  50. :)
  51. echo "Option -$OPTARG requires an argument"
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. # clear options to parse main arguments
  57. shift $(( OPTIND -1 ))
  58. tag=$1
  59. git_user=$2
  60. git_email=$3
  61. # sanity check
  62. if [ -z $tag ] || [ -z $git_user ] || [ -z $git_email ] || [ ! -z $4 ]; then
  63. usage
  64. exit 1
  65. fi
  66. # load properties + functions
  67. . "$( cd "$( dirname "$0" )" && pwd )"/properties
  68. . "$( cd "$( dirname "$0" )" && pwd )"/functions
  69. # more sanity checks
  70. if [ `is_version_num $tag` == "0" ]; then
  71. echo "$tag is a not a valid release tag"
  72. exit 1
  73. fi
  74. if [ `is_primary_branch_num $tag` == "1" ]; then
  75. echo "$tag is a not a valid release tag, can't be same as primary branch name"
  76. exit 1
  77. fi
  78. #checkout branch locally if it doesn't exist
  79. if ! git show-ref refs/heads/$branch; then
  80. echo "checkout branch #branch locally"
  81. git fetch origin $branch:$branch
  82. fi
  83. # ensure there is a jira release
  84. jira_id=`get_jira_id $tag`
  85. if [ -z $jira_id ]; then
  86. echo "Could not locate release $tag in JIRA"
  87. exit -1
  88. fi
  89. # move to root of source tree
  90. pushd .. > /dev/null
  91. dist=`pwd`/distribution/$tag
  92. mkdir -p $dist/plugins
  93. echo "Building release with following parameters:"
  94. echo " branch = $branch"
  95. echo " revision = $rev"
  96. echo " tag = $tag"
  97. echo " geotools = $gt_ver"
  98. echo " geowebcache = $gwc_ver"
  99. echo " jira id = $jira_id"
  100. echo " distribution = $dist"
  101. echo
  102. echo "maven/java settings:"
  103. mvn -version $MAVEN_FLAGS
  104. echo "maven opts:"
  105. echo "$MAVEN_OPTS"
  106. echo "maven flags:"
  107. echo "$MAVEN_FLAGS"
  108. echo "maven localRepository:"
  109. mvn help:evaluate $MAVEN_FLAGS -Dexpression=settings.localRepository -N --no-transfer-progress -B | grep -v '\[INFO\]'
  110. # clear out any changes
  111. git reset --hard HEAD
  112. # checkout and update primary branch
  113. git checkout $branch
  114. git pull origin $branch
  115. # check to see if a release branch already exists
  116. if [ `git branch --list rel_$tag | wc -l` == 1 ]; then
  117. echo "branch rel_$tag exists, deleting it"
  118. git branch -D rel_$tag
  119. fi
  120. # checkout the branch to release from
  121. git checkout $branch
  122. # ensure the specified revision actually on this branch
  123. if [ $rev != "HEAD" ]; then
  124. set +e
  125. git log | grep $rev
  126. if [ $? != 0 ]; then
  127. echo "Revision $rev not a revision on branch $branch"
  128. exit -1
  129. fi
  130. set -e
  131. fi
  132. # create a release branch
  133. git checkout -b rel_$tag $rev
  134. # setup geotools dependency
  135. if [ -z $SKIP_GT ]; then
  136. if [ ! -z $gt_ver ]; then
  137. # deterine if this is a revision or version number
  138. if [ "`is_version_num $gt_ver`" == "1" ]; then
  139. gt_tag=$gt_ver
  140. fi
  141. # if version specified as branch/revision check it out
  142. if [ -z $gt_tag ]; then
  143. arr=(${gt_ver//@/ })
  144. if [ "${#arr[@]}" != "2" ]; then
  145. echo "Bad version $gt_ver, must be specified as <branch>@<revision>"
  146. exit 1
  147. fi
  148. gt_branch=${arr[0]}
  149. gt_rev=${arr[1]}
  150. gt_dir=build/geotools/$gt_branch/$gt_rev
  151. if [ ! -e $gt_dir ]; then
  152. echo "cloning geotools repo from $GT_GIT_URL"
  153. git clone $GT_GIT_URL $gt_dir
  154. fi
  155. # checkout branch/rev
  156. pushd $gt_dir > /dev/null
  157. echo "checking out geotools ${gt_branch}@${gt_rev}"
  158. git checkout $gt_rev
  159. # build geotools
  160. mvn clean install $MAVEN_FLAGS -Dall -DskipTests
  161. popd > /dev/null
  162. # derive the gt version
  163. gt_tag=`get_pom_version $git_dir/pom.xml`
  164. fi
  165. fi
  166. fi
  167. if [ ! -z $gt_tag ]; then
  168. echo "GeoTools version = $gt_tag"
  169. fi
  170. # update geotools version
  171. if [ ! -z $gt_tag ]; then
  172. sed -i "s/\(<gt.version>\).*\(<\/gt.version>\)/\1$gt_tag\2/g" src/pom.xml
  173. else
  174. # look up from pom instead
  175. gt_tag=`cat src/pom.xml | grep "<gt.version>" | sed 's/ *<gt.version>\(.*\)<\/gt.version>/\1/g'`
  176. fi
  177. # setup geowebcache dependency
  178. if [ -z $SKIP_GWC ]; then
  179. if [ ! -z $gwc_ver ]; then
  180. # deterine if this is a revision or version number
  181. if [ "`is_version_num $gwc_ver`" == "1" ]; then
  182. gwc_tag=$gwc_ver
  183. fi
  184. # if version specified as branch/revision check it out
  185. if [ -z $gwc_tag ]; then
  186. arr=(${gwc_ver//@/ })
  187. if [ "${#arr[@]}" != "2" ]; then
  188. echo "Bad version $gwc_ver, must be specified as <branch>:<revision>"
  189. exit 1
  190. fi
  191. gwc_branch=${arr[0]}
  192. gwc_rev=${arr[1]}
  193. gwc_dir=build/geowebcache/$gwc_branch/$gwc_rev
  194. if [ ! -e $gwc_dir -o ! -e $gwc_dir/geowebcache ]; then
  195. rm -rf $gwc_dir
  196. mkdir -p $gwc_dir
  197. echo "checking out geowebache ${gwc_branch}@${gwc_rev}"
  198. git clone $GWC_GIT_URL $gwc_dir
  199. pushd $gwc_dir > /dev/null
  200. git checkout $gwc_rev
  201. popd > /dev/null
  202. fi
  203. # build geowebache
  204. pushd $gwc_dir/geowebcache > /dev/null
  205. mvn clean install $MAVEN_FLAGS -DskipTests
  206. # derive the gwc version
  207. gwc_tag=`get_pom_version pom.xml`
  208. popd > /dev/null
  209. fi
  210. fi
  211. fi
  212. if [ ! -z $gwc_tag ]; then
  213. echo "GeoWebCache version = $gwc_tag"
  214. fi
  215. # update geowebcache version
  216. if [ ! -z $gwc_tag ]; then
  217. sed -i "s/\(<gwc.version>\).*\(<\/gwc.version>\)/\1$gwc_tag\2/g" src/pom.xml
  218. else
  219. gwc_tag=`cat src/pom.xml | grep "<gwc.version>" | sed 's/ *<gwc.version>\(.*\)<\/gwc.version>/\1/g'`
  220. fi
  221. # update version numbers
  222. old_ver=`get_pom_version src/pom.xml`
  223. echo "updating version numbers from $old_ver to $tag"
  224. find src -name pom.xml -exec sed -i "s/$old_ver/$tag/g" {} \;
  225. find doc -name conf.py -exec sed -i "s/$old_ver/$tag/g" {} \;
  226. find doc -name pom.xml -exec sed -i "s/$old_ver/$tag/g" {} \;
  227. pushd src/release > /dev/null
  228. shopt -s extglob
  229. # sed -i "s/$old_ver/$tag/g" !(pom).xml installer/win/*.nsi installer/win/*.conf
  230. shopt -u extglob
  231. popd > /dev/null
  232. pushd src > /dev/null
  233. # build the release
  234. if [ -z $SKIP_BUILD ]; then
  235. echo "building release"
  236. mvn clean install $MAVEN_FLAGS -DskipTests -P release
  237. # build the javadocs
  238. mvn javadoc:aggregate $MAVEN_FLAGS
  239. ##################
  240. # Build the docs
  241. ##################
  242. pushd ../doc/en > /dev/null
  243. # ant clean user -Dproject.version=$tag
  244. # ant user-pdf -Dproject.version=$tag
  245. # ant developer -Dproject.version=$tag
  246. mvn clean compile $MAVEN_FLAGS
  247. mvn package $MAVEN_FLAGS
  248. popd > /dev/null
  249. else
  250. echo "Skipping mvn clean install $MAVEN_FLAGS -DskipTests -P release"
  251. fi
  252. if [ -z $SKIP_COMMUNITY ]; then
  253. pushd community > /dev/null
  254. set +e
  255. mvn clean install $MAVEN_FLAGS -P communityRelease -DskipTests || true
  256. set -e
  257. popd > /dev/null
  258. else
  259. echo "Skipping mvn clean install $MAVEN_FLAGS -P communityRelease -DskipTests"
  260. fi
  261. echo "Assemble artifacts"
  262. mvn assembly:single $MAVEN_FLAGS -N
  263. artifacts=`pwd`/target/release
  264. echo "artifacts = $artifacts"
  265. # bundle up mac and windows installer stuff
  266. pushd release/installer/mac > /dev/null
  267. zip -q -r $artifacts/geoserver-$tag-mac.zip *
  268. popd > /dev/null
  269. pushd release/installer/win > /dev/null
  270. zip -q -r $artifacts/geoserver-$tag-win.zip *
  271. popd > /dev/null
  272. pushd $artifacts > /dev/null
  273. htmldoc=geoserver-$tag-htmldoc.zip
  274. if [ -e ../../../doc/en/target/$htmldoc ]; then
  275. echo "Using $htmldoc assembly"
  276. # use assembly
  277. cp ../../../doc/en/target/$htmldoc $htmldoc
  278. else
  279. echo "Creating $htmldoc"
  280. # setup doc artifacts
  281. if [ -e user ]; then
  282. unlink user
  283. fi
  284. if [ -e developer ]; then
  285. unlink developer
  286. fi
  287. ln -sf ../../../doc/en/target/user/html user
  288. ln -sf ../../../doc/en/target/developer/html developer
  289. ln -sf ../../../doc/en/release/README.txt readme
  290. if [ -e $htmldoc ]; then
  291. rm -f $htmldoc
  292. fi
  293. zip -q -r $htmldoc user developer readme
  294. unlink user
  295. unlink developer
  296. unlink readme
  297. fi
  298. popd > /dev/null
  299. # stage distribution artifacts
  300. echo "copying artifacts to $dist"
  301. cp $artifacts/*-plugin.zip $dist/plugins
  302. for a in `ls $artifacts/*.zip | grep -v plugin`; do
  303. cp $a $dist
  304. done
  305. cp $artifacts/../../../doc/en/target/user/latex/manual.pdf $dist/geoserver-$tag-user-manual.pdf || true
  306. echo "generated artifacts:"
  307. ls -la $dist
  308. # git commit changes on the release branch
  309. pushd .. > /dev/null
  310. init_git $git_user $git_email
  311. git add doc
  312. git add src
  313. git commit -m "updating version numbers and release notes for $tag" .
  314. # tag release branch
  315. if [ -z $SKIP_TAG ]; then
  316. # fetch single tag, don't fail if its not there
  317. git fetch origin refs/tags/$tag:refs/tags/$tag --no-tags || true
  318. # check to see if tag already exists
  319. if [ `git tag --list $tag | wc -l` == 1 ]; then
  320. echo "tag $tag exists, deleting it"
  321. git tag -d $tag
  322. fi
  323. if [ `git ls-remote --refs --tags origin tags/$tag | wc -l` == 1 ]; then
  324. echo "tag $tag exists on $GIT_ROOT, deleting it"
  325. git push --delete origin $tag
  326. fi
  327. # tag the release branch
  328. git tag $tag
  329. # push up tag
  330. git push origin $tag
  331. fi
  332. popd > /dev/null
  333. popd > /dev/null
  334. echo "build complete, artifacts available at $DIST_URL/distribution/$tag"
  335. exit 0