Skip to content
33 changes: 26 additions & 7 deletions .common-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SCRIPT_PARENT_PATH="$( dirname ${SCRIPT_PATH} )"

source ${SCRIPT_PATH}/.hooks-default.sh
if [ -f "${SCRIPT_PARENT_PATH}/.release-scripts-hooks.sh" ]; then
echo "Found .release-hooks.sh. Using it as master hooks"
echo "Found .release-scripts-hooks.sh. Using it as master hooks"
source "${SCRIPT_PARENT_PATH}/.release-scripts-hooks.sh"
else
source ${SCRIPT_PATH}/hooks.sh
Expand All @@ -29,10 +29,29 @@ function check_local_workspace_state {
}

function is_branch_existing {
if [ `git branch -a --list "$1"` ]
then
return 0
else
return 1
fi
if git branch -a --list | grep "$1"
then
return 0
else
return 1
fi
}

function is_workspace_clean {
if git diff-files --quiet --ignore-submodules --
then
return 0
else
return 1
fi
}

function is_workspace_synced {
if test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)"
then
return 0
else
return 1
fi
}

14 changes: 14 additions & 0 deletions .hooks-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ function get_master_branch_name {
echo "master"
}

# Hook method to define the patter for support branches
# Parameter $1 - support branch identifer, i.e. 2.x
# Returns support branches name as text, i.e. support-2.x
function format_support_branch_name {
echo "support-$1"
}

# Hook method to define the patter for support master branches
# Parameter $1 - support branch identifer, i.e. 2.x
# Returns support branches name as text, i.e. master-2.x
function format_support_master_branch_name {
echo "master-$1"
}

# Hook method to format the release branch name
# Parameter $1 - version as text
# Returns the formatted release branch name as text
Expand Down
2 changes: 1 addition & 1 deletion .version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

VERSION=0.11.0 #
VERSION=0.13.0-SNAPSHOT #
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
## How to run unit tests over release scripts
1. Install [bats-core](https://github.com/bats-core/bats-core)
2. Go to tests directory
3. Run `bats release.bats`
3. Run `bats *.bats`
14 changes: 14 additions & 0 deletions hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ function get_master_branch_name {
echo "master"
}

# Hook method to define the patter for support branches
# Parameter $1 - support branch identifer, i.e. 2.x
# Returns support branches name as text, i.e. support-2.x
function format_support_branch_name {
echo "support-$1"
}

# Hook method to define the patter for support master branches
# Parameter $1 - support branch identifer, i.e. 2.x
# Returns support branches name as text, i.e. master-2.x
function format_support_master_branch_name {
echo "master-$1"
}

# Hook method to format the release branch name
# Parameter $1 - version as text
# Returns the formatted release branch name as text
Expand Down
6 changes: 3 additions & 3 deletions hotfix_finish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ git reset --hard
set_modules_version $HOTFIX_VERSION
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
if ! is_workspace_clean
then
# commit hotfix versions
git commit -am "Release hotfix $HOTFIX_VERSION"
Expand All @@ -64,7 +64,7 @@ git reset --hard
git checkout ${MASTER_BRANCH} && git pull ${REMOTE_REPO}
git merge --no-edit ${HOTFIX_BRANCH}

# create release tag and push master
# create release tag
HOTFIX_TAG=`format_release_tag "${HOTFIX_VERSION}"`
git tag -a "${HOTFIX_TAG}" -m "Release ${HOTFIX_VERSION}"

Expand All @@ -75,7 +75,7 @@ NEXT_SNAPSHOT_VERSION=`format_snapshot_version "${NEXT_VERSION}"`
set_modules_version "${NEXT_SNAPSHOT_VERSION}"
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
if ! is_workspace_clean
then
# commit next snapshot versions
git commit -am "Start next iteration with ${NEXT_SNAPSHOT_VERSION} after hotfix ${HOTFIX_VERSION}"
Expand Down
2 changes: 1 addition & 1 deletion hotfix_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ git checkout -b ${HOTFIX_BRANCH}
set_modules_version ${HOTFIX_SNAPSHOT_VERSION}
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
if ! is_workspace_clean
then
# commit hotfix versions
git commit -am "Start hotfix ${HOTFIX_SNAPSHOT_VERSION}"
Expand Down
31 changes: 17 additions & 14 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ fi
check_local_workspace_state "release"

git checkout ${DEVELOP_BRANCH} && git pull ${REMOTE_REPO}
git checkout -b ${RELEASE_BRANCH}

# check and create master branch if not present
if is_branch_existing ${MASTER_BRANCH} || is_branch_existing remotes/${REMOTE_REPO}/${MASTER_BRANCH}
then
git checkout ${MASTER_BRANCH} && git pull ${REMOTE_REPO}
else
git checkout -b ${MASTER_BRANCH}
git push --set-upstream ${REMOTE_REPO} ${MASTER_BRANCH}
fi

git checkout ${DEVELOP_BRANCH} && git checkout -b ${RELEASE_BRANCH}

build_snapshot_modules
cd ${GIT_REPO_DIR}
Expand All @@ -48,7 +58,7 @@ git reset --hard
set_modules_version ${RELEASE_VERSION}
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
if ! is_workspace_clean
then
# commit release versions
git commit -am "Prepare release ${RELEASE_VERSION}"
Expand All @@ -61,36 +71,29 @@ cd ${GIT_REPO_DIR}
git reset --hard

# merge current develop (over release branch) into master
if is_branch_existing ${MASTER_BRANCH} || is_branch_existing remotes/${REMOTE_REPO}/${MASTER_BRANCH}
then
git checkout ${MASTER_BRANCH} && git pull ${REMOTE_REPO}
else
git checkout -b ${MASTER_BRANCH}
git push --set-upstream ${REMOTE_REPO} ${MASTER_BRANCH}
fi

git checkout ${MASTER_BRANCH}
git merge -X theirs --no-edit ${RELEASE_BRANCH}

# create release tag on master
RELEASE_TAG=`format_release_tag "${RELEASE_VERSION}"`
git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_VERSION}"

