From 56475fcf0425a20cb3b1450cfb5747757ae6fc8d Mon Sep 17 00:00:00 2001 From: Denys Golubiev Date: Tue, 5 Mar 2019 17:58:59 +0100 Subject: [PATCH 01/11] Add support_release.sh --- support_release.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 support_release.sh diff --git a/support_release.sh b/support_release.sh new file mode 100755 index 0000000..03930b1 --- /dev/null +++ b/support_release.sh @@ -0,0 +1,103 @@ +#!/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 + source ${SCRIPT_PATH}/.common-util.sh +else + echo 'Missing file .common-util.sh. Aborting' + exit -1 +fi + +SUPPORT_BRANCH=$1 +RELEASE_VERSION=$2 +NEXT_VERSION=$3 + +if [ $# -ne 3 ] +then + echo 'Usage: support_release.sh ' + echo 'For example: support_release.sh support-3.x 3.2 3.3' + exit 2 +fi + +if ! is_branch_existing ${SUPPORT_BRANCH} && ! is_branch_existing remotes/${REMOTE_REPO}/${SUPPORT_BRANCH} +then + echo "Cannot find branch '${SUPPORT_BRANCH}'" + echo 'Usage: support_release.sh ' + echo 'For example: support_release.sh support-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" + +git checkout ${SUPPORT_BRANCH} && git pull ${REMOTE_REPO} +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 + +# create release tag on release branch +RELEASE_TAG=`format_release_tag "${RELEASE_VERSION}"` +git tag -a "${RELEASE_TAG}" -m "Release ${RELEASE_VERSION}" + +git checkout ${SUPPORT_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 + +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} ${RELEASE_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} ${RELEASE_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing" +fi From 64e2712ec4a2736c3d2e8130f440d2d6a4e6de5c Mon Sep 17 00:00:00 2001 From: Denys Golubiev Date: Wed, 6 Mar 2019 11:48:00 +0100 Subject: [PATCH 02/11] Add support_release script to work with support branches --- .common-util.sh | 3 ++- .hooks-default.sh | 14 ++++++++++ hooks.sh | 14 ++++++++++ support_release.sh | 50 +++++++++++++++++++++-------------- tests/common-util-test.bats | 10 +++++++ tests/release.bats | 25 +----------------- tests/support_release.bats | 52 +++++++++++++++++++++++++++++++++++++ tests/test-hooks.sh | 18 +++++++++++-- tests/tests_common.bash | 29 +++++++++++++++++++++ 9 files changed, 168 insertions(+), 47 deletions(-) create mode 100644 tests/common-util-test.bats create mode 100644 tests/support_release.bats create mode 100644 tests/tests_common.bash diff --git a/.common-util.sh b/.common-util.sh index fe776e7..521b70b 100644 --- a/.common-util.sh +++ b/.common-util.sh @@ -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 @@ -36,3 +36,4 @@ function is_branch_existing { return 1 fi } + diff --git a/.hooks-default.sh b/.hooks-default.sh index 04c7775..2a6c3bc 100644 --- a/.hooks-default.sh +++ b/.hooks-default.sh @@ -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 diff --git a/hooks.sh b/hooks.sh index 5e55dd8..72a2915 100644 --- a/hooks.sh +++ b/hooks.sh @@ -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 diff --git a/support_release.sh b/support_release.sh index 03930b1..2139d93 100755 --- a/support_release.sh +++ b/support_release.sh @@ -11,33 +11,26 @@ fi echo "Release scripts (release, version: ${VERSION})" -if [ -f "${SCRIPT_PATH}/.common-util.sh" ]; then - source ${SCRIPT_PATH}/.common-util.sh -else +if [[ ! -f "${SCRIPT_PATH}/.common-util.sh" ]]; then echo 'Missing file .common-util.sh. Aborting' exit -1 fi -SUPPORT_BRANCH=$1 +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 ' - echo 'For example: support_release.sh support-3.x 3.2 3.3' - exit 2 -fi - -if ! is_branch_existing ${SUPPORT_BRANCH} && ! is_branch_existing remotes/${REMOTE_REPO}/${SUPPORT_BRANCH} -then - echo "Cannot find branch '${SUPPORT_BRANCH}'" - echo 'Usage: support_release.sh ' - echo 'For example: support_release.sh support-3.x 3.2 3.3' + echo 'Usage: support_release.sh ' + 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}" ] @@ -48,7 +41,11 @@ fi check_local_workspace_state "release" -git checkout ${SUPPORT_BRANCH} && git pull ${REMOTE_REPO} +if is_branch_existing "remotes/${REMOTE_REPO}/${SUPPORT_BRANCH}" +then + git pull ${REMOTE_REPO} +fi + git checkout -b ${RELEASE_BRANCH} build_snapshot_modules @@ -70,11 +67,22 @@ build_release_modules cd ${GIT_REPO_DIR} git reset --hard -# create release tag on release branch +# 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 ${SUPPORT_BRANCH} +git checkout ${RELEASE_BRANCH} NEXT_SNAPSHOT_VERSION=`format_snapshot_version "${NEXT_VERSION}"` set_modules_version "${NEXT_SNAPSHOT_VERSION}" @@ -88,16 +96,18 @@ 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} ${RELEASE_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing" + 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} ${RELEASE_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing" + echo "git push --atomic ${REMOTE_REPO} ${SUPPORT_MASTER_BRANCH} ${SUPPORT_BRANCH} --follow-tags # all or nothing" fi diff --git a/tests/common-util-test.bats b/tests/common-util-test.bats new file mode 100644 index 0000000..1dc960f --- /dev/null +++ b/tests/common-util-test.bats @@ -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" ]] +} diff --git a/tests/release.bats b/tests/release.bats index 7705aa7..d46e621 100644 --- a/tests/release.bats +++ b/tests/release.bats @@ -1,29 +1,6 @@ #!/usr/bin/env bats -# -WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" -LOCALREPO=${WORKDIR}/localrepo -REMOTEREPO=${WORKDIR}/remoterepo - -setup() { - mkdir -p "${LOCALREPO}" "${REMOTEREPO}" - cd "${REMOTEREPO}" && git init --bare - git clone "${REMOTEREPO}" "${LOCALREPO}" - cd "${LOCALREPO}" - echo "somedata" > somefile - git add somefile - git commit -m "add somefile" - git checkout -b develop - git submodule add ${BATS_TEST_DIRNAME}/.. release-scripts - cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh - git add release-scripts - git commit -m "register release-scripts" - git push -u origin master develop -} -teardown() { - cd .. - [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" -} +load tests_common @test "run release script from develop" { git checkout develop diff --git a/tests/support_release.bats b/tests/support_release.bats new file mode 100644 index 0000000..031f158 --- /dev/null +++ b/tests/support_release.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load tests_common + +@test "run release script from support branch" { + ./release-scripts/release.sh 32.1 33.0 + git push --atomic origin master develop --follow-tags + + git tag | grep v32.1 + + git checkout v32.1 + git branch support-32.x + + git checkout develop + echo "some 33-related work" >> somefile + git add somefile + git commit -m "Do some 33-related work" + ./release-scripts/release.sh 33.0 33.1 + git push --atomic origin master develop --follow-tags + + git tag | grep v33.0 + + git checkout develop + [[ "$(cat version.txt)" == "33.1-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + git checkout support-32.x + echo "some 32-support work" >> somefile + git add somefile + git commit -m "Do some 32-support related work" + + ./release-scripts/support_release.sh 32.x 32.2 32.3 + git push --atomic origin master-32.x support-32.x --follow-tags + + git tag | grep v32.2 + + git checkout v32.2 + [[ "$(cat version.txt)" == "32.2" ]] || cat version.txt "Incorrect support tag version" + cat somefile | grep "some 32-support work" > /dev/null + + git checkout master-32.x + [[ "$(cat version.txt)" == "32.2" ]] || cat version.txt "Incorrect support master version" + cat somefile | grep "some 32-support work" > /dev/null + + git checkout support-32.x + [[ "$(cat version.txt)" == "32.3-SNAPSHOT" ]] || cat version.txt "Incorrect support branch snapshot version" + cat somefile | grep "some 32-support work" > /dev/null + + git checkout master + [[ "$(cat version.txt)" == "33.0" ]] || cat version.txt "Incorrect master version" + [[ "$(grep "some 32-support work" somefile)" != "0" ]] +} + diff --git a/tests/test-hooks.sh b/tests/test-hooks.sh index e69f33f..e31b9fb 100644 --- a/tests/test-hooks.sh +++ b/tests/test-hooks.sh @@ -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 @@ -57,13 +71,13 @@ function format_hotfix_branch_name { # Hook to build the snapshot modules before release # You can build and run your tests here to avoid releasing an unstable build function build_snapshot_modules { - echo "do nothing" >> /dev/null + echo "build_snapshot_modules" } # Hook to build the released modules after release # You can deploy your artifacts here function build_release_modules { - echo "do nothing" >> /dev/null + echo "build_release_modules" } # Should set version numbers in your modules diff --git a/tests/tests_common.bash b/tests/tests_common.bash new file mode 100644 index 0000000..6611e3e --- /dev/null +++ b/tests/tests_common.bash @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" +LOCALREPO=${WORKDIR}/localrepo +REMOTEREPO=${WORKDIR}/remoterepo + +setup() { + mkdir -p "${LOCALREPO}" "${REMOTEREPO}" + cd "${REMOTEREPO}" && git init --bare + git clone "${REMOTEREPO}" "${LOCALREPO}" + cd "${LOCALREPO}" + echo "somedata" > somefile + git add somefile + git commit -m "add somefile" + git checkout -b develop + mkdir release-scripts + cp -r ${BATS_TEST_DIRNAME}/../. release-scripts/ + rm -rf release-scripts/.git release-scripts/tests + cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh + git add release-scripts .release-scripts-hooks.sh + git commit -m "register release-scripts" + git status + git push -u origin master develop +} + +teardown() { + cd .. + [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" +} From 834859363a6d25d0c73bd393028e42f90c419ac2 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Wed, 20 Jun 2018 08:30:34 +0200 Subject: [PATCH 03/11] Prepare release 0.11.0 --- .version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version.sh b/.version.sh index c1a669b..6054baf 100644 --- a/.version.sh +++ b/.version.sh @@ -1,3 +1,3 @@ #!/bin/bash -VERSION=0.11.0-SNAPSHOT # +VERSION=0.11.0 # From 23c62e6f9debbd9ec936ee7e51c3f0b9f4bb36b4 Mon Sep 17 00:00:00 2001 From: Denys Golubiev Date: Tue, 5 Mar 2019 16:09:01 +0100 Subject: [PATCH 04/11] Add tests for release scripts --- README.md | 5 +++ tests/release.bats | 82 +++++++++++++++++++++++++++++++++++++++++++++ tests/test-hooks.sh | 75 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 tests/release.bats create mode 100644 tests/test-hooks.sh diff --git a/README.md b/README.md index 2233233..771e8ce 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,8 @@ ## Revert a (local) release $ ./revert_release + +## 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` diff --git a/tests/release.bats b/tests/release.bats new file mode 100644 index 0000000..7705aa7 --- /dev/null +++ b/tests/release.bats @@ -0,0 +1,82 @@ +#!/usr/bin/env bats +# +WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" +LOCALREPO=${WORKDIR}/localrepo +REMOTEREPO=${WORKDIR}/remoterepo + +setup() { + mkdir -p "${LOCALREPO}" "${REMOTEREPO}" + cd "${REMOTEREPO}" && git init --bare + git clone "${REMOTEREPO}" "${LOCALREPO}" + cd "${LOCALREPO}" + echo "somedata" > somefile + git add somefile + git commit -m "add somefile" + git checkout -b develop + git submodule add ${BATS_TEST_DIRNAME}/.. release-scripts + cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh + git add release-scripts + git commit -m "register release-scripts" + git push -u origin master develop +} + +teardown() { + cd .. + [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" +} + +@test "run release script from develop" { + git checkout develop + echo "some work" >> somefile + git add somefile + git commit -m "Do some work" + ./release-scripts/release.sh 23.1 23.2 + git push --atomic origin master develop --follow-tags + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + cat somefile | grep "some work" > /dev/null + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some work" > /dev/null +} + +@test "run hotfix from develop" { + ./release-scripts/release.sh 23.1 23.2 + git push --atomic origin master develop --follow-tags + ./release-scripts/hotfix_start.sh 23.1.1 + git push --set-upstream origin hotfix-23.1.1 + + echo "some fix" >> somefile + git add somefile + git commit -m "make some fix" + + [[ "$(cat version.txt)" == "23.1.1-SNAPSHOT" ]] || cat version.txt "Incorrect hotfix branch version" + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + + git checkout hotfix-23.1.1 + ./release-scripts/hotfix_finish.sh 23.1.1 23.2 + git push --atomic origin master develop hotfix-23.1.1 --follow-tags + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + cat somefile | grep "some fix" + + git checkout master + [[ "$(cat version.txt)" == "23.1.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some fix" +} + + diff --git a/tests/test-hooks.sh b/tests/test-hooks.sh new file mode 100644 index 0000000..e69f33f --- /dev/null +++ b/tests/test-hooks.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# ********************** INFO ********************* +# This file is used to define default settings. +# Please do not change it. +# To override these settings please define functions +# with the same name in file hooks.sh in this directory +# or in file .release-script-hook.sh in parent directory +# ************************************************* +set -e + +# Hook method to format your release tag +# Parameter $1 - version as text +# Returns tag as text +function format_release_tag { + echo "v$1" +} + +# Hook method to format your next snapshot version +# Parameter $1 - version as text +# Returns snapshot version as text +function format_snapshot_version { + echo "$1-SNAPSHOT" +} + +# Hook method to define the remote repository name +# Returns the name of the remote repository as text +function get_remote_repo_name { + echo "origin" +} + +# Hook method to define the develop branch name +# Returns the develop branch name as text +function get_develop_branch_name { + echo "develop" +} + +# Hook method to define the master branch name +# Returns the master branch name as text +function get_master_branch_name { + echo "master" +} + +# Hook method to format the release branch name +# Parameter $1 - version as text +# Returns the formatted release branch name as text +function format_release_branch_name { + echo "release-$1" +} + +# Hook method to format the hotfix branch name +# Parameter $1 - version as text +# Returns the formatted hotfix branch name as text +function format_hotfix_branch_name { + echo "hotfix-$1" +} + +# Hook to build the snapshot modules before release +# You can build and run your tests here to avoid releasing an unstable build +function build_snapshot_modules { + echo "do nothing" >> /dev/null +} + +# Hook to build the released modules after release +# You can deploy your artifacts here +function build_release_modules { + echo "do nothing" >> /dev/null +} + +# Should set version numbers in your modules +# Parameter $1 - version as text +function set_modules_version { + echo "$1" > version.txt + git add version.txt + git commit -m "set version number $(echo $1)" version.txt +} From 8a1f9662f66f627cf19d356fc9fe164a435f5d44 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 10:30:04 +0100 Subject: [PATCH 05/11] correct version --- .version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version.sh b/.version.sh index 6054baf..677d695 100644 --- a/.version.sh +++ b/.version.sh @@ -1,3 +1,3 @@ #!/bin/bash -VERSION=0.11.0 # +VERSION=0.12.0-SNAPSHOT # From c69f234fde0b1b932b8694117452e3b79139fe20 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 11:00:22 +0100 Subject: [PATCH 06/11] use current sources for tests --- tests/release.bats | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/release.bats b/tests/release.bats index 7705aa7..03073d6 100644 --- a/tests/release.bats +++ b/tests/release.bats @@ -1,5 +1,6 @@ #!/usr/bin/env bats # +SRCDIR=`pwd`/.. WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" LOCALREPO=${WORKDIR}/localrepo REMOTEREPO=${WORKDIR}/remoterepo @@ -13,7 +14,8 @@ setup() { git add somefile git commit -m "add somefile" git checkout -b develop - git submodule add ${BATS_TEST_DIRNAME}/.. release-scripts + mkdir release-scripts + find ${SRCDIR} -maxdepth 1 -type f -exec cp -a {} ./release-scripts \; cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh git add release-scripts git commit -m "register release-scripts" From 6d8c7dfcd2793e3d920bd98552941df1ca305595 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 11:49:02 +0100 Subject: [PATCH 07/11] Fix issue #5: dont push into master if locally missing but existing on remote --- .common-util.sh | 11 ++- README.md | 2 +- hotfix_finish.sh | 2 +- tests/release-without-local-master.bats | 111 ++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 tests/release-without-local-master.bats diff --git a/.common-util.sh b/.common-util.sh index fe776e7..db7550e 100644 --- a/.common-util.sh +++ b/.common-util.sh @@ -29,10 +29,19 @@ function check_local_workspace_state { } function is_branch_existing { - if [ `git branch -a --list "$1"` ] + if [ `git branch -a --list | grep "$1"` ] 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 +} diff --git a/README.md b/README.md index 771e8ce..d549be3 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/hotfix_finish.sh b/hotfix_finish.sh index 5b897dc..005b67c 100755 --- a/hotfix_finish.sh +++ b/hotfix_finish.sh @@ -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}" diff --git a/tests/release-without-local-master.bats b/tests/release-without-local-master.bats new file mode 100644 index 0000000..4b4eff8 --- /dev/null +++ b/tests/release-without-local-master.bats @@ -0,0 +1,111 @@ +#!/usr/bin/env bats +# +SRCDIR=`pwd`/.. +WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" +LOCALREPO=${WORKDIR}/localrepo +REMOTEREPO=${WORKDIR}/remoterepo + +setup() { + mkdir -p "${LOCALREPO}" "${REMOTEREPO}" + cd "${REMOTEREPO}" && git init --bare + git clone "${REMOTEREPO}" "${LOCALREPO}" + cd "${LOCALREPO}" + echo "somedata" > somefile + git add somefile + git commit -m "add somefile" + git checkout -b develop + mkdir release-scripts + find ${SRCDIR} -maxdepth 1 -type f -exec cp -a {} ./release-scripts \; + cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh + git add release-scripts + git commit -m "register release-scripts" + git push -u origin master develop + git branch -d master +} + +teardown() { + cd .. + [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" +} + +@test "run release script from develop" { + # Given + git checkout develop + echo "some work" >> somefile + git add somefile + git commit -m "Do some work" + ./release-scripts/release.sh 23.1 23.2 + + # develop should NOT be pushed + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + # master should NOT be pushed + git checkout master + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + # When + git checkout develop + git push --atomic origin master develop --follow-tags + + # Then + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + # develop should be pushed + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + cat somefile | grep "some work" > /dev/null + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some work" > /dev/null + + # master should be pushed + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" +} + +@test "run hotfix from develop" { + ./release-scripts/release.sh 23.1 23.2 + git push --atomic origin master develop --follow-tags + ./release-scripts/hotfix_start.sh 23.1.1 + git push --set-upstream origin hotfix-23.1.1 + + echo "some fix" >> somefile + git add somefile + git commit -m "make some fix" + + [[ "$(cat version.txt)" == "23.1.1-SNAPSHOT" ]] || cat version.txt "Incorrect hotfix branch version" + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + + git checkout hotfix-23.1.1 + ./release-scripts/hotfix_finish.sh 23.1.1 23.2 + + # master should not be pushed + git checkout master + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + git checkout hotfix-23.1.1 + git push --atomic origin master develop hotfix-23.1.1 --follow-tags + + # master should be pushed + git checkout master + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + cat somefile | grep "some fix" + + git checkout master + [[ "$(cat version.txt)" == "23.1.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some fix" +} From 5a87f88495dba7e7eec9887c4974be3788cfb390 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 13:02:03 +0100 Subject: [PATCH 08/11] support repositories without remote master branch --- .common-util.sh | 21 +++-- hotfix_finish.sh | 4 +- hotfix_start.sh | 2 +- release.sh | 25 +++--- tests/release-without-local-master.bats | 4 +- tests/release-without-remote-master.bats | 110 +++++++++++++++++++++++ 6 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 tests/release-without-remote-master.bats diff --git a/.common-util.sh b/.common-util.sh index db7550e..66f107f 100644 --- a/.common-util.sh +++ b/.common-util.sh @@ -29,12 +29,21 @@ function check_local_workspace_state { } function is_branch_existing { - if [ `git branch -a --list | grep "$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 { diff --git a/hotfix_finish.sh b/hotfix_finish.sh index 005b67c..e37732c 100755 --- a/hotfix_finish.sh +++ b/hotfix_finish.sh @@ -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" @@ -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}" diff --git a/hotfix_start.sh b/hotfix_start.sh index bf27616..788d26d 100755 --- a/hotfix_start.sh +++ b/hotfix_start.sh @@ -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}" diff --git a/release.sh b/release.sh index a7f28d1..c5e4b19 100755 --- a/release.sh +++ b/release.sh @@ -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} @@ -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}" @@ -61,14 +71,7 @@ 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 @@ -81,7 +84,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 into develop git commit -am "Start next iteration with ${NEXT_SNAPSHOT_VERSION}" diff --git a/tests/release-without-local-master.bats b/tests/release-without-local-master.bats index 4b4eff8..af878ea 100644 --- a/tests/release-without-local-master.bats +++ b/tests/release-without-local-master.bats @@ -28,7 +28,7 @@ teardown() { [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" } -@test "run release script from develop" { +@test "run release script from develop without local master" { # Given git checkout develop echo "some work" >> somefile @@ -66,7 +66,7 @@ teardown() { test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" } -@test "run hotfix from develop" { +@test "run hotfix from develop without local master" { ./release-scripts/release.sh 23.1 23.2 git push --atomic origin master develop --follow-tags ./release-scripts/hotfix_start.sh 23.1.1 diff --git a/tests/release-without-remote-master.bats b/tests/release-without-remote-master.bats new file mode 100644 index 0000000..da38591 --- /dev/null +++ b/tests/release-without-remote-master.bats @@ -0,0 +1,110 @@ +#!/usr/bin/env bats +# +SRCDIR=`pwd`/.. +WORKDIR="${BATS_TMPDIR}/release-test-$(date '+%Y-%m-%d_%H-%M-%S')" +LOCALREPO=${WORKDIR}/localrepo +REMOTEREPO=${WORKDIR}/remoterepo + +setup() { + mkdir -p "${LOCALREPO}" "${REMOTEREPO}" + cd "${REMOTEREPO}" && git init --bare + git clone "${REMOTEREPO}" "${LOCALREPO}" + cd "${LOCALREPO}" + echo "somedata" > somefile + git checkout -b develop + git add somefile + git commit -m "add somefile" + mkdir release-scripts + find ${SRCDIR} -maxdepth 1 -type f -exec cp -a {} ./release-scripts \; + cp ${BATS_TEST_DIRNAME}/test-hooks.sh .release-scripts-hooks.sh + git add release-scripts + git commit -m "register release-scripts" + git push -u origin develop +} + +teardown() { + cd .. + [[ -d "${WORKDIR}" ]] && rm -fr "${WORKDIR}" +} + +@test "run release script from develop without remote master" { + # Given + git checkout develop + echo "some work" >> somefile + git add somefile + git commit -m "Do some work" + ./release-scripts/release.sh 23.1 23.2 + + # develop should NOT be pushed + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + # master should NOT be pushed + git checkout master + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + # When + git checkout develop + git push --atomic origin master develop --follow-tags + + # Then + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + # develop should be pushed + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + cat somefile | grep "some work" > /dev/null + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some work" > /dev/null + + # master should be pushed + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" +} + +@test "run hotfix from develop without remote master" { + ./release-scripts/release.sh 23.1 23.2 + git push --atomic origin master develop --follow-tags + ./release-scripts/hotfix_start.sh 23.1.1 + git push --set-upstream origin hotfix-23.1.1 + + echo "some fix" >> somefile + git add somefile + git commit -m "make some fix" + + [[ "$(cat version.txt)" == "23.1.1-SNAPSHOT" ]] || cat version.txt "Incorrect hotfix branch version" + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + + git checkout v23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" + + git checkout master + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" + + git checkout hotfix-23.1.1 + ./release-scripts/hotfix_finish.sh 23.1.1 23.2 + + # master should not be pushed + git checkout master + test "$(git rev-parse @{u})" != "$(git rev-parse HEAD)" + + git checkout hotfix-23.1.1 + git push --atomic origin master develop hotfix-23.1.1 --follow-tags + + # master should be pushed + git checkout master + test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" + + git checkout develop + [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" + cat somefile | grep "some fix" + + git checkout master + [[ "$(cat version.txt)" == "23.1.1" ]] || cat version.txt "Incorrect master version" + cat somefile | grep "some fix" +} From 25f92de1cffbe69fd37a2a09f8822f7b3612bef5 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 13:04:09 +0100 Subject: [PATCH 09/11] Prepare release 0.12.0 --- .version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version.sh b/.version.sh index 677d695..9c8300f 100644 --- a/.version.sh +++ b/.version.sh @@ -1,3 +1,3 @@ #!/bin/bash -VERSION=0.12.0-SNAPSHOT # +VERSION=0.12.0 # From a322c20881d7c880c9efabe0d91a0273d503f405 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Fri, 8 Mar 2019 13:04:09 +0100 Subject: [PATCH 10/11] Start next iteration with 0.13.0-SNAPSHOT --- .version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version.sh b/.version.sh index 9c8300f..389bca1 100644 --- a/.version.sh +++ b/.version.sh @@ -1,3 +1,3 @@ #!/bin/bash -VERSION=0.12.0 # +VERSION=0.13.0-SNAPSHOT # From 38f90e028ac00df990b399ce8aa51e9a84187c37 Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Mon, 11 Mar 2019 08:13:59 +0100 Subject: [PATCH 11/11] issue/#8: Release branch contains release version (#14) --- release.sh | 6 +++--- tests/release-without-local-master.bats | 5 +++++ tests/release-without-remote-master.bats | 5 +++++ tests/release.bats | 8 ++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/release.sh b/release.sh index c5e4b19..50597d8 100755 --- a/release.sh +++ b/release.sh @@ -78,7 +78,9 @@ git merge -X theirs --no-edit ${RELEASE_BRANCH} 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}" @@ -92,8 +94,6 @@ 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! diff --git a/tests/release-without-local-master.bats b/tests/release-without-local-master.bats index af878ea..863f015 100644 --- a/tests/release-without-local-master.bats +++ b/tests/release-without-local-master.bats @@ -62,7 +62,12 @@ teardown() { [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" cat somefile | grep "some work" > /dev/null + git checkout release-23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect version in release-23.1" + cat somefile | grep "some work" > /dev/null + # master should be pushed + git checkout master test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" } diff --git a/tests/release-without-remote-master.bats b/tests/release-without-remote-master.bats index da38591..9b0741b 100644 --- a/tests/release-without-remote-master.bats +++ b/tests/release-without-remote-master.bats @@ -61,7 +61,12 @@ teardown() { [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" cat somefile | grep "some work" > /dev/null + git checkout release-23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect version in release-23.1" + cat somefile | grep "some work" > /dev/null + # master should be pushed + git checkout master test "$(git rev-parse @{u})" = "$(git rev-parse HEAD)" } diff --git a/tests/release.bats b/tests/release.bats index 03073d6..016458e 100644 --- a/tests/release.bats +++ b/tests/release.bats @@ -38,13 +38,17 @@ teardown() { git checkout develop [[ "$(cat version.txt)" == "23.2-SNAPSHOT" ]] || cat version.txt "Incorrect next snapshot version" - git checkout v23.1 + git checkout v23.1 [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect release version" cat somefile | grep "some work" > /dev/null - git checkout master + git checkout master [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect master version" cat somefile | grep "some work" > /dev/null + + git checkout release-23.1 + [[ "$(cat version.txt)" == "23.1" ]] || cat version.txt "Incorrect version in release-23.1" + cat somefile | grep "some work" > /dev/null } @test "run hotfix from develop" {