release.sh 8.4 KB
Newer Older
1 2 3 4
#!/bin/bash
#
# Builds release tarballs of Mahara at the given version, ready for
# distribution
5 6 7 8 9
#
# Use "mergesecurity" if you're doing a release which has security
# fixes so that the script will merge the security repo into the
# public repo too. Otherwise use "justpublic".
#
10 11 12 13
set -e


print_usage() {
14 15 16
    echo "Usage is $0 [version] [branch] justpublic|mergesecurity"
    echo "e.g. $0 1.3.5 1.3_STABLE mergesecurity"
    echo "e.g. $0 1.2.8 1.2_STABLE justpublic"
17 18
}

19
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
20 21 22 23
    print_usage
    exit 1
fi

24 25
# Check for git gpg lp-project-upload

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
if [ ! -x /usr/bin/gpg ] ; then
  echo "You need to install gpg: apt-get install gnupg"
  exit 1
fi

if [ ! -x /usr/bin/git ] ; then
  echo "You need to install git: apt-get install git-core"
  exit 1
fi

if [ ! -x /usr/bin/lp-project-upload ] ; then
  echo "You need to install lp-project-upload: apt-get install ubuntu-dev-tools"
  exit 1
fi

GIT_MAJOR=`git --version | cut -d' ' -f 3 | cut -d'.' -f 1`
GIT_MINOR=`git --version | cut -d' ' -f 3 | cut -d'.' -f 2`

if [ $GIT_MAJOR -lt 1 ] || [ $GIT_MAJOR == 1 -a $GIT_MINOR -lt 6 ] ; then
  echo "Your version of git is too old. Install git 1.6."
  exit 1
fi

# Check all parameters

51
VERSION=$1
52

