3 # Copyright (c) 2013 Conformal Systems LLC <info@conformal.com>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 # Prepares for a release:
19 # - Bumps version according to specified level (major, minor, or patch)
20 # - Updates all version files and package control files with new version
21 # - Performs some basic validation on specified release notes
22 # - Updates project changes file with release notes
26 PROJECT_UC=$(echo $PROJECT | tr '[:lower:]' '[:upper:]')
29 VERFILES="$VERFILE ../cmd/btcctl/version.go"
30 PROJ_CHANGES=../CHANGES
34 echo "usage: $SCRIPT {major | minor | patch} release-notes-file"
41 # verify version files exist
42 for verfile in $VERFILES; do
43 if [ ! -f "$verfile" ]; then
44 echo "$SCRIPT: error: $verfile does not exist" 1>&2
49 # verify changes file exists
50 if [ ! -f "$PROJ_CHANGES" ]; then
51 echo "$SCRIPT: error: $PROJ_CHANGES does not exist" 1>&2
57 if [ $(echo $RELEASE_NOTES | cut -c1) != "/" ]; then
58 RELEASE_NOTES="$CUR_DIR/$RELEASE_NOTES"
61 # verify valid release type
62 if [ "$RTYPE" != "major" -a "$RTYPE" != "minor" -a "$RTYPE" != "patch" ]; then
63 echo "$SCRIPT: error: release type must be major, minor, or patch"
67 # verify release notes
68 if [ ! -e "$RELEASE_NOTES" ]; then
69 echo "$SCRIPT: error: specified release notes file does not exist"
73 if [ ! -s "$RELEASE_NOTES" ]; then
74 echo "$SCRIPT: error: specified release notes file is empty"
78 # verify release notes format
79 while IFS='' read line; do
80 if [ -z "$line" ]; then
81 echo "$SCRIPT: error: release notes must not have blank lines"
84 if [ ${#line} -gt 74 ]; then
85 echo -n "$SCRIPT: error: release notes must not contain lines "
86 echo "with more than 74 characters"
89 if expr "$line" : ".*\.$" >/dev/null 2>&1 ; then
90 echo -n "$SCRIPT: error: release notes must not contain lines "
91 echo "that end in a period"
94 if ! expr "$line" : "\-" >/dev/null 2>&1; then
95 if ! expr "$line" : " " >/dev/null 2>&1; then
96 echo -n "$SCRIPT: error: release notes must not contain lines "
97 echo "that do not begin with a dash and are not indented"
101 done <"$RELEASE_NOTES"
103 # verify git is available
104 if ! type git >/dev/null 2>&1; then
105 echo -n "$SCRIPT: error: Unable to find 'git' in the system path."
109 # verify the git repository is on the master branch
110 BRANCH=$(git branch | grep '\*' | cut -c3-)
111 if [ "$BRANCH" != "master" ]; then
112 echo "$SCRIPT: error: git repository must be on the master branch."
116 # verify there are no uncommitted modifications prior to release modifications
117 NUM_MODIFIED=$(git diff 2>/dev/null | wc -l | sed 's/^[ \t]*//')
118 NUM_STAGED=$(git diff --cached 2>/dev/null | wc -l | sed 's/^[ \t]*//')
119 if [ "$NUM_MODIFIED" != "0" -o "$NUM_STAGED" != "0" ]; then
120 echo -n "$SCRIPT: error: the working directory contains uncommitted "
126 PAT_PREFIX="(^[[:space:]]+app"
127 PAT_SUFFIX='[[:space:]]+uint[[:space:]]+=[[:space:]]+)[0-9]+$'
128 MAJOR=$(egrep "${PAT_PREFIX}Major${PAT_SUFFIX}" $VERFILE | awk '{print $4}')
129 MINOR=$(egrep "${PAT_PREFIX}Minor${PAT_SUFFIX}" $VERFILE | awk '{print $4}')
130 PATCH=$(egrep "${PAT_PREFIX}Patch${PAT_SUFFIX}" $VERFILE | awk '{print $4}')
131 if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then
132 echo "$SCRIPT: error: unable to get version from $VERFILE" 1>&2
136 # bump version according to level
137 if [ "$RTYPE" = "major" ]; then
138 MAJOR=$(expr $MAJOR + 1)
141 elif [ "$RTYPE" = "minor" ]; then
142 MINOR=$(expr $MINOR + 1)
144 elif [ "$RTYPE" = "patch" ]; then
145 PATCH=$(expr $PATCH + 1)
147 PROJ_VER="$MAJOR.$MINOR.$PATCH"
149 # update project changes with release notes
150 DATE=$(date "+%a %b %d %Y")
151 awk -v D="$DATE" -v VER="$PROJ_VER" '
152 /=======/ && first_line==0 {
157 /=======/ && first_line==1 {
160 print "Changes in "VER" ("D")"
164 ' <"$PROJ_CHANGES" >"${PROJ_CHANGES}.tmp"
165 cat "$RELEASE_NOTES" | sed 's/^/ /' >>"${PROJ_CHANGES}.tmp"
167 /=======/ && first_line==0 {
171 /=======/ && first_line==1 {
175 second_line==1 { print $0 }
176 ' <"$PROJ_CHANGES" >>"${PROJ_CHANGES}.tmp"
178 # update version filef with new version
179 for verfile in $VERFILES; do
181 s/${PAT_PREFIX}Major${PAT_SUFFIX}/\1${MAJOR}/;
182 s/${PAT_PREFIX}Minor${PAT_SUFFIX}/\1${MINOR}/;
183 s/${PAT_PREFIX}Patch${PAT_SUFFIX}/\1${PATCH}/;
184 " <"$verfile" >"${verfile}.tmp"
189 mv "${PROJ_CHANGES}.tmp" "$PROJ_CHANGES"
190 for verfile in $VERFILES; do
191 mv "${verfile}.tmp" "$verfile"
194 echo "All files have been prepared for release."
195 echo "Use the following commands to review the changes for accuracy:"
199 echo "If everything is accurate, use the following commands to commit, tag,"
200 echo "and push the changes"
201 echo " git commit -am \"Prepare for release ${PROJ_VER}.\""
202 echo -n " git tag -a \"${PROJECT_UC}_${MAJOR}_${MINOR}_${PATCH}\" -m "
203 echo "\"Release ${PROJ_VER}\""
205 echo " git push --tags"