Skip to content

Commit

Permalink
Add tag.sh for easily making releases (#1649)
Browse files Browse the repository at this point in the history
Add bash script for tagging commits with calver version and pushing to remote
  • Loading branch information
djahandarie authored Dec 10, 2024
1 parent 0acaad3 commit a5609e9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# bash script which tags the current commit with a calver version
# and pushes the tag to the remote repository

# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

if [[ $(git branch --show-current) != "master" ]]; then
echo -e "${RED}Please only tag commits on master branch.${NC}"
exit 1
fi

echo -e "${YELLOW}Checking if branch is up to date...${NC}"

changed=0
git remote update && git status -uno | grep -q 'Your branch is behind' && changed=1
if [ $changed = 1 ]; then
echo -e "${RED}Please git pull before tagging.${NC}"
exit 1
fi

# get the current date in the format YY.MM.DD
DATE=$(date +%y.%-m.%-d)

# create plain tag with .0 at end
TAG=$DATE.0

# Ask user to confirm the commit and the tag name
echo -e "${YELLOW}Current HEAD of master branch:${NC}"
git log -1 --decorate
echo
echo -e -n "${YELLOW}Tagging current HEAD of master with tag ${TAG}. Are you sure? (y/n): ${NC}"
read -p "" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Tagging aborted.${NC}"
exit 1
fi

git tag $TAG

echo -e -n "${YELLOW}Do you want to push the tag ${TAG} to the remote repository (which will cause a pre-release to get created)? (y/n): ${NC}"
read -p "" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Push aborted.${NC}"
exit 1
fi

git push origin $TAG

0 comments on commit a5609e9

Please sign in to comment.