git checkout ${RELEASE_BRANCH}
# merge release into develop
git checkout ${DEVELOP_BRANCH}
git merge -X theirs --no-edit ${RELEASE_BRANCH}

NEXT_SNAPSHOT_VERSION=`format_snapshot_version "${NEXT_VERSION}"`
set_modules_version "${NEXT_SNAPSHOT_VERSION}"
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
if ! is_workspace_clean
then
# Commit next snapshot versions into develop
git commit -am "Start next iteration with ${NEXT_SNAPSHOT_VERSION}"
else
echo "Nothing to commit..."
fi

git checkout ${DEVELOP_BRANCH}

if git merge --no-edit ${RELEASE_BRANCH}
then
# Nope, doing that automtically is too dangerous. But the command is great!
Expand Down
113 changes: 113 additions & 0 deletions support_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
set -e

SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ -f "${SCRIPT_PATH}/.version.sh" ]; then
source ${SCRIPT_PATH}/.version.sh
else
VERSION="UNKNOWN VERSION"
fi

echo "Release scripts (release, version: ${VERSION})"

if [[ ! -f "${SCRIPT_PATH}/.common-util.sh" ]]; then
echo 'Missing file .common-util.sh. Aborting'
exit -1
fi

source ${SCRIPT_PATH}/.common-util.sh


SUPPORT_BRANCH=`format_support_branch_name $1`
SUPPORT_MASTER_BRANCH=`format_support_master_branch_name $1`
RELEASE_VERSION=$2
NEXT_VERSION=$3

if [ $# -ne 3 ]
then
echo 'Usage: support_release.sh <support-branch-suffix> <release-version> <next-snapshot-version>'
echo 'For example: support_release.sh 3.x 3.2 3.3'
exit 2
fi

RELEASE_BRANCH=`format_release_branch_name "$RELEASE_VERSION"`

if [ ! "${CURRENT_BRANCH}" = "${SUPPORT_BRANCH}" ]
then
echo "Please checkout the branch '${SUPPORT_BRANCH}' before processing this release script."
exit 1
fi

check_local_workspace_state "release"

if is_branch_existing "remotes/${REMOTE_REPO}/${SUPPORT_BRANCH}"
then
git pull ${REMOTE_REPO}
fi

git checkout -b ${RELEASE_BRANCH}

build_snapshot_modules
cd ${GIT_REPO_DIR}
git reset --hard

set_modules_version ${RELEASE_VERSION}
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
then
# commit release versions
git commit -am "Prepare release ${RELEASE_VERSION}"
else
echo "Nothing to commit..."
fi

build_release_modules
cd ${GIT_REPO_DIR}
git reset --hard

# merge current develop (over release branch) into master-x.y
if is_branch_existing ${SUPPORT_MASTER_BRANCH} || is_branch_existing remotes/${REMOTE_REPO}/${SUPPORT_MASTER_BRANCH}
then
git checkout ${SUPPORT_MASTER_BRANCH} && git pull ${REMOTE_REPO}
else
git checkout -b ${SUPPORT_MASTER_BRANCH}
git push --set-upstream ${REMOTE_REPO} ${SUPPORT_MASTER_BRANCH}
fi

git merge -X theirs --no-edit ${RELEASE_BRANCH}

# create release tag on master-x.y
RELEASE_TAG=`format_release_tag "${RELEASE_VERSION}"`
git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_VERSION}"

git checkout ${RELEASE_BRANCH}

NEXT_SNAPSHOT_VERSION=`format_snapshot_version "${NEXT_VERSION}"`
set_modules_version "${NEXT_SNAPSHOT_VERSION}"
cd ${GIT_REPO_DIR}

if ! git diff-files --quiet --ignore-submodules --
then
# Commit next snapshot versions into develop
git commit -am "Start next iteration with ${NEXT_SNAPSHOT_VERSION}"
else
echo "Nothing to commit..."
fi

git checkout ${SUPPORT_BRANCH}

if git merge --no-edit ${RELEASE_BRANCH}
then
# Nope, doing that automtically is too dangerous. But the command is great!
echo "# Okay, now you've got a new tag and commits on ${RELEASE_BRANCH} and ${SUPPORT_BRANCH}."
echo "# Please check if everything looks as expected and then push."
echo "# Use this command to push all at once or nothing, if anything goes wrong:"
echo "git push --atomic ${REMOTE_REPO} ${SUPPORT_MASTER_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing"
else
echo "# Okay, you have got a conflict while merging onto ${SUPPORT_BRANCH}"
echo "# but don't panic, in most cases you can easily resolve the conflicts (in some cases you even do not need to merge all)."
echo "# Please do so and finish the release process with the following command:"
echo "git push --atomic ${REMOTE_REPO} ${SUPPORT_MASTER_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing"
fi
10 changes: 10 additions & 0 deletions tests/common-util-test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bats

load tests_common

@test "support branch becomes prefix defined in hooks" {
ls -la
source .release-scripts-hooks.sh
SUPPORT_NAME=`format_support_branch_name 29.x`
[[ "${SUPPORT_NAME}" == "support-29.x" ]]
}
Loading