From 8c20071ef6cfa70f57c3ec3a3db80d3689e6dc7b Mon Sep 17 00:00:00 2001 From: Rishi K Date: Sun, 16 Jan 2022 13:30:26 +0530 Subject: [PATCH] chore: add release-tag script To create & push release tag --- release-tag | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 release-tag diff --git a/release-tag b/release-tag new file mode 100755 index 0000000..1adc2d9 --- /dev/null +++ b/release-tag @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + + +repo_path=$( realpath $( dirname ${BASH_SOURCE[0]} ) ) + +# validate if the path is a git repository +if ! git -C ${repo_path} rev-parse; then + printf '%s\n' "${repo_path} is not a git repository!" 1>&2 + exit 1 +else + printf '%s\n\n' "Repository path: ${repo_path}" +fi + +# check if main branch exist or not +if [[ -z $( git branch --list main ) ]]; then + printf '%s\n' "main branch doesn't exist!" 1>&2 + exit 1 +fi + +# generate tag name +commit_count=$( git --git-dir="${repo_path}"/.git rev-list --count main ) +latest_commit=$( git --git-dir="${repo_path}"/.git rev-parse --short main ) +tag_name="r${commit_count}.${latest_commit}" + +# create tag to the most recent commit on the main branch +read -r -p "Create tag on main: ${tag_name}: (Y/n): " response +[[ ${response} != "Y" && ${response} != "y" ]] && exit 1 +git tag ${tag_name} main + +# check if tag created successfully by checking if the tag exist or not +if [[ -z $( git tag --list ${tag_name} ) ]]; then + printf '%s\n' "No tag exist with name ${tag_name}" 1>&2 + printf '%s\n' "Tag may not be created successfully!" 1>&2 + exit 1 +fi + +# if exist, ask the user wether to push the tag or not +read -r -p "Push tag ${tag_name}: (Y/n): " response +[[ ${response} != "Y" && ${response} != "y" ]] && exit 1 +git push origin ${tag_name}