Merge pull request #2789 from SergioCrisostomo/upgrade-karma-sauce-launcher
[mootools.git] / prepare-release
blob3e55cb3c149cd0e0d1c64ce1e75daaf9fc78617c
1 #!/bin/sh
3 TAGLENGTH=3
4 COREFILE='Source/Core/Core.js'
5 PKGFILES='package.json bower.json'
7 DIST='node_modules/.bin/grunt'
8 DIST_ARGS='dist'
9 DIST_DIR='dist'
11 DIR=`dirname "$0"`
12 COREFILE="$DIR/$COREFILE"
13 TAG=`echo "$1" | cut -d'.' -f-$TAGLENGTH`
14 SUFFIX="`echo "$2" | tr '[A-Z]' '[a-z]'`"
15 BUILD=`sh -c "cd '$DIR' && git rev-parse HEAD"`
16 CUTLENGTH=`echo "$TAGLENGTH - 1" | bc`
18 usage(){
19 moo "Usage: $0 <tag> [suffix]
21 suffix: alpha, beta or rc*"
24 moo(){
25 echo "$1" >&2
26 exit 1
29 get_suffixnumber(){
30 NUMBER=`echo "$1" | sed 's/^[a-z]*[ ]*\([0-9]*\).*/\1/'`
31 [ -n "$NUMBER" ] && echo "$NUMBER" || echo "1"
34 [ -z "$1" -o "$1" = '-h' -o "$1" = '--help' ] && usage
35 [ -z "$BUILD" ] && moo 'Unable to determine build.'
36 [ -z "$DIST" -o -x "$DIR/$DIST" ] || moo "Cannot execute '$DIST', did you npm install?"
38 until [ -n "`echo "$TAG." | cut -d'.' -f$TAGLENGTH`" ]; do
39 TAG="$TAG.0"
40 done
42 case "$SUFFIX" in
43 '') RELEASE=''; SUFFIX='';;
44 a*) NUMBER="`get_suffixnumber $SUFFIX`"; RELEASE=" Alpha $NUMBER"; SUFFIX="-a$NUMBER";;
45 b*) NUMBER="`get_suffixnumber $SUFFIX`"; RELEASE=" Beta $NUMBER"; SUFFIX="-b$NUMBER";;
46 rc*) NUMBER="`get_suffixnumber $SUFFIX`"; RELEASE=" Release Candidate $NUMBER"; SUFFIX="-rc$NUMBER";;
47 *) moo 'Invalid suffix specified.';;
48 esac
50 if [ "$TAG" != "$1" ]; then
51 echo -n "Did you mean $TAG$SUFFIX? (y/n): "
52 read FIXTAG
53 [ "$FIXTAG" = "y" ] || moo "Invalid tag specified, this project's tags consist of $TAGLENGTH parts."
56 sh -c "cd '$DIR' && git show-ref --quiet --tags '$TAG$SUFFIX'" && moo "Tag $TAG$SUFFIX already exists."
58 if [ -z "$SUFFIX" ]; then
59 MINOR=`echo "$TAG" | cut -d'.' -f$TAGLENGTH-`
60 [ -z "$MINOR" ] && MINOR='0'
61 NEXTTAG="`echo "$TAG" | cut -d'.' -f-$CUTLENGTH`.`echo "$MINOR + 1" | bc`-dev"
62 else
63 NEXTTAG="${TAG}-dev"
66 if [ -n "$DIST" -a -d "$DIR/$DIST_DIR" ]; then
67 echo -n "The '$DIST_DIR' directory already exists. Overwrite it? (y/n): "
68 read DELETEDIST
69 if [ "$DELETEDIST" = "y" ]; then
70 sh -c "cd '$DIR' && git rm -r '$DIR/$DIST_DIR'"
71 else
72 moo "Aborting, will not overwrite '$DIST_DIR'."
76 # Replace build and version strings.
77 sed -i".$BUILD" -e "s/\(version:[ ]*\)'[0-9.]*-dev'/\1'$TAG$SUFFIX'/" -e "s/\(build:[ ]*\)'%build%'/\1'$BUILD'/" "$COREFILE" || moo "Error setting version and build for $TAG$SUFFIX in $COREFILE."
78 sh -c "cd '$DIR' && git add '$COREFILE'" || moo "Error adding changed $COREFILE for $TAG$SUFFIX to repository."
79 for PKGFILE in $PKGFILES; do
80 PKGFILE="$DIR/$PKGFILE"
81 sed -i".$BUILD" -e "s/^\([ ]*\"version\":[ ]*\)\"[0-9.]*-dev\"/\1\"$TAG$SUFFIX\"/" "$PKGFILE" || moo "Error setting version for $TAG$SUFFIX in $PKGFILE."
82 sh -c "cd '$DIR' && git add '$PKGFILE'" || moo "Error adding changed $PKGFILE for $TAG$SUFFIX to repository."
83 done
85 # Build dist files.
86 if [ -n "$DIST" ]; then
87 echo "Building '$DIST_DIR' files." >&2
88 sh -c "cd '$DIR' && $DIST $DIST_ARGS" || moo "Error building '$DIST_DIR' files."
89 sh -c "cd '$DIR' && git add -f '$DIR/$DIST_DIR'" || moo "Error adding '$DIST_DIR' files to repository."
90 echo "Successfully built '$DIST_DIR' files." >&2
93 # Make the new release final.
94 sh -c "cd '$DIR' && git commit -qm 'Welcome $TAG$SUFFIX.'" || moo "Error committing $TAG$SUFFIX."
95 sh -c "cd '$DIR' && git tag -am '$TAG$RELEASE.' '$TAG$SUFFIX'" || moo "Error tagging $TAG$SUFFIX."
96 echo "Tagged $TAG$SUFFIX." >&2
98 # Revert to old corefile and pkgfiles.
99 mv "$COREFILE.$BUILD" "$COREFILE" || moo "Error reverting version and build in $COREFILE."
100 for PKGFILE in $PKGFILES; do
101 PKGFILE="$DIR/$PKGFILE"
102 mv "$PKGFILE.$BUILD" "$PKGFILE" || moo "Error reverting version in $PKFILE."
103 done
105 # Replace build and version strings.
106 sed -i".$BUILD" -e "s/\(version:[ ]*\)'[0-9.]*-dev'/\1'$NEXTTAG'/" "$COREFILE" || moo "Error setting version $NEXTTAG in $COREFILE."
107 sh -c "cd '$DIR' && git add '$COREFILE'" || moo "Error adding changed $COREFILE for $NEXTTAG to repository."
108 for PKGFILE in $PKGFILES; do
109 PKGFILE="$DIR/$PKGFILE"
110 sed -i".$BUILD" -e "s/^\([ ]*\"version\":[ ]*\)\"[0-9.]*-dev\"/\1\"$NEXTTAG\"/" "$PKGFILE" || moo "Error setting version for $NEXTTAG in $PKGFILE."
111 sh -c "cd '$DIR' && git add '$PKGFILE'" || moo "Error adding changed $PKGFILE for $NEXTTAG to repository."
112 done
114 # Clean up temporary and dist files.
115 rm "$COREFILE.$BUILD" || moo "Error cleaning up $COREFILE.$BUILD."
116 for PKGFILE in $PKGFILES; do
117 PKGFILE="$DIR/$PKGFILE"
118 rm "$PKGFILE.$BUILD" || moo "Error cleaning up $PKGFILE.$BUILD."
119 done
120 if [ -n "$DIST" ]; then
121 sh -c "cd '$DIR' && git rm -qr '$DIR/$DIST_DIR'" || moo "Error cleaning up '$DIST_DIR' files."
124 # Make the new dev version final.
125 sh -c "cd '$DIR' && git commit -qm 'Hello $NEXTTAG.'" || moo "Error committing $NEXTTAG."
126 echo "Committed $NEXTTAG." >&2