53 54
MAJOR=${VERSION%.*}
REST=${VERSION##*.}
55 56 57 58 59 60 61
MINOR=${REST%%[a-z]*}
MICRO=`echo ${REST} | sed 's/^[0-9]*//g'`
MICROA=`echo ${MICRO} | sed 's/[^a-z]//g'`
MICROB=`echo ${MICRO} | sed 's/[a-z]//g'`

BRANCH=$2
OPTION=$3
62
BUILDDIR="/tmp/mahara/tarballs"
63
CURRENTDIR="`pwd`"
64
SCRIPTDIR=$( readlink -f -- "${0%/*}" )
65 66 67 68 69 70

if [ -z "${MAJOR}" ] || [ -z "${MINOR}" ]; then
    print_usage
    exit 1
fi

71
if [ "$OPTION" != "justpublic" ] && [ "${OPTION}" != 'mergesecurity' ]; then
72 73 74 75
    print_usage
    exit 1
fi

76 77 78 79 80 81 82 83 84 85 86 87
if [ -d ${BUILDDIR} ]; then
    rm -rf ${BUILDDIR}
fi

mkdir -p ${BUILDDIR}/mahara
pushd ${BUILDDIR}/mahara




# Get the public & security branches

88
PUBLIC="git@gitorious.org:mahara/mahara.git"
89 90
SECURITY="git+ssh://git.catalyst.net.nz/var/gitprivate/mahara-security.git"

91
echo "Cloning public repository ${PUBLIC} in ${BUILDDIR}/mahara"
92 93
git init
git remote add -t ${BRANCH} mahara ${PUBLIC}
94 95
git fetch -q mahara
git checkout -b ${BRANCH} mahara/${BRANCH}
96

97
if [ "$OPTION" != "justpublic" ]; then
98
    echo "Checking out security repository ${SECURITY}..."
99
    git remote add -t ${BRANCH} mahara-security ${SECURITY}
100
    git fetch -q mahara-security
101 102
    git checkout -b S_${BRANCH} mahara-security/${BRANCH}
    echo "Merging $BRANCH (public) into $BRANCH (security)"
103
    git merge ${BRANCH}
104
    # Check for merge conflicts
105 106 107 108
fi



109
# Edit ChangeLog
110 111 112 113
if [ -z "${MICRO}" ] && [ ! -f "ChangeLog" ]; then
    echo "The ChangeLog file is missing and this is a stable release. Create an empty file called ChangeLog and commit it."
    exit 1
fi
114

115 116
RELEASE="${MAJOR}.${MINOR}${MICRO}"

117 118 119 120
echo -e "#\n# Please add a description of the major changes in this release, one per line:\n#\n" > ${CURRENTDIR}/ChangeLog.temp
sensible-editor ${CURRENTDIR}/ChangeLog.temp
grep -v "^#" ${CURRENTDIR}/ChangeLog.temp > ${CURRENTDIR}/changes.temp

121 122 123
if [ -f "ChangeLog" ]; then
    cp ChangeLog ChangeLog.back
    echo "$RELEASE (`date +%Y-%m-%d`)" > ChangeLog
124
    sed 's/^/- /g' ${CURRENTDIR}/changes.temp >> ChangeLog
125 126 127 128 129 130 131 132
    echo >> ChangeLog
    cat ChangeLog.back >> ChangeLog
    git add ChangeLog
fi




133
# Add a version bump commit for the release
134 135 136

VERSIONFILE=htdocs/lib/version.php

137 138 139
# If there's no 'micro' part of the version number, assume it's a stable release, and
# bump version by 1.  If it's an unstable release, use 
if [ -z "${MICRO}" ]; then
140 141
    OLDVERSION=$(perl -n -e 'print if s/^\$config->version = (\d{10}).*/$1/' < ${VERSIONFILE})
    NEWVERSION=$(( ${OLDVERSION} + 1 ))
142 143
else
    NEWVERSION=`date +%Y%m%d`00
144 145 146 147 148
fi

sed "s/\$config->version = [0-9]\{10\};/\$config->version = $NEWVERSION;/" ${VERSIONFILE} > ${VERSIONFILE}.temp
sed "s/\$config->release = .*/\$config->release = '$RELEASE';/" ${VERSIONFILE}.temp > ${VERSIONFILE}

149
echo
150 151 152
git add ${VERSIONFILE}
git commit -m "Version bump for $RELEASE"

153 154 155


# Tag the version bump commit
156
LASTTAG=`git describe --abbrev=0`
157
RELEASETAG="`echo $RELEASE | tr '[:lower:]' '[:upper:]'`_RELEASE"
158
echo -e "\nTag new version bump commit as '$RELEASETAG'"
159 160 161 162 163
git tag -s ${RELEASETAG} -m "$RELEASE release"



# Create tarballs
164

165
echo "Creating mahara-${RELEASE}.tar.gz"
166
git archive --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | gzip -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.gz
167
echo "Creating mahara-${RELEASE}.tar.bz2"
168
git archive --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | bzip2 -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.bz2
169
echo "Creating mahara-${RELEASE}.zip"
170
git archive --format=zip --prefix=mahara-${VERSION}/ -9 ${RELEASETAG} > ${CURRENTDIR}/mahara-${RELEASE}.zip
171 172 173



174
# Save git changelog
175 176
if [ -n "${LASTTAG}" ] ; then
    echo "Getting changelog from previous tag ${LASTTAG}"
177
    git log --pretty=format:"%s" --no-color --no-merges ${LASTTAG}..${RELEASETAG} > ${CURRENTDIR}/${RELEASETAG}.cl
178
else
179
    git log --pretty=format:"%s" --no-color --no-merges ${RELEASETAG} > ${CURRENTDIR}/${RELEASETAG}.cl
180
fi
181
OLDRELEASE=${LASTTAG%_RELEASE}
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204



# Prepare eduforge release notes

TMP_M4_FILE=/tmp/mahara-releasnotes.m4.tmp
echo "changecom" > $TMP_M4_FILE
echo "define(\`__RELEASE__',\`${RELEASE}')dnl" >> $TMP_M4_FILE
echo "define(\`__OLDRELEASE__',\`${OLDRELEASE}')dnl" >> $TMP_M4_FILE
echo "define(\`__MAJOR__',\`${MAJOR}')dnl" >> $TMP_M4_FILE
sed 's/^/ * /g' ${CURRENTDIR}/changes.temp >> ${CURRENTDIR}/changes.eduforge.temp
echo "define(\`__CHANGES__',\`include(\`${CURRENTDIR}/changes.eduforge.temp')')dnl" >> $TMP_M4_FILE

if [ -z "${MICRO}" ]; then
    TEMPLATE=releasenotes.stable.template
else
    TEMPLATE=releasenotes.${MICROA}.template
fi

m4 ${TMP_M4_FILE} ${SCRIPTDIR}/${TEMPLATE} > ${CURRENTDIR}/releasenotes-${RELEASE}.txt



205 206 207
# Second version bump for post-release

NEWVERSION=$(( ${NEWVERSION} + 1 ))
208
if [ -z "${MICRO}" ]; then
209
    NEWRELEASE="${MAJOR}.$(( ${MINOR} + 1 ))testing"
210 211
else
    NEWRELEASE="${MAJOR}.${MINOR}${MICROA}$(( ${MICROB} + 1 ))dev"
212 213 214 215 216 217 218 219 220 221
fi

sed "s/\$config->version = [0-9]\{10\};/\$config->version = $NEWVERSION;/" ${VERSIONFILE} > ${VERSIONFILE}.temp
sed "s/\$config->release = .*/\$config->release = '$NEWRELEASE';/" ${VERSIONFILE}.temp > ${VERSIONFILE}

git add ${VERSIONFILE}
git commit -m "Version bump for $NEWRELEASE"



222 223
# Merge security back into public

224
if [ "$OPTION" != "justpublic" ]; then
225 226 227 228 229 230 231 232 233
    git checkout ${BRANCH}
    git merge S_${BRANCH}
fi



# Output commands to push to the remote repository and clean up

CLEANUPSCRIPT=release-${RELEASE}-cleanup.sh
234 235 236 237
echo > ${CURRENTDIR}/${CLEANUPSCRIPT}


echo "cd ${BUILDDIR}/mahara" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
238 239
echo "git push mahara ${BRANCH}:refs/heads/${BRANCH}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "git push mahara ${RELEASETAG}:refs/tags/${RELEASETAG}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
240
if [ "$OPTION" != "justpublic" ]; then
241 242 243
    echo "git push mahara-security S_${BRANCH}:refs/heads/${BRANCH}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
    echo "git push mahara-security ${RELEASETAG}:refs/tags/${RELEASETAG}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
fi
244 245 246 247 248

echo "gpg --armor --sign --detach-sig ${CURRENTDIR}/mahara-${RELEASE}.tar.gz" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "gpg --armor --sign --detach-sig ${CURRENTDIR}/mahara-${RELEASE}.tar.bz2" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "gpg --armor --sign --detach-sig ${CURRENTDIR}/mahara-${RELEASE}.zip" >> ${CURRENTDIR}/${CLEANUPSCRIPT}

249 250 251 252
echo "cd ${CURRENTDIR}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "lp-project-upload mahara ${RELEASE} mahara-${RELEASE}.tar.gz" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "lp-project-upload mahara ${RELEASE} mahara-${RELEASE}.tar.bz2" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "lp-project-upload mahara ${RELEASE} mahara-${RELEASE}.zip" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
253

254
echo "echo rm -rf ${BUILDDIR}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
255

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
chmod 700 ${CURRENTDIR}/${CLEANUPSCRIPT}



# Clean up

rm ${VERSIONFILE}.temp
rm ${CURRENTDIR}/ChangeLog.temp
rm ${CURRENTDIR}/changes.temp
rm ${CURRENTDIR}/changes.eduforge.temp
rm ${TMP_M4_FILE}




271
echo -e "\n\nTarballs, release notes & changelog for Launchpad:\n"
272 273 274
cd ${CURRENTDIR}
ls -l mahara-${RELEASE}.tar.gz mahara-${RELEASE}.tar.bz2 mahara-${RELEASE}.zip releasenotes-${RELEASE}.txt ${RELEASETAG}.cl

275 276 277
echo -e "\n1. Check that everything is in order in the ${BUILDDIR}/mahara repository."
echo -e "\n2. Create the release on launchpad at https://launchpad.net/mahara/+milestone/${RELEASE}"
echo -e "\n3. Run the commands in ${CLEANUPSCRIPT} to push the changes back to the remote repository and upload the tarballs."