Skip to content

Commit

Permalink
feat: add release and branch creation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Aug 3, 2021
1 parent 6d23f73 commit b2911e7
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 63 deletions.
33 changes: 33 additions & 0 deletions create-release-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
APP_PATH=`cd "$APP_PATH"; pwd`

cd "${APP_PATH}"
echo "Doubtfire is currently at version `git describe --abbrev=0 --tags`"

echo
echo "What's the name of the release branch?"
echo

read -p "Name: (Format as: 5.0.x) " RELEASE_BRANCH_NAME

function prepare_branch {
PROJECT=$1
PROJECT_PATH=$2

cd "${PROJECT_PATH}"

git checkout -b $RELEASE_BRANCH_NAME
if [ $? -ne 0 ]; then
echo "Oh no... fix up this mess please";
exit 1
fi

git push -u github.com:doubtfire-lms/$PROJECT.git $RELEASE_BRANCH_NAME
}

prepare_branch 'doubtfire-web', "${APP_PATH}/doubtfire-web"
prepare_branch 'doubtfire-api', "${APP_PATH}/doubtfire-api"
prepare_branch 'doubtfire-overseer', "${APP_PATH}/doubtfire-overseer"
prepare_branch 'doubtfire-deploy', "${APP_PATH}"
145 changes: 82 additions & 63 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ APP_PATH=`cd "$APP_PATH"; pwd`
cd "${APP_PATH}"

echo "## Generate Release Notes and Push to Release Branch"

echo
echo "### Step 1: Build"
echo
Expand All @@ -29,81 +30,99 @@ echo
echo "### Step 2. Update version tags"
echo

function prepare_release {
PROJECT=$1
PROJECT_PATH=$2
select answer in "Full" "Prerelease"; do
case $answer in
Full)
break;
;;
Prerelease)
PRERELEASE="--prerelease"
break;
;;
esac
done

cd "${PROJECT_PATH}"
select answer in "Skip" "Auto" "Major" "Minor" "Patch"; do

echo "${PROJECT} is at version `git describe --abbrev=0 --tags`"
echo
echo "Do you wish to make a new ${PROJECT} release?"
echo "Even if there are no changes this will still bump the version number"
select answer in "Skip" "Major" "Minor" "Patch" "Custom"; do
case $answer in
Skip)
echo "Not changing ${PROJECT} tag"
break;
;;
Major)
echo "Creating the ${PROJECT} release and bumping the major version"
standard-version --release-as major
break;
;;
Minor)
echo "Creating the ${PROJECT} release and bumping the minor version"
standard-version --release-as minor
break;
;;
Patch)
echo "Creating the ${PROJECT} release and bumping the patch version"
standard-version --release-as patch
break;
;;
Custom)
read -p "Enter new tag name: " TAG_NAME
standard-version --release-as $TAG_NAME
break;
;;
esac
done
function prepare_release {
PROJECT=$1
PROJECT_PATH=$2

echo
}
cd "${PROJECT_PATH}"

prepare_release 'doubtfire-web', "${APP_PATH}/doubtfire-web"
WEB_VERSION=$(git describe --abbrev=0 --tags)
echo "${PROJECT} is at version `git describe --abbrev=0 --tags`"
case $answer in
Skip)
echo "Not changing ${PROJECT} tag"
break;
;;
Auto)
echo "Creating ${PROJECT} release and bumping the major version"
standard-version $PRERELEASE
break;
;;
Major)
echo "Creating ${PROJECT} release and bumping the major version"
standard-version --release-as major $PRERELEASE
break;
;;
Minor)
echo "Creating ${PROJECT} release and bumping the minor version"
standard-version --release-as minor $PRERELEASE
break;
;;
Patch)
echo "Creating ${PROJECT} release and bumping the patch version"
standard-version --release-as patch $PRERELEASE
break;
;;
esac

prepare_release 'doubtfire-api', "${APP_PATH}/doubtfire-api"
API_VERSION=$(git describe --abbrev=0 --tags)
CURRENT_BRANCH=$(git branch --show-current)
RELEASE_VERSION=`git describe --abbrev=0 --tags`
while [ $CURRENT_BRANCH != $RELEASE_VERSION ]; do
echo "$PROJECT does not match release branch naming: $CURRENT_BRANCH != $RELEASE_VERSION"
read -p "Fix then press enter to continue"

