Skip to content

Commit 65e74c7

Browse files
authored
Adding prepare and verify scripts (#14)
* Adding prepare and verify scripts * Moved parse version function to a separate source file; Added check to verify master branch. * Support for sed on Mac
1 parent 4709d9f commit 65e74c7

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

scripts/bash_utils.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
function parseVersion {
4+
if [[ ! "$1" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
5+
return 1
6+
fi
7+
MAJOR_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\1/')
8+
MINOR_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\2/')
9+
PATCH_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\3/')
10+
return 0
11+
}

scripts/prepare_release.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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."

scripts/verify_release.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
source bash_utils.sh
4+
5+
if [ -z "$1" ]; then
6+
echo "[ERROR] No version number provided."
7+
echo "[INFO] Usage: ./verify_release.sh <VERSION_NUMBER>"
8+
exit 1
9+
fi
10+
11+
VERSION="$1"
12+
if ! parseVersion "$VERSION"; then
13+
echo "[ERROR] Illegal version number provided. Version number must match semver."
14+
exit 1
15+
fi
16+
17+
mkdir sandbox
18+
virtualenv sandbox
19+
source sandbox/bin/activate
20+
pip install firebase_admin
21+
INSTALLED_VERSION=`python -c 'import firebase_admin; print firebase_admin.__version__'`
22+
echo "[INFO] Installed firebase_admin version $INSTALLED_VERSION"
23+
deactivate
24+
rm -rf sandbox
25+
26+
if [[ "$VERSION" == "$INSTALLED_VERSION" ]]; then
27+
echo "[INFO] Release verified successfully"
28+
else
29+
echo "[ERROR] Installed version did not match the release version."
30+
exit 1
31+
fi

0 commit comments

Comments
 (0)