release.sh 9.23 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
# If you're doing a release which has security fixes, add the names
# of the patches to the end of the command line, and the script will
# apply the patches before committing the version bumps and editing
# the changelog.
10
#
11 12 13 14
set -e


print_usage() {
15 16 17 18
    echo "Usage is $0 [version] [branch] [<patchfile>...]"
    echo "e.g. $0 1.3.5 1.3_STABLE ~/patches/0001-Add-foo-to-bar.patch ~/patches/0002-Fix-big-security-hole.patch"
    echo "e.g. $0 1.2.8 1.2_STABLE"
    echo "Patches should be created with git format-patch"
19 20
}

21
if [ $# -lt 2 ]; then
22 23 24 25
    print_usage
    exit 1
fi

26 27
# Check for git gpg lp-project-upload

28 29 30 31 32 33 34 35 36 37 38
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
39
  echo "You need to install lp-project-upload: apt-get install ubuntu-dev-tools (maverick or earlier) or lptools"
40 41 42
  exit 1
fi

43 44 45 46 47
if [ ! -x /usr/bin/m4 ] ; then
  echo "You need to install m4: apt-get install m4"
  exit 1
fi

48 49 50 51 52 53 54 55 56 57
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

58
VERSION=$1
59

60 61
MAJOR=${VERSION%.*}
REST=${VERSION##*.}
62 63 64 65 66 67
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
68

69
BUILDDIR=`mktemp -d /tmp/mahara.XXXXX`
70
CURRENTDIR="`pwd`"
71
SCRIPTDIR=$( readlink -f -- "${0%/*}" )
72 73 74 75 76 77

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

78 79 80 81
if [ ! -z "${MICRO}" ] && [ "${BRANCH}" != 'master' ]; then
    echo "* Micro version is ${MICRO} and this is a stable branch. Stuff may be wrong. *"
fi

82 83 84 85 86
mkdir -p ${BUILDDIR}/mahara
pushd ${BUILDDIR}/mahara



87
# Main Mahara repo to pull from
88
#PUBLIC="git@git.mahara.org:mahara/mahara.git"
Aaron Wells's avatar
Aaron Wells committed
89
PUBLIC="git@github.com:MaharaProject/mahara.git"
90

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

98 99 100 101 102 103
# Apply patch files named on command line
patch=3
while [ $patch -le $# ]; do
    git am ${!patch}
    patch=$((patch+1))
done
104

105
# Edit ChangeLog
106 107 108 109
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
110

111 112
RELEASE="${MAJOR}.${MINOR}${MICRO}"

113
echo -e "#\n# Please add a description of the major changes in this release, one per line.\n# Don't put a dash or asterisk at the front of each line, they'll get added automatically.\n# Also, don't leave any blank lines at the bottom of this file.\n#\n" > ${CURRENTDIR}/ChangeLog.temp
114 115 116
sensible-editor ${CURRENTDIR}/ChangeLog.temp
grep -v "^#" ${CURRENTDIR}/ChangeLog.temp > ${CURRENTDIR}/changes.temp

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




129
# Add a version bump commit for the release
130 131 132

VERSIONFILE=htdocs/lib/version.php

133 134
# 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 
135
if [ -z "${MICRO}" ] || [ "${BRANCH}" != 'master' ]; then
136 137
    OLDVERSION=$(perl -n -e 'print if s/^\$config->version = (\d{10}).*/$1/' < ${VERSIONFILE})
    NEWVERSION=$(( ${OLDVERSION} + 1 ))
138 139
else
    NEWVERSION=`date +%Y%m%d`00
140 141 142 143 144
fi

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

145
echo
146
git add ${VERSIONFILE}
147
git commit -s -m "Version bump for $RELEASE"
148

149 150 151


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


158 159 160 161 162 163 164 165 166
# Update the .gitattributes to ignore tests directories
# First get the location for all phpunit directories
phpunitdirs=`find ./ -type d -name 'phpunit' | grep 'tests/phpunit' | sed "s_./__"`

for dir in $phpunitdirs
do
  parentdir=`dirname "$dir"`
  # Determine whether the parent directory contains anything other than
  # phpunit. If not, ignore the whole parent directory.
167 168
  siblings=`find "$parentdir" -maxdepth 1 -mindepth 1 | wc -l`
  if [ "$siblings" = "1" ]
169 170 171 172 173 174
  then
    echo "$parentdir export-ignore" >> .gitattributes
  else
    echo "$dir export-ignore" >> .gitattributes
  fi
done
175 176

# Create tarballs
177

178
echo "Creating mahara-${RELEASE}.tar.gz"
179
git archive --worktree-attributes --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | gzip -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.gz
180
echo "Creating mahara-${RELEASE}.tar.bz2"
181
git archive --worktree-attributes --format=tar --prefix=mahara-${VERSION}/ ${RELEASETAG} | bzip2 -9 > ${CURRENTDIR}/mahara-${RELEASE}.tar.bz2
182
echo "Creating mahara-${RELEASE}.zip"
183
git archive --worktree-attributes --format=zip --prefix=mahara-${VERSION}/ -9 ${RELEASETAG} > ${CURRENTDIR}/mahara-${RELEASE}.zip
184 185 186



187
# Save git changelog
188 189
if [ -n "${LASTTAG}" ] ; then
    echo "Getting changelog from previous tag ${LASTTAG}"
190
    git log --pretty=format:"%s" --no-color --no-merges ${LASTTAG}..${RELEASETAG} > ${CURRENTDIR}/${RELEASETAG}.cl
191
else
192
    git log --pretty=format:"%s" --no-color --no-merges ${RELEASETAG} > ${CURRENTDIR}/${RELEASETAG}.cl
193
fi
194
OLDRELEASE=${LASTTAG%_RELEASE}
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217



# 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



218 219 220
# Second version bump for post-release

NEWVERSION=$(( ${NEWVERSION} + 1 ))
221
if [ -z "${MICRO}" ]; then
222
    NEWRELEASE="${MAJOR}.$(( ${MINOR} + 1 ))testing"
223 224
else
    NEWRELEASE="${MAJOR}.${MINOR}${MICROA}$(( ${MICROB} + 1 ))dev"
225 226 227 228 229 230
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}
231
git commit -s -m "Version bump for $NEWRELEASE"
232 233 234



235 236 237 238 239
# Add gerrit repo, for pushing the new security patches, version bump & changelog commits
GERRIT="ssh://reviews.mahara.org:29418/mahara"
git remote add gerrit ${GERRIT}


240 241 242
# Output commands to push to the remote repository and clean up

CLEANUPSCRIPT=release-${RELEASE}-cleanup.sh
243
echo "#!/bin/sh" > ${CURRENTDIR}/${CLEANUPSCRIPT}
244

245
echo "set -e" > ${CURRENTDIR}/${CLEANUPSCRIPT}
246 247

echo "cd ${BUILDDIR}/mahara" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
248 249
echo "git push gerrit ${BRANCH}:refs/heads/${BRANCH}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "git push gerrit ${RELEASETAG}:refs/tags/${RELEASETAG}" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
250 251 252 253 254

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}

255 256 257 258
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}
259

260
echo "echo" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
261 262
echo "echo \"All done. Once you've checked that the files were uploaded successfully, run this:\"" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
echo "echo \"  rm -rf ${BUILDDIR}\"" >> ${CURRENTDIR}/${CLEANUPSCRIPT}
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
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}




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

283 284 285
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."