From c3a5f3f46bb3bd2ee8662797ac39d0f9729fac6b Mon Sep 17 00:00:00 2001 From: Oleg Balunenko Date: Fri, 11 Aug 2023 19:00:15 +0400 Subject: [PATCH] chore: Bump go-tools image to v1.1.0 (#77) * chore: Bump go-tools image to v1.1.0 * chore: Use svu in release script --- Makefile | 3 ++ build/docker/go-tools/Dockerfile | 2 +- scripts/release/new-version.sh | 54 +++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 53687873..e669008f 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ VERSION ?= $(shell git describe --tags $(git rev-list --tags --max-count=1)) APP_NAME?=ge-tax-calc SHELL := env APP_NAME=$(APP_NAME) $(SHELL) +RELEASE_BRANCH?=master +SHELL := env RELEASE_BRANCH=$(RELEASE_BRANCH) $(SHELL) + COMPOSE_TOOLS_FILE=deployments/docker-compose/go-tools-docker-compose.yml COMPOSE_TOOLS_CMD_BASE=docker compose -f $(COMPOSE_TOOLS_FILE) COMPOSE_TOOLS_CMD_UP=$(COMPOSE_TOOLS_CMD_BASE) up --remove-orphans --exit-code-from diff --git a/build/docker/go-tools/Dockerfile b/build/docker/go-tools/Dockerfile index a450fa69..2f3807ec 100644 --- a/build/docker/go-tools/Dockerfile +++ b/build/docker/go-tools/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/obalunenko/go-tools:v1.0.0 AS builder +FROM ghcr.io/obalunenko/go-tools:v1.1.0 AS builder CMD ["/bin/sh", "-c", ""] \ No newline at end of file diff --git a/scripts/release/new-version.sh b/scripts/release/new-version.sh index 28f7a61d..98935f02 100755 --- a/scripts/release/new-version.sh +++ b/scripts/release/new-version.sh @@ -2,10 +2,39 @@ set -Eeuo pipefail -SCRIPT_NAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" +SCRIPT_NAME="$(basename "$0")" +SCRIPT_DIR="$(dirname "$0")" +REPO_ROOT="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)" +SCRIPTS_DIR="${REPO_ROOT}/scripts" + +source "${SCRIPTS_DIR}/helpers-source.sh" + +APP=${APP_NAME} + +RELEASE_BRANCH=${RELEASE_BRANCH:-"release"} + +echo "${SCRIPT_NAME} is running fo ${APP}... " + +checkInstalled 'svu' echo "${SCRIPT_NAME} is running... " +function requireReleaseBranch() { + err=0 + branch=$(git branch --show-current) + + echo "Current branch is: ${branch}" + + if [[ ${branch} != "${RELEASE_BRANCH}" ]]; then + err=1 + fi + + if [[ ${err} == 1 ]]; then + echo >&2 "Please checkout to ${RELEASE_BRANCH} branch." + exit 1 + fi +} + function require_clean_work_tree() { # Update the index git update-index -q --ignore-submodules --refresh @@ -32,7 +61,10 @@ function require_clean_work_tree() { } function menu() { + PREV_VERSION=$(svu current) clear + + echo "Current version: ${PREV_VERSION}" printf "Select what you want to update: \n" printf "1 - Major update\n" printf "2 - Minor update\n" @@ -40,27 +72,18 @@ function menu() { printf "4 - Exit\n" read -r selection - SHORTCOMMIT="$(git rev-parse --short HEAD)" - - PREV_VERSION="$(git tag | sort -V | tail -1)" - if [ -z "${PREV_VERSION}" ] || [ "${PREV_VERSION}" = "${SHORTCOMMIT}" ]; then - PREV_VERSION="v0.0.0" - fi - - echo "Current version: ${PREV_VERSION}" - case "$selection" in 1) printf "Major updates......\n" - NEW_VERSION=$(echo ${PREV_VERSION} | sed 's/\(.*v\)\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2;\3;\4;\1/g' | sort -t';' -k 1,1n -k 2,2n -k 3,3n | tail -n 1 | awk -F';' '{printf "%s%d.%d.%d", $4, ($1+1),0,0 }') + NEW_VERSION=$(svu major) ;; 2) printf "Run Minor update.........\n" - NEW_VERSION=$(echo ${PREV_VERSION} | sed 's/\(.*v\)\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2;\3;\4;\1/g' | sort -t';' -k 1,1n -k 2,2n -k 3,3n | tail -n 1 | awk -F';' '{printf "%s%d.%d.%d", $4, $1,($2+1),0 }') + NEW_VERSION=$(svu minor) ;; 3) printf "Patch update.........\n" - NEW_VERSION=$(echo ${PREV_VERSION} | sed 's/\(.*v\)\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2;\3;\4;\1/g' | sort -t';' -k 1,1n -k 2,2n -k 3,3n | tail -n 1 | awk -F';' '{printf "%s%d.%d.%d", $4, $1,$2,($3 + 1) }') + NEW_VERSION=$(svu patch) ;; 4) printf "Exit................................\n" @@ -75,6 +98,9 @@ function menu() { } +## Check if release branch +requireReleaseBranch + ## Check if git is clean require_clean_work_tree "create new version" @@ -92,7 +118,7 @@ while true; do case $yn in [Yy]*) - git tag -a "${NEW_TAG}" -m "${NEW_TAG}" && + git tag -a "${NEW_TAG}" -m "${NEW_TAG}" && git push --tags break