Skip to content

Commit 7f6a05e

Browse files
authored
Merge pull request #3 from firebase/hkj-release-tools
Adding scripts to prepare and build releases
2 parents ea98e90 + 0fb275b commit 7f6a05e

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

package_release.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
set -e
18+
19+
CURRENT_DIR=$(pwd)
20+
SLN_FILE="${CURRENT_DIR}/FirebaseAdmin/FirebaseAdmin.sln"
21+
if [[ ! -f "${SLN_FILE}" ]]; then
22+
echo "[ERROR] Package script must be executed from the root of the project."
23+
exit 1
24+
fi
25+
26+
if [[ -z "${FrameworkPathOverride}" ]]; then
27+
echo "[INFO] FrameworkPathOverride not set. Using default."
28+
FrameworkPathOverride="/usr/lib/mono/4.5/"
29+
fi
30+
31+
rm -rf FirebaseAdmin/FirebaseAdmin/bin/Release
32+
dotnet pack -c Release FirebaseAdmin/FirebaseAdmin /p:OS="Windows_NT" /p:FrameworkPathOverride=${FrameworkPathOverride}

prepare_release.sh

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Copyright 2018 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
function isNewerVersion {
18+
parseVersion "$1"
19+
ARG_MAJOR=$MAJOR_VERSION
20+
ARG_MINOR=$MINOR_VERSION
21+
ARG_PATCH=$PATCH_VERSION
22+
23+
parseVersion "$2"
24+
if [ "$ARG_MAJOR" -ne "$MAJOR_VERSION" ]; then
25+
if [ "$ARG_MAJOR" -lt "$MAJOR_VERSION" ]; then return 1; else return 0; fi;
26+
fi
27+
if [ "$ARG_MINOR" -ne "$MINOR_VERSION" ]; then
28+
if [ "$ARG_MINOR" -lt "$MINOR_VERSION" ]; then return 1; else return 0; fi;
29+
fi
30+
if [ "$ARG_PATCH" -ne "$PATCH_VERSION" ]; then
31+
if [ "$ARG_PATCH" -lt "$PATCH_VERSION" ]; then return 1; else return 0; fi;
32+
fi
33+
# The build numbers are equal
34+
return 1
35+
}
36+
37+
function parseVersion {
38+
if [[ ! "$1" =~ ^([0-9]*)\.([0-9]*)\.([0-9]*)$ ]]; then
39+
return 1
40+
fi
41+
MAJOR_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\1/')
42+
MINOR_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\2/')
43+
PATCH_VERSION=$(echo "$1" | sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)$/\3/')
44+
return 0
45+
}
46+
47+
set -e
48+
49+
if [[ -z "$1" ]]; then
50+
echo "[ERROR] No version number provided."
51+
echo "[INFO] Usage: ./prepare_release.sh <VERSION_NUMBER>"
52+
exit 1
53+
fi
54+
55+
CURRENT_DIR=$(pwd)
56+
SLN_FILE="${CURRENT_DIR}/FirebaseAdmin/FirebaseAdmin.sln"
57+
if [[ ! -f "${SLN_FILE}" ]]; then
58+
echo "[ERROR] Prepare script must be executed from the root of the project."
59+
exit 1
60+
fi
61+
62+
#############################
63+
# VALIDATE VERSION NUMBER #
64+
#############################
65+
66+
VERSION="$1"
67+
if ! parseVersion "$VERSION"; then
68+
echo "[ERROR] Illegal version number provided. Version number must match semver."
69+
exit 1
70+
fi
71+
72+
PROJECT_FILE="FirebaseAdmin/FirebaseAdmin/FirebaseAdmin.csproj"
73+
CUR_VERSION=$(grep "<Version>" ${PROJECT_FILE} | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
74+
if [ -z "$CUR_VERSION" ]; then
75+
echo "[ERROR] Failed to find the current version. Check ${PROJECT_FILE} for version declaration."
76+
exit 1
77+
fi
78+
if ! parseVersion "$CUR_VERSION"; then
79+
echo "[ERROR] Illegal current version number. Version number must match semver."
80+
exit 1
81+
fi
82+
83+
if ! isNewerVersion "$VERSION" "$CUR_VERSION"; then
84+
echo "[ERROR] Illegal version number provided. Version $VERSION <= $CUR_VERSION"
85+
exit 1
86+
fi
87+
88+
89+
#############################
90+
# VALIDATE TEST RESOURCES #
91+
#############################
92+
93+
INTEGRATION_TESTS_DIR="FirebaseAdmin/FirebaseAdmin.IntegrationTests/resources"
94+
if [[ ! -e "${INTEGRATION_TESTS_DIR}/integration_cert.json" ]]; then
95+
echo "[ERROR] integration_cert.json file is required to run integration tests."
96+
exit 1
97+
fi
98+
99+
if [[ ! -e "${INTEGRATION_TESTS_DIR}/integration_apikey.txt" ]]; then
100+
echo "[ERROR] integration_apikey.txt file is required to run integration tests."
101+
exit 1
102+
fi
103+
104+
105+
###################
106+
# VALIDATE REPO #
107+
###################
108+
109+
# Ensure the checked out branch is master
110+
CHECKED_OUT_BRANCH="$(git branch | grep "*" | awk -F ' ' '{print $2}')"
111+
if [[ $CHECKED_OUT_BRANCH != "master" ]]; then
112+
read -p "[WARN] You are on the '${CHECKED_OUT_BRANCH}' branch, not 'master'. Continue? (y/N) " CONTINUE
113+
case $CONTINUE in
114+
y|Y) ;;
115+
*) echo "[INFO] You chose not to continue." ;
116+
exit 1 ;;
117+
esac
118+
fi
119+
120+
# Ensure the branch does not have local changes
121+
if [[ $(git status --porcelain) ]]; then
122+
read -p "[WARN] Local changes exist in the repo. Continue? (y/N) " CONTINUE
123+
case $CONTINUE in
124+
y|Y) ;;
125+
*) echo "[INFO] You chose not to continue." ;
126+
exit 1 ;;
127+
esac
128+
fi
129+
130+
131+
##################################
132+
# UPDATE VERSION AND CHANGELOG #
133+
##################################
134+
135+
HOST=$(uname)
136+
echo "[INFO] Updating FirebaseAdmin.csproj and CHANGELOG.md"
137+
sed -i -e "s/<Version>$CUR_VERSION<\/Version>/<Version>$VERSION<\/Version>/" "${PROJECT_FILE}"
138+
139+
awk '
140+
BEGIN { print "# Unreleased\n\n-\n\n# v'${VERSION}'" }
141+
/^# Unreleased$/ { next }
142+
{ print }
143+
' CHANGELOG.md > TEMP_CHANGELOG.md
144+
mv TEMP_CHANGELOG.md CHANGELOG.md
145+
146+
147+
##################
148+
# LAUNCH TESTS #
149+
##################
150+
151+
dotnet clean FirebaseAdmin
152+
echo "[INFO] Building project"
153+
dotnet build FirebaseAdmin/FirebaseAdmin
154+
155+
echo "[INFO] Running unit tests"
156+
dotnet test FirebaseAdmin/FirebaseAdmin.Tests
157+
158+
echo "[INFO] Running integration tests"
159+
dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests
160+
161+
echo "[INFO] This repo has been prepared for a release. Create a branch and commit the changes."

0 commit comments

Comments
 (0)