Skip to content

Commit

Permalink
Rename tag script to release and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mraffonso committed Mar 19, 2024
1 parent e895337 commit bf4a47b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 53 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ ShortVersion.parse("1.3") > SemanticVersion.parse("1.2.3") # => true

## Releasing

Creating a realease is just tagging a git commit. The `./script/tag` shell script should be used for creating tags.
Creating a release is three steps: tag a commit (the current one), push the tag to origin, and create a github release. The `./script/release` script was created to automate this and provide a few guard rails.

The current release workflow is:

* update the version specified in `shard.yml`
* commit with the message "Bump version to x.x.x"
* push to main
* run the tag script with no arguments `./script/tag`
* confirm tag creation
* run the release script with no arguments `./script/release`
* confirm release creation

And that's it, a release is created.

Expand Down
112 changes: 62 additions & 50 deletions script/tag → script/release
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
#!/bin/sh

VERSION=$(shards version)
VERSION="v$(shards version)"
SHORT_HASH=$(git rev-parse --short HEAD)
DESCRIPTION="Tag the current commit ($SHORT_HASH)."
DESCRIPTION="Tag and release the current commit ($SHORT_HASH)."

check_if_tag_exists() {
git ls-remote --tags 2>/dev/null | grep "$1" 1>/dev/null
if [ $? -eq 0 ]; then
echo "Git tag $1 exists."
exit 1
confirm_proceeding() {
while true; do
read -p "Do you want to tag and release this commit? (y/N) " yn
case $yn in
[Yy]*)
break;;
[Nn]*)
exit;;
"")
exit;;
*)
echo "Please answer [y]es or [n]o.";;
esac
done
}

gh_authenticated() {
gh auth status 1> /dev/null 2> /dev/null
if [ $? -gt 0 ]; then
print_error "gh is not logged in."
exit 1
fi
echo "."
}

parse_opts() {
case $1 in
--help|-h)
print_usage;;
--check|-c)
if [ $# -eq 2 ]; then
tag_exists $2
echo "Git tag $2 does not exist."
else
tag_exists $VERSION
echo "Git tag $VERSION does not exist."
fi
;;
-*)
print_error "unknown option \"$1\"";;
*)
run_release $1;;
esac
}

print_commands() {
echo $DESCRIPTION
echo
echo "Commands:"
echo
echo " git tag -a \"v$1\" -m \"Tagged v$1\""
echo " git tag -a \"$1\" -m \"Tagged $1\""
echo " git push origin --tags"
echo " gh release create "$1" --generate-notes"
echo
}

Expand Down Expand Up @@ -51,56 +89,30 @@ print_usage() {
exit
}

parse_opts() {
case $1 in
--help|-h)
print_usage;;
--check|-c)
if [ $# -eq 2 ]; then
check_if_tag_exists $2
echo "Git tag $2 does not exist."
else
check_if_tag_exists $VERSION
echo "Git tag $VERSION does not exist."
fi
;;
-*)
print_error "unknown option \"$1\"";;
*)
check_if_tag_exists $1
print_commands $1
confirm_tagging
tag_commit $1
;;
esac
run_release() {
tag_exists $1
print_commands $1
confirm_proceeding
tag_and_release $1
}

confirm_tagging() {
while true; do
read -p "Do you want to tag this commit? (y/N) " yn
case $yn in
[Yy]*)
break;;
[Nn]*)
exit;;
"")
exit;;
*)
echo "Please answer [y]es or [n]o.";;
esac
done
tag_exists() {
git ls-remote --tags 2>/dev/null | grep "/$1$" 1>/dev/null
if [ $? -eq 0 ]; then
echo "Git tag $1 exists."
exit 1
fi
}

tag_commit() {
git tag -a "v$1" -m "Tagged v$1"
tag_and_release() {
gh_authenticated
git tag -a "$1" -m "Tagged $1"
git push origin --tags
gh release create "$1" --generate-notes
}

if [ $# -eq 0 ]; then
check_if_tag_exists $VERSION
print_commands $VERSION
confirm_tagging
tag_commit $VERSION
run_release $VERSION
elif [ $# -gt 0 ]; then
parse_opts "$@"
fi

0 comments on commit bf4a47b

Please sign in to comment.