Skip to content

Commit 13cf9ab

Browse files
committed
feat(release): add support for VERSION_TAG_PREFIX_MODE
1 parent 1460a27 commit 13cf9ab

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ export DEFAULT_BRANCH=main
1616
export GIT_CLIFF__REMOTE__GITHUB__OWNER=toggle-corp
1717
export GIT_CLIFF__REMOTE__GITHUB__REPO=fugit
1818

19-
"$SCRIPT_DIR/scripts/release.sh"
19+
"$SCRIPT_DIR/scripts/release.sh" "$@"

scripts/release.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ DEFAULT_BRANCH=${DEFAULT_BRANCH?error}
1313
# TODO: Make sure to also update cliff.toml:footer to includes those archived changelogs as well
1414
START_COMMIT=${START_COMMIT:-$(git rev-list --max-parents=0 HEAD)}
1515
RELEASE_CUSTOM_HOOK="${RELEASE_CUSTOM_HOOK?error}"
16+
VERSION_TAG_PREFIX_MODE="${VERSION_TAG_PREFIX_MODE:-require}"
1617

1718
check_typos
1819
check_git_cliff
1920
check_semver
2021
check_gh
2122

23+
log_warning "Using VERSION_TAG_PREFIX_MODE=${VERSION_TAG_PREFIX_MODE}"
2224
echo "Generating GITHUB_TOKEN using gh (Used by git-cliff)"
2325
GITHUB_TOKEN="$(gh auth token)"
2426
export GITHUB_TOKEN
@@ -43,7 +45,25 @@ echo "Existing tags:"
4345
git for-each-ref --sort=-creatordate --format '- %(refname:short)' refs/tags | head -n 10
4446
echo
4547

46-
read -rp "Enter new version tag (e.g. v1.2.3, v1.2.3-dev0): " version_tag
48+
default_version="$1"
49+
# Decide prompt message based on VERSION_TAG_PREFIX_MODE
50+
case "$VERSION_TAG_PREFIX_MODE" in
51+
require)
52+
prompt_msg="Enter new version tag (must start with 'v', e.g. v1.2.3): "
53+
;;
54+
forbid)
55+
prompt_msg="Enter new version tag (must NOT start with 'v', e.g. 1.2.3): "
56+
;;
57+
ignore)
58+
prompt_msg="Enter new version tag (e.g. v1.2.3, v1.2.3-dev0): "
59+
;;
60+
*)
61+
log_error "Invalid VERSION_TAG_PREFIX_MODE: ${VERSION_TAG_PREFIX_MODE}. Should be require|forbid|ignore"
62+
exit 1
63+
;;
64+
esac
65+
66+
read -e -i "$default_version" -rp "$prompt_msg" version_tag
4767

4868
# Trim leading/trailing whitespace
4969
version_tag=$(echo "$version_tag" | xargs)
@@ -60,6 +80,25 @@ else
6080
exit 1
6181
fi
6282

83+
case "${VERSION_TAG_PREFIX_MODE}" in
84+
require)
85+
if [[ "${version_tag}" != v* ]]; then
86+
log_error "Error: version_tag must start with 'v' (got: ${version_tag})"
87+
exit 1
88+
fi
89+
;;
90+
forbid)
91+
if [[ "${version_tag}" == v* ]]; then
92+
log_error "Error: version_tag must NOT start with 'v' (got: ${version_tag})"
93+
exit 1
94+
fi
95+
;;
96+
ignore | "")
97+
# do nothing
98+
;;
99+
# NOTE: Invalid option is already checked during version prompt
100+
esac
101+
63102
# Define your cleanup or final function
64103
exit_message() {
65104
log_warning "-----------------"

0 commit comments

Comments
 (0)