github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/release/prep_release.sh (about) 1 #!/bin/sh 2 # 3 # Copyright (c) 2013 Conformal Systems LLC <info@conformal.com> 4 # 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. 8 # 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. 16 # 17 # 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 23 # 24 25 PROJECT=btcd 26 PROJECT_UC=$(echo $PROJECT | tr '[:lower:]' '[:upper:]') 27 SCRIPT=$(basename $0) 28 VERFILE=../version.go 29 VERFILES="$VERFILE ../cmd/btcctl/version.go" 30 PROJ_CHANGES=../CHANGES 31 32 # verify params 33 if [ $# -lt 2 ]; then 34 echo "usage: $SCRIPT {major | minor | patch} release-notes-file" 35 exit 1 36 fi 37 38 CUR_DIR=$(pwd) 39 cd "$(dirname $0)" 40 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 45 exit 1 46 fi 47 done 48 49 # verify changes file exists 50 if [ ! -f "$PROJ_CHANGES" ]; then 51 echo "$SCRIPT: error: $PROJ_CHANGES does not exist" 1>&2 52 exit 1 53 fi 54 55 RTYPE="$1" 56 RELEASE_NOTES="$2" 57 if [ $(echo $RELEASE_NOTES | cut -c1) != "/" ]; then 58 RELEASE_NOTES="$CUR_DIR/$RELEASE_NOTES" 59 fi 60 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" 64 exit 1 65 fi 66 67 # verify release notes 68 if [ ! -e "$RELEASE_NOTES" ]; then 69 echo "$SCRIPT: error: specified release notes file does not exist" 70 exit 1 71 fi 72 73 if [ ! -s "$RELEASE_NOTES" ]; then 74 echo "$SCRIPT: error: specified release notes file is empty" 75 exit 1 76 fi 77 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" 82 exit 1 83 fi 84 if [ ${#line} -gt 74 ]; then 85 echo -n "$SCRIPT: error: release notes must not contain lines " 86 echo "with more than 74 characters" 87 exit 1 88 fi 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" 92 exit 1 93 fi 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" 98 exit 1 99 fi 100 fi 101 done <"$RELEASE_NOTES" 102 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." 106 exit 1 107 fi 108 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." 113 exit 1 114 fi 115 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 " 121 echo "modifications" 122 exit 1 123 fi 124 125 # get version 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 133 exit 1 134 fi 135 136 # bump version according to level 137 if [ "$RTYPE" = "major" ]; then 138 MAJOR=$(expr $MAJOR + 1) 139 MINOR=0 140 PATCH=0 141 elif [ "$RTYPE" = "minor" ]; then 142 MINOR=$(expr $MINOR + 1) 143 PATCH=0 144 elif [ "$RTYPE" = "patch" ]; then 145 PATCH=$(expr $PATCH + 1) 146 fi 147 PROJ_VER="$MAJOR.$MINOR.$PATCH" 148 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 { 153 first_line=1 154 print $0 155 next 156 } 157 /=======/ && first_line==1 { 158 print $0 159 print "" 160 print "Changes in "VER" ("D")" 161 exit 162 } 163 { print $0 } 164 ' <"$PROJ_CHANGES" >"${PROJ_CHANGES}.tmp" 165 cat "$RELEASE_NOTES" | sed 's/^/ /' >>"${PROJ_CHANGES}.tmp" 166 awk ' 167 /=======/ && first_line==0 { 168 first_line=1 169 next 170 } 171 /=======/ && first_line==1 { 172 second_line=1 173 next 174 } 175 second_line==1 { print $0 } 176 ' <"$PROJ_CHANGES" >>"${PROJ_CHANGES}.tmp" 177 178 # update version filef with new version 179 for verfile in $VERFILES; do 180 sed -E " 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" 185 done 186 187 188 # Apply changes 189 mv "${PROJ_CHANGES}.tmp" "$PROJ_CHANGES" 190 for verfile in $VERFILES; do 191 mv "${verfile}.tmp" "$verfile" 192 done 193 194 echo "All files have been prepared for release." 195 echo "Use the following commands to review the changes for accuracy:" 196 echo " git status" 197 echo " git diff" 198 echo "" 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}\"" 204 echo " git push" 205 echo " git push --tags"