|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +source bash_utils.sh |
| 4 | + |
| 5 | +function isNewerVersion { |
| 6 | + parseVersion "$1" |
| 7 | + ARG_MAJOR=$MAJOR_VERSION |
| 8 | + ARG_MINOR=$MINOR_VERSION |
| 9 | + ARG_PATCH=$PATCH_VERSION |
| 10 | + |
| 11 | + parseVersion "$2" |
| 12 | + if [ "$ARG_MAJOR" -ne "$MAJOR_VERSION" ]; then |
| 13 | + if [ "$ARG_MAJOR" -lt "$MAJOR_VERSION" ]; then return 1; else return 0; fi; |
| 14 | + fi |
| 15 | + if [ "$ARG_MINOR" -ne "$MINOR_VERSION" ]; then |
| 16 | + if [ "$ARG_MINOR" -lt "$MINOR_VERSION" ]; then return 1; else return 0; fi; |
| 17 | + fi |
| 18 | + if [ "$ARG_PATCH" -ne "$PATCH_VERSION" ]; then |
| 19 | + if [ "$ARG_PATCH" -lt "$PATCH_VERSION" ]; then return 1; else return 0; fi; |
| 20 | + fi |
| 21 | + # The build numbers are equal |
| 22 | + return 1 |
| 23 | +} |
| 24 | + |
| 25 | +set -e |
| 26 | + |
| 27 | +if [ -z "$1" ]; then |
| 28 | + echo "[ERROR] No version number provided." |
| 29 | + echo "[INFO] Usage: ./prepare_release.sh <VERSION_NUMBER>" |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +VERSION="$1" |
| 34 | +if ! parseVersion "$VERSION"; then |
| 35 | + echo "[ERROR] Illegal version number provided. Version number must match semver." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +CUR_VERSION=`grep "^__version__ =" ../firebase_admin/__init__.py | awk '{print $3}' | sed "s/'//g"` |
| 40 | +if [ -z "$CUR_VERSION" ]; then |
| 41 | + echo "[ERROR] Failed to find the current version. Check firebase_admin/__init__.py for version declaration." |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | +if ! parseVersion "$CUR_VERSION"; then |
| 45 | + echo "[ERROR] Illegal current version number. Version number must match semver." |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +if ! isNewerVersion "$VERSION" "$CUR_VERSION"; then |
| 50 | + echo "[ERROR] Illegal version number provided. Version $VERSION <= $CUR_VERSION" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +CHECKED_OUT_BRANCH="$(git branch | grep "*" | awk -F ' ' '{print $2}')" |
| 55 | +if [[ $CHECKED_OUT_BRANCH != "master" ]]; then |
| 56 | + echo "[ERROR] You are on the '${CHECKED_OUT_BRANCH}' branch. Release must be prepared from the 'master' branch." |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +if [[ `git status --porcelain` ]]; then |
| 60 | + echo "[ERROR] Local changes exist in the repo. Resolve local changes before release." |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +HOST=$(uname) |
| 65 | +echo "[INFO] Updating version number in firebase_admin/__init__.py" |
| 66 | +if [ $HOST == "Darwin" ]; then |
| 67 | + sed -i "" -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__init__.py" |
| 68 | +else |
| 69 | + sed --in-place -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__init__.py" |
| 70 | +fi |
| 71 | + |
| 72 | +echo "[INFO] Running unit tests" |
| 73 | +tox --workdir .. |
| 74 | + |
| 75 | +echo "[INFO] This repo has been prepared for a release. Create a branch and commit the changes." |
0 commit comments