prepare_release 'overseer', "${APP_PATH}/overseer"
OVERSEER_VERSION=$(git describe --abbrev=0 --tags)
CURRENT_BRANCH=$(git branch --show-current)
RELEASE_VERSION=`git describe --abbrev=0 --tags`
done
echo
}

prepare_release 'doubtfire-web', "${APP_PATH}/doubtfire-web"
WEB_VERSION=$(git describe --abbrev=0 --tags)

echo
echo "### Step 4: Prepare deploy for release"
echo
prepare_release 'doubtfire-api', "${APP_PATH}/doubtfire-api"
API_VERSION=$(git describe --abbrev=0 --tags)

cd "${APP_PATH}/releases"
DATE_WITH_TIME=`date "+%Y-%m%d-%H%M"`
mkdir $DATE_WITH_TIME
echo "$API_VERSION" > "${DATE_WITH_TIME}/.apiversion"
echo "$WEB_VERSION" > "${DATE_WITH_TIME}/.webversion"
echo "$OVERSEER_VERSION" > "${DATE_WITH_TIME}/.overseer"
cp -r ./release-template/. ./${DATE_WITH_TIME}
echo "https://github.com/doubtfire-lms/doubtfire-web/blob/${WEB_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/WEB_CHANGELOG.md
echo "https://github.com/doubtfire-lms/doubtfire-api/blob/${API_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/API_CHANGELOG.md
echo "https://github.com/doubtfire-lms/doubtfire-api/blob/${OVERSEER_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/OVERSEER_CHANGELOG.md
prepare_release 'doubtfire-overseer', "${APP_PATH}/doubtfire-overseer"
OVERSEER_VERSION=$(git describe --abbrev=0 --tags)

echo
echo "Please update release notes, and push them to origin before continuing here..."
echo
echo "### Step 3: Prepare deploy for release"
echo

prepare_release 'doubtfire-deploy', "${APP_PATH}"
DEPLOY_VERSION=$(git describe --abbrev=0 --tags)
cd "${APP_PATH}/releases"
DATE_WITH_TIME=`date "+%Y-%m%d-%H%M"`
mkdir $DATE_WITH_TIME
echo "$API_VERSION" > "${DATE_WITH_TIME}/.apiversion"
echo "$WEB_VERSION" > "${DATE_WITH_TIME}/.webversion"
echo "$OVERSEER_VERSION" > "${DATE_WITH_TIME}/.overseer"
cp -r ./release-template/. ./${DATE_WITH_TIME}
echo "https://github.com/doubtfire-lms/doubtfire-web/blob/${WEB_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/WEB_CHANGELOG.md
echo "https://github.com/doubtfire-lms/doubtfire-api/blob/${API_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/API_CHANGELOG.md
echo "https://github.com/doubtfire-lms/doubtfire-api/blob/${OVERSEER_VERSION}/CHANGELOG.md" > ${DATE_WITH_TIME}/OVERSEER_CHANGELOG.md

echo
echo "Please update release notes, and push them to origin before continuing here..."

prepare_release 'doubtfire-deploy', "${APP_PATH}"
DEPLOY_VERSION=$(git describe --abbrev=0 --tags)
done

echo
echo "### Step 3: Push releases"
echo "### Step 4: Push releases"
echo

function push_release {
Expand All @@ -129,7 +148,7 @@ select answer in "Skip" "Push"; do
Push)
push_release 'doubtfire-web', "${APP_PATH}/doubtfire-web"
push_release 'doubtfire-api', "${APP_PATH}/doubtfire-api"
push_release 'overseer', "${APP_PATH}/overseer"
push_release 'doubtfire-overseer', "${APP_PATH}/doubtfire-overseer"
push_release 'doubtfire-deploy', "${APP_PATH}"
break;
;;
Expand Down

0 comments on commit b2911e7

Please sign in to comment.