From: <svn...@os...> - 2012-05-30 03:24:41
|
Author: jdeolive Date: 2012-05-29 20:24:31 -0700 (Tue, 29 May 2012) New Revision: 38778 Added: trunk/build/release/ trunk/build/release/build_release.sh trunk/build/release/functions trunk/build/release/jira_release.py trunk/build/release/properties trunk/build/release/publish_release.sh Modified: trunk/build/rename.xml Log: adding automated release scripts Added: trunk/build/release/build_release.sh =================================================================== --- trunk/build/release/build_release.sh (rev 0) +++ trunk/build/release/build_release.sh 2012-05-30 03:24:31 UTC (rev 38778) @@ -0,0 +1,184 @@ +#!/bin/bash + +# error out if any statements fail +set -e +set -x + +function usage() { + echo "$0 [options] <tag>" + echo + echo " tag : Release tag (eg: 2.7.5, 8.0-RC1, ...)" + echo + echo "Options:" + echo " -h : Print usage" + echo " -b <branch> : Branch to release from (eg: trunk, 2.1.x, ...)" + echo " -r <rev> : Revision to release (eg: 12345)" + echo + echo "Environment variables:" + echo " BUILD_FROM_BRANCH : Builds release from branch rather than tag" + echo " SKIP_SVN_TAG : Skips creation of svn tag" + echo " SKIP_BUILD : Skips main release build" +} + +# parse options +while getopts "hb:r:" opt; do + case $opt in + h) + usage + exit + ;; + b) + branch=$OPTARG + ;; + r) + rev=$OPTARG + ;; + \?) + usage + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument" + exit 1 + ;; + esac +done + +# clear options to parse main arguments +shift $(( OPTIND -1 )) +tag=$1 + +# sanity check +if [ -z $tag ] || [ ! -z $2 ]; then + usage + exit 1 +fi + +# load properties + functions +. "$( cd "$( dirname "$0" )" && pwd )"/properties +. "$( cd "$( dirname "$0" )" && pwd )"/functions + +echo "Building release with following parameters:" +echo " branch = $branch" +echo " revision = $rev" +echo " tag = $tag" + +mvn -version + +if [ ! -z $BUILD_FROM_BRANCH ]; then + if [ ! -e tags/$tag ]; then + if [ "$branch" == "trunk" ]; then + svn_url=$SVN_ROOT/trunk + else + svn_url=$SVN_ROOT/branches/$branch + fi + + echo "checking out $svn_url" + svn co $svn_url tags/$tag + fi +else + # check if the svn tag already exists + if [ -z $SKIP_SVN_TAG ]; then + set +e && svn ls $SVN_ROOT/tags/$tag >& /dev/null && set -e + if [ $? == 0 ]; then + # tag already exists + # TODO: delete it automatically... + echo "svn tag $tag already exists, delete before proceeding" + exit 1 + fi + + # create svn tag + revopt="-r $rev" + if [ "$rev" == "latest" ]; then + revopt="" + fi + + echo "svn cp -m "tagging $tag" $revopt $SVN_ROOT/$branch $SVN_ROOT/tags/$tag" + + # checkout newly created tag + if [ -e tags/$tag ]; then + # remove old checkout + rm -rf tags/$tag + fi + + echo "checking out tag $tag" + svn co $SVN_ROOT/tags/$tag tags/$tag + fi +fi + +if [ ! -z $SKIP_SVN_TAG ] || [ ! -z $BUILD_FROM_BRANCH ]; then + echo "updating tag $tag" + svn revert --recursive tags/$tag + svn up tags/$tag +fi + +# update the rename script +# generate release notes +jira_id=`get_jira_id $tag` +if [ -z $jira_id ]; then + echo "Could not locate release $tag in JIRA" + exit -1 +fi + +pushd tags/$tag > /dev/null + +# update versions +pushd build > /dev/null +sed -i 's/@VERSION@/'$tag'/g' rename.xml +ant -f rename.xml +popd > /dev/null + +# build the release +if [ -z $SKIP_BUILD ]; then + echo "building release" + mvn $MAVEN_FLAGS -Dall clean + mvn $MAVEN_FLAGS -DskipTests install +fi + +pushd target > /dev/null +bin=geotools-$tag-bin.zip +unzip $bin +cd geotools-$tag +rm junit*.jar +rm *dummy-* +cd .. +rm $bin +zip -r $bin geotools-$tag +rm -rf geotools-$tag +popd > /dev/null + +target=`pwd`/target + +# build the javadocs +pushd modules > /dev/null +mvn javadoc:aggregate +pushd target/site > /dev/null +zip -r $target/geotools-$tag-doc.zip apidocs +popd > /dev/null +popd > /dev/null + +# build the user docs +pushd docs > /dev/null +mvn $MAVEN_FLAGS install +pushd target/user > /dev/null +zip -r $target/geotools-$tag-userguide.zip html +popd > /dev/null +popd > /dev/null + +# copy over the artifacts +if [ ! -e $DIST_PATH ]; then + mkdir -p $DIST_PATH +fi +dist=$DIST_PATH/$tag +if [ -e $dist ]; then + rm -rf $dist +fi +mkdir $dist + +echo "copying artifacts to $dist" +cp $target/*.zip $dist + +popd > /dev/null + +echo "build complete, artifacts available at $DIST_URL/$tag" +exit 0 Property changes on: trunk/build/release/build_release.sh ___________________________________________________________________ Added: svn:executable + * Added: trunk/build/release/functions =================================================================== --- trunk/build/release/functions (rev 0) +++ trunk/build/release/functions 2012-05-30 03:24:31 UTC (rev 38778) @@ -0,0 +1,97 @@ +# common functions + +# get_file <base_url> <file> <dir> +# downlaods file from $base_url/$file into directory $dir +function get_file() { + local base_url=$1 + local file=$2 + local dir=$3 + + if [ ! -e $dir ]; then + mkdir $dir + fi + if [ -e $dir/$file ]; then + rm $dir/$file + fi + pushd $dir > /dev/null + wget $base_url/$file + popd > /dev/null +} + +# setup_artifacts <tag> <suffix> +# downloads artifacts to build installer: +# 1. geoserver bin artifact +# 2. installer specific artifact specified by <suffix> +# files are unpacked into tmp directory +function setup_artifacts() { + local tag=$1 + local suf=$2 + + local gs_artifact=geoserver-$tag-bin.zip + local installer_artifact=geoserver-$tag-$suf.zip + + if [ -z $SKIP_DOWNLOAD ]; then + get_file $DIST_URL/$tag $gs_artifact files + get_file $DIST_URL/$tag $installer_artifact files + fi + + # unpack the artifacts + if [ -e tmp ]; then + rm -rf tmp + fi + mkdir -p tmp + + unzip -d tmp files/$installer_artifact + unzip -d tmp files/$gs_artifact +} + +# upload_installer <tag> <file> +# uploads file <file> to distribution server under tag <tag> +function upload_installer() { + local tag=$1 + local file=$2 + local ssh_opts="-i $DIST_PK -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + + if [ -z $SKIP_UPLOAD ]; then + echo "uploading $file" + scp $ssh_opts -P $DIST_PORT $file $DIST_USER@$DIST_HOST:$DIST_PATH/$tag + fi +} + +# start_installer_job <hudson_url> <tag> +# starts a hudson installer job +function start_installer_job() { + curl -k --connect-timeout 10 "$1/job/geoserver-installer/buildWithParameters?TAG=$2" +} + +# is_version_nuym <str> +# tests a string to see if it is a x.y.z or x.y-z style version number +function is_version_num() { + local str=$1 + if [ "$( echo $str | egrep "[0-9]+\.[0-9]+((\.|-).*)?" )" == "$str" ]; then + echo "1" + else + if [ "$( echo $str | egrep "[0-9]+-.*" )" == "$str" ]; then + echo "1" + else + echo "0" + fi + fi +} + +# get_pom_version <pom> +# gets the version declared in a pom file +function get_pom_version() { + local pom=$1 + echo `grep "<version>" $pom | head -n 1 | sed 's/<.*>\(.*\)<\/.*>/\1/g' | sed 's/ //g'` +} + +# get_jira_id <tag> +# gets the jira id for a version named <tag> +function get_jira_id() { + local tag=$1 + local jira_id=`curl -s -G $JIRA_REST/project/$JIRA_PROJ/versions | tr "{" "\n" | grep $tag | tr "," "\n" | grep "\"id\"" | sed 's/"id": *\([0-9]*\).*/\1/g'` + if [ ! -z $jira_id ]; then + echo $jira_id + fi +} Added: trunk/build/release/jira_release.py =================================================================== --- trunk/build/release/jira_release.py (rev 0) +++ trunk/build/release/jira_release.py 2012-05-30 03:24:31 UTC (rev 38778) @@ -0,0 +1,128 @@ +import sys, optparse, getpass +import SOAPpy, SOAPpy.Types + +class JIRA(object): + + def __init__(self, jira_host, proj, user, passwd): + self.proj = proj + self.soap = SOAPpy.WSDL.Proxy( + '%s/rpc/soap/jirasoapservice-v2?wsdl'%jira_host) + self.auth = self.soap.login(user, passwd) + + + def list_methods(self): + for m in self.soap.methods.keys(): + print m + + def describe_method(self, name): + m = self.soap.methods[name] + for p in m.inparams: + print p.name.ljust(10), p.type + + def list_versions(self): + versions = self.soap.getVersions(self.auth, self.proj) + return [v.name for v in versions] + + def is_version_released(self, name): + versions = self.soap.getVersions(self.auth, self.proj) + for v in versions: + if v.name == name: + return v.released + + def get_version_id(self, name): + """ + Return the id for a named version, returning None if no such version exists. + """ + versions = self.soap.getVersions(self.auth, self.proj) + for v in versions: + if v.name == name: + return v.id + + def create_version(self, name): + """ + Creates a new version with the specified name. + """ + self.soap.addVersion(self.auth, self.proj, {'name': name}) + + def get_open_issues(self, ver_name): + """ + Returns keys for unresolved/open issues for the specified version name. + """ + jql = 'project = %s and status in (Open, "In Progress", Reopened) and fixVersion = "%s"' % (self.proj, ver_name) + n = SOAPpy.Types.intType(500) + issues = self.soap.getIssuesFromJqlSearch(self.auth, jql, n) + return [i.key for i in issues] + + def set_fixed_version(self, issue, ver_name): + """ + Sets the fixVersion for an issue + """ + ver_id = self.get_version_id(ver_name) + if ver_id: + self.soap.updateIssue(self.auth, issue, + [{'id': 'fixVersions', 'values': [ver_id]}]) + + def release_version(self, ver_name): + self.soap.releaseVersion(self.auth, self.proj, + {'name': ver_name, "released": True}) + +if __name__ == "__main__": + + p = optparse.OptionParser('Usage: %prog [options] version next_version') + p.add_option('-j', '--host', dest='host', default='http://jira.codehaus.org', + help='JIRA host, default is codehaus') + p.add_option('-k', '--key', dest='key', default='GEOS', + help='JIRA project key, default is GEOS') + p.add_option('-u', '--user', dest='user', default=getpass.getuser(), + help='JIRA user, default is current OS user') + p.add_option('-p', '--passwd', dest='passwd', + help='JIRA password') + p.add_option('-v', '--verbose', dest='verbose', action='store_true', + help='Verbose flag') + + opts, args = p.parse_args() + if len(args) < 2: + p.error('Must specify version to release and next version') + + opts = vars(opts) + jira = JIRA(opts['host'], opts['key'], opts['user'], opts['passwd']) + + verbose = opts['verbose'] + ver = args[0] + next_ver = args[1] + + if not jira.get_version_id(ver): + sys.exit('Version %s does not exist in JIRA' % ver) + + if jira.is_version_released(ver) == True: + print 'Version %s is already released in JIRA, exiting' % ver + sys.exit(0) + + if not jira.get_version_id(next_ver): + # create id + print 'creating version %s in JIRA' % next_ver + jira.create_version(next_ver) + + if not jira.get_version_id(next_ver): + sys.exit('Unable to create version %s in JIRA' % next_ver) + + # move over all open issues from old to new + x = 0 + while x < 100: + issues = jira.get_open_issues(ver) + if len(issues) == 0: + break + + for i in jira.get_open_issues(ver): + if verbose == True: + print 'Setting fix version of %s to %s' % (i, next_ver) + jira.set_fixed_version(i, next_ver) + x += 1 + + # check all versions were moved + if len(jira.get_open_issues(ver)) > 0: + sys.exit('Unable to move back all issues to version %s' % next_ver) + + # mark the version as released + print 'Releasing %s in JIRA' % ver + jira.release_version(ver) Added: trunk/build/release/properties =================================================================== --- trunk/build/release/properties (rev 0) +++ trunk/build/release/properties 2012-05-30 03:24:31 UTC (rev 38778) @@ -0,0 +1,49 @@ + +# as environment variables + +# constants +SVN_ROOT=http://svn.osgeo.org/geotools +JIRA_REST=http://jira.codehaus.org/rest/api/latest +JIRA_PROJ=GEOT +SF_HOST=frs.sourceforge.net + +# parameter defaults +if [ -z $branch ]; then + branch="trunk" +fi + +if [ -z $rev ]; then + rev="HEAD" +fi + +if [ -z $DIST_PATH ]; then + DIST_PATH=/var/www/html/geotools/release +fi + +if [ -z $DIST_HOST ]; then + DIST_HOST=gridlock.opengeo.org +fi + +if [ -z $DIST_URL ]; then + DIST_URL=http://$DIST_HOST/geotools/release +fi + +if [ -z $DIST_PORT ]; then + DIST_PORT=7777 +fi + +if [ -z $DIST_USER ]; then + DIST_USER=tomcat +fi + +if [ -z $DIST_PK ]; then + DIST_PK=$HOME/.ssh/id_rsa_${DIST_USER}_${DIST_HOST} +fi + +if [ -z $SF_USER ]; then + SF_USER=jdeolive +fi + +if [ -z $SF_PK ]; then + SF_PK=$HOME/.ssh/id_dsa_${SF_USER}_frs.sourceforge.net +fi Added: trunk/build/release/publish_release.sh =================================================================== --- trunk/build/release/publish_release.sh (rev 0) +++ trunk/build/release/publish_release.sh 2012-05-30 03:24:31 UTC (rev 38778) @@ -0,0 +1,36 @@ +#!/bin/bash + +# error out if any statements fail +set -e +set -x + +function usage() { + echo "$0 [options] <tag>" + echo + echo " tag : Release tag (eg: 2.1.4, 2.2-beta1, ...)" + echo +} + +if [ -z $1 ]; then + usage + exit +fi + +tag=$1 + +# load properties + functions +. "$( cd "$( dirname "$0" )" && pwd )"/properties +. "$( cd "$( dirname "$0" )" && pwd )"/functions + +# get <major.minor> for sf release dir +if [ "$( echo $str | egrep "[0-9]+\.[0-9]+((\.|-).*)?" )" != "$str" ]; then + echo "$tag is not a valid release version number" + exit 1 +fi +dir=`echo $tag | sed 's/\([0-9]*\.[0-9]*\).*/\1/g'` + +pushd $DIST_PATH/$tag > /dev/null + +rsync -ave "ssh -i $SF_PK" *.zip $SF_USER@$SF_HOST:"/home/pfs/project/g/ge/geotools/GeoTools\ $dir\ Releases/$tag/" + +popd > /dev/null Property changes on: trunk/build/release/publish_release.sh ___________________________________________________________________ Added: svn:executable + * Modified: trunk/build/rename.xml =================================================================== --- trunk/build/rename.xml 2012-05-30 02:22:31 UTC (rev 38777) +++ trunk/build/rename.xml 2012-05-30 03:24:31 UTC (rev 38778) @@ -9,36 +9,36 @@ <replace dir=".."> <include name="**/pom.xml"/> <replacefilter token="<version>8-SNAPSHOT</version>" - value="<version>8.0-RC2</version>"/> + value="<version>@VERSION@</version>"/> </replace> <replace dir="../modules/library/metadata/src/main/java/org/geotools/factory"> <include name="GeoTools.java"/> <replacefilter token="8-SNAPSHOT" - value="8.0-M5"/> + value="@VERSION@"/> </replace> </target> <target name="doc"> <replace dir="../docs/user/tutorial/"> <include name="**/pom.xml"/> - <replacefilter token="<geotools.version>8.0-RC1</geotools.version>" - value="<geotools.version>8.0-RC2</geotools.version>"/> + <replacefilter token="<geotools.version>8-SNAPSHOT</geotools.version>" + value="<geotools.version>@VERSION@</geotools.version>"/> </replace> <replace dir="../docs/"> - <include name="common.py"/> - <replacefilter token="8.0-RC1" - value="8.0-RC2"/> + <include name="pom.xml"/> + <replacefilter token="8-SNAPSHOT" + value="@VERSION@"/> </replace> </target> <target name="readme"> <replace file="../README.html"> <replacefilter token="@RELEASE@" - value="8.0-M5"/> + value="@VERSION@"/> <replacefilter token="@DATE@" - value="Dec, 8th, 2011"/> + value="@RELEASE_DATE@"/> </replace> </target> |