release.sh 1.68 KB
Newer Older
1 2
#!/usr/bin/env bash

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
###################################################################
#
#   Create a new tag for a release of edx-ora2 and
#   push it to the remote.
#
#   Release tags have a uniform naming scheme that includes
#   the current date.
#
#   Usage:
#
#       ./release.sh COMMIT
#
#   If no commit is specified, use origin/master.
#
#   Examples:
#
#       Create a release tag for origin/master:
#       ./release.sh
#
#       Create a release tag for a specific commit:
#       ./release.sh f921f3ee4bc07edf2f1b492f94350cb1dd844100
#
#       Create a release tag without user input:
#       yes | ./release.sh
#
###################################################################
29

30 31 32 33
# Use YYYY-MM-DD-HH:MM format (UTC)
DATE=`date -u +%Y-%m-%dT%H.%M`

read -p "Create the release candidate?  (You may lose changes that are not committed or stashed.)  [y/n]  " RESP
34 35 36 37 38
if [ "$RESP" != "y" ]; then
    exit 0
fi

echo "Updating origin/master..."
39
git fetch
40

41 42 43 44 45
# If no commit is specified, use origin/master
if [ -z "$1" ]; then
    git checkout -q origin/master || exit 1
else
    git checkout -q $1 || exit 1
46 47
fi

48
echo "Tagging the release candidate..."
49 50 51
TAG="release-$DATE"
git tag | grep -q "$TAG"
if [ $? -eq 0 ]; then
52
    read -p "Tag $TAG already exists.  Delete it and create a new one? [y/n]  " RESP
53 54 55 56 57 58 59 60 61 62 63
    if [ "$RESP" = "y" ]; then
        echo "Deleting $TAG"
        git tag -d $TAG
    else
        exit 0
    fi
fi

git tag -m "release for $DATE" "$TAG"
echo " == Created tag $TAG"

64
read -p "Push tag $TAG to origin? [y/n]  " RESP
65
if [ "$RESP" = "y" ]; then
66 67
    git push origin $TAG
    echo " == Pushed tag $TAG to origin"
68 69 70 71 72
fi

echo " == Finished =="
echo "Tag: $TAG"
echo "Commit: `git rev-parse HEAD`"