1219820Sjeff#!/bin/bash 2219820Sjeff 3219820SjeffTMPDIR=`pwd`/dist 4219820Sjeffif [ ! -d $TMPDIR ]; then mkdir $TMPDIR; fi 5219820Sjeff 6219820Sjeffusage() { 7219820Sjeffecho "$0 daily | release [ signed | <key-id> ]" 8219820Sjeffecho 9219820Sjeffecho " You must specify either release or daily in order for this script" 10219820Sjeffecho "to make tarballs. If this is a daily release, the tarballs will" 11219820Sjeffecho "be named <component>-git.tar.gz and will overwrite existing tarballs." 12219820Sjeffecho "If this is a release build, then the tarball will be named" 13219820Sjeffecho "<component>-<version>.tar.gz and must be a new file. In addition," 14219820Sjeffecho "the script will add a new set of symbolic tags to the git repo" 15219820Sjeffecho "that correspond to the <component>-<version> of each tarball." 16219820Sjeffecho 17219820Sjeffecho " If the TARGETS environment variable is not NULL, then it is taken" 18219820Sjeffecho "as the list of components in the management tree that should be" 19219820Sjeffecho "included in this release. If it's NULL, then do all the components." 20219820Sjeffecho 21219820Sjeffecho " If the script detects that the tag on any component already exists," 22219820Sjeffecho "it will abort the release and prompt you to update the version on" 23219820Sjeffecho "the already tagged component. This enforces the proper behavior of" 24219820Sjeffecho "treating any released tarball as set in stone so that in the future" 25219820Sjeffecho "you will always be able to get to any given release tarball by" 26219820Sjeffecho "checking out the git tag and know with certainty that it is the same" 27219820Sjeffecho "code as released before even if you no longer have the same tarball" 28219820Sjeffecho "around." 29219820Sjeffecho 30219820Sjeffecho " As part of this process, the script will parse the <target>.spec.in" 31219820Sjeffecho "file and output a <target>.spec file. Since this script isn't smart" 32219820Sjeffecho "enough to deal with other random changes that should have their own" 33219820Sjeffecho "checkin the script will refuse to run if the current repo state is not" 34219820Sjeffecho "clean." 35219820Sjeffecho 36219820Sjeffecho " NOTE: the script has no clue if you are tagging on the right branch," 37219820Sjeffecho "it will however show you the git branch output so you can confirm it" 38219820Sjeffecho "is on the right branch before proceeding with the release." 39219820Sjeffecho 40219820Sjeffecho " In addition to just tagging the git repo, whenever creating a release" 41219820Sjeffecho "there is an optional argument of either signed or a hex gpg key-id." 42219820Sjeffecho "If you do not pass an argument to release, then the tag will be a" 43219820Sjeffecho "simple git annotated tag. If you pass signed as the argument, the" 44219820Sjeffecho "git tag operation will use your default signing key to sign the tag." 45219820Sjeffecho "Or you can pass an actual gpg key id in hex format and git will sign" 46219820Sjeffecho "the tag with that key." 47219820Sjeffecho 48219820Sjeff} 49219820Sjeff 50219820Sjeffif [ -z "$1" ]; then usage; exit 1; fi 51219820Sjeff 52219820Sjeffif [ "$1" != "daily" -a "$1" != "release" ]; then usage; exit 1; fi 53219820Sjeff 54219820Sjeffif [ -z "$TARGETS" ]; then 55219820Sjeff TARGETS="libibcommon libibumad libibmad opensm infiniband-diags" 56219820Sjefffi 57219820Sjeff 58219820Sjeff# Is the repo clean? 59219820Sjeffgit diff-index --quiet HEAD -- $package > /dev/null 2>&1 60219820Sjeffif [ $? -ne 0 ]; then 61219820Sjeff echo "Git tree is dirty. Please commit or undo any changes before proceeding." 62219820Sjeff exit 4 63219820Sjefffi 64219820Sjeff 65219820Sjeff# make sure we are on the right branch 66219820Sjeffgit branch 67219820Sjeffecho -n "Is the active branch the right one to tag this release on [y/N]? " 68219820Sjeffread answer 69219820Sjeffif [ "$answer" = y -o "$answer" = Y ]; then 70219820Sjeff echo "Proceeding..." 71219820Sjeffelse 72219820Sjeff echo "Please check out the right branch and run make.dist again" 73219820Sjeff exit 0 74219820Sjefffi 75219820Sjeff 76219820Sjefffor target in $TARGETS; do 77219820Sjeff VERSION=`grep "AC_INIT.*$target" $target/configure.in | cut -f 2 -d ',' | sed -e 's/ //g'` 78219820Sjeff if [ "$1" = "release" ]; then 79219820Sjeff # Check versions to make sure that we can proceed 80219820Sjeff if [ -f $TMPDIR/$target-$VERSION.tar.gz ]; then 81219820Sjeff echo "Target $target-$VERSION.tar.gz already exists, please update the version on" 82219820Sjeff echo "component $target" 83219820Sjeff exit 2 84219820Sjeff fi 85219820Sjeff if [ ! -z "`git tag -l $target-$VERSION`" ]; then 86219820Sjeff echo "A git tag already exists for $target-$VERSION. Please change the version" 87219820Sjeff echo "of $target so a tag replacement won't occur." 88219820Sjeff exit 3 89219820Sjeff fi 90219820Sjeff# On a real release, this resets the daily release starting point, on the 91219820Sjeff# assumption that any new daily builds will have a version number that is 92219820Sjeff# incrementally higher than the last officially released tarball. 93219820Sjeff RELEASE=1 94219820Sjeff echo $RELEASE > $TMPDIR/$target.release 95219820Sjeff 96219820Sjeff if [ ! -z "$2" ]; then 97219820Sjeff if [ $2 = "signed" ]; then 98219820Sjeff git tag -s -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 99219820Sjeff else 100219820Sjeff git tag -u "$2" -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 101219820Sjeff fi 102219820Sjeff elif [ $1 = "release" ]; then 103219820Sjeff git tag -a -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 104219820Sjeff fi 105219820Sjeff elif [ "$1" = "daily" ]; then 106219820Sjeff DATE=`date +%Y%m%d` 107219820Sjeff git_rev=`./gen_ver.sh $target | sed -e 's/^'$VERSION'_//'` 108219820Sjeff if [ "$git_rev" = "$VERSION" ] ; then 109219820Sjeff VERSION=${VERSION}_${DATE} 110219820Sjeff else 111219820Sjeff VERSION=${VERSION}_${DATE}_${git_rev} 112219820Sjeff fi 113219820Sjeff if [ -f $TMPDIR/$target.gitrev ]; then 114219820Sjeff old_rev=`cat $TMPDIR/$target.gitrev` 115219820Sjeff fi 116219820Sjeff echo $git_rev > $TMPDIR/$target.gitrev 117219820Sjeff if [ "$old_rev" = "$git_rev" ] ; then 118219820Sjeff echo "No daily build is needed for '$target' ($git_rev)" 119219820Sjeff continue 120219820Sjeff fi 121219820Sjeff if [ -f $TMPDIR/$target.release ]; then 122219820Sjeff RELEASE=`cat $TMPDIR/$target.release` 123219820Sjeff RELEASE=`expr $RELEASE + 1` 124219820Sjeff else 125219820Sjeff RELEASE=1 126219820Sjeff fi 127219820Sjeff echo $RELEASE > $TMPDIR/$target.release 128219820Sjeff RELEASE=0.${RELEASE} 129219820Sjeff cat $target/configure.in \ 130219820Sjeff | sed -e '/AC_INIT/s/'$target', .*,/'$target', '$VERSION',/' \ 131219820Sjeff > configure.in.new 132219820Sjeff diff $target/configure.in configure.in.new > /dev/null \ 133219820Sjeff || cat configure.in.new > $target/configure.in 134219820Sjeff fi 135219820Sjeff 136219820Sjeff TARBALL=$target-$VERSION.tar.gz 137219820Sjeff 138219820Sjeff echo "Creating $TMPDIR/$TARBALL" 139219820Sjeff ( export RELEASE=$RELEASE && export TARBALL=$TARBALL && 140219820Sjeff cd $target && ./autogen.sh && ./configure && 141219820Sjeff make dist && mv $target-$VERSION.tar.gz $TMPDIR/$TARBALL ) || 142219820Sjeff exit $? 143219820Sjeff git checkout $target/configure.in 144219820Sjeffdone 145