From 0140b539f5289e34797550535df28a3a3cf004a7 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Thu, 4 Aug 2016 19:12:59 +0300 Subject: [PATCH] Implement [shellcheck](https://www.shellcheck.net/) recommendations --- release.sh | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/release.sh b/release.sh index 90e88b9..a1aa749 100755 --- a/release.sh +++ b/release.sh @@ -10,6 +10,7 @@ # file in which to update version number FILE_VERSION="VERSION" +# file to use as our change log FILE_CHANGELOG="CHANGELOG.md" NOW="$(date +'%Y-%m-%d')" @@ -22,7 +23,7 @@ CYAN="\033[1;36m" WHITE="\033[1;37m" RESET="\033[0m" -LATEST_HASH=`git log --pretty=format:'%h' -n 1` +LATEST_HASH=$(git log --pretty=format:'%h' -n 1) # current Git branch BRANCH_CURRENT=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') @@ -50,7 +51,7 @@ fi if [ ! -f $FILE_VERSION ]; then echo -ne "${QUESTION_FLAG} ${CYAN}Can't find version file (${FILE_VERSION}), create one?" - read RESPONSE + read -r RESPONSE if [[ $RESPONSE =~ [yY](es)* ]] || [ "$RESPONSE" = "" ]; then echo "0.0.0" > $FILE_VERSION else @@ -62,7 +63,7 @@ fi if [ ! -f $FILE_CHANGELOG ]; then echo -ne "${QUESTION_FLAG} ${CYAN}Can't find changelog file (${FILE_CHANGELOG}), create one?" - read RESPONSE + read -r RESPONSE if [[ $RESPONSE =~ [yY](es)* ]] || [ "$RESPONSE" = "" ]; then echo "" > $FILE_CHANGELOG else @@ -71,13 +72,13 @@ if [ ! -f $FILE_CHANGELOG ]; then fi # Continue to guess new value for our version -BASE_STRING=`cat $FILE_VERSION` +BASE_STRING=$(cat $FILE_VERSION) -if [ $BASE_STRING = "" ]; then +if [ "$BASE_STRING" = "" ]; then BASE_STRING="0.0.0" fi -BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`) +BASE_LIST=($(echo $BASE_STRING | tr '.' ' ')) V_MAJOR=${BASE_LIST[0]} V_MINOR=${BASE_LIST[1]} V_PATCH=${BASE_LIST[2]} @@ -91,59 +92,59 @@ V_PATCH=$((V_PATCH + 1)) SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH" echo -ne "${QUESTION_FLAG} ${CYAN}Enter a version number [${WHITE}$SUGGESTED_VERSION${CYAN}]: " -read NEW_VERSION +read -r NEW_VERSION if [ "$NEW_VERSION" = "" ]; then NEW_VERSION=$SUGGESTED_VERSION fi echo -e "${NOTICE_FLAG} Will set new version to be ${WHITE}$NEW_VERSION" echo "" echo -ne "${WARNING_FLAG} This is the last chance to bail out before anything has happened." -read +read -r # Set up our release branch name BRANCH_RELEASE=release-$NEW_VERSION # create the release branch from the -develop branch -git checkout -b $BRANCH_RELEASE $BRANCH_DEV +git checkout -b "$BRANCH_RELEASE" "$BRANCH_DEV" # Set our new version to our version file -echo $NEW_VERSION > $FILE_VERSION +echo "$NEW_VERSION" > "$FILE_VERSION" # Create our changelog echo "## $NEW_VERSION ($NOW)" > tmpfile git log --pretty=format:" - %h %ad | %s%d [%an]" --date=short --no-merges "$BASE_STRING"...HEAD >> tmpfile echo "" >> tmpfile echo "" >> tmpfile -cat $FILE_CHANGELOG >> tmpfile +cat "$FILE_CHANGELOG" >> tmpfile mv tmpfile $FILE_CHANGELOG echo -e "$ADJUSTMENTS_MSG" -read +read -r echo -e "$PUSHING_MSG" # Make sure changes have been added -git add $FILE_VERSION $FILE_CHANGELOG +git add "$FILE_VERSION" "$FILE_CHANGELOG" # Commit version number increment git commit -am "Incrementing version number to $NEW_VERSION" # Merge release branch with the new version number into master -git checkout $BRANCH_MASTER -git merge --no-ff $BRANCH_RELEASE +git checkout "$BRANCH_MASTER" +git merge --no-ff "$BRANCH_RELEASE" # Create tag for new version from -master git tag -am "Tag version ${NEW_VERSION}." "$NEW_VERSION" # Merge release branch with the new version number back into develop -git checkout $BRANCH_DEV -git merge --no-ff $BRANCH_RELEASE +git checkout "$BRANCH_DEV" +git merge --no-ff "$BRANCH_RELEASE" # Remove release branch -git branch -d $BRANCH_RELEASE +git branch -d "$BRANCH_RELEASE" echo -ne "${QUESTION_FLAG} ${CYAN}Push?" -read PUSH +read -r PUSH if [[ $PUSH =~ [yY](es)* ]] || [ "$PUSH" = "" ]; then git push --all origin fi