File tree Expand file tree Collapse file tree 1 file changed +43
-11
lines changed Expand file tree Collapse file tree 1 file changed +43
-11
lines changed Original file line number Diff line number Diff line change 22
33set -e
44
5+ DRY_RUN=1
6+
7+ if [ $# -eq 0 ]; then
8+ echo " Error: Tag version is required"
9+ help
10+ fi
11+
12+ TAG=$1
13+ shift
14+
15+ while getopts " t" opt; do
16+ case $opt in
17+ t)
18+ DRY_RUN=0
19+ ;;
20+ \? )
21+ echo " Invalid option: -$OPTARG " >&2
22+ exit 1
23+ ;;
24+ esac
25+ done
26+
527help () {
628 cat << - EOF
7- Usage: TAG=tag $0
29+ Usage: $0 TAGVERSION [-t]
830
931Creates git tags for public Go packages.
1032
11- VARIABLES:
12- TAG git tag, for example, v1.0.0
33+ ARGUMENTS:
34+ TAGVERSION Tag version to create, for example v1.0.0
35+
36+ OPTIONS:
37+ -t Execute git commands (default: dry run)
1338EOF
1439 exit 0
1540}
1641
17- if [ -z " $TAG " ]
18- then
19- printf " TAG env var is required\n\n" ;
20- help
42+ if [ " $DRY_RUN " -eq 1 ]; then
43+ echo " Running in dry-run mode"
2144fi
2245
2346if ! grep -Fq " \" ${TAG# v} \" " version.go
@@ -31,12 +54,21 @@ PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
3154 | sed ' s/^\.\///' \
3255 | sort)
3356
34- git tag ${TAG}
35- git push origin ${TAG}
57+
58+ execute_git_command () {
59+ if [ " $DRY_RUN " -eq 0 ]; then
60+ " $@ "
61+ else
62+ echo " DRY-RUN: Would execute: $@ "
63+ fi
64+ }
65+
66+ execute_git_command git tag ${TAG}
67+ execute_git_command git push origin ${TAG}
3668
3769for dir in $PACKAGE_DIRS
3870do
3971 printf " tagging ${dir} /${TAG} \n"
40- git tag ${dir} /${TAG}
41- git push origin ${dir} /${TAG}
72+ execute_git_command git tag ${dir} /${TAG}
73+ execute_git_command git push origin ${dir} /${TAG}
4274done
You can’t perform that action at this time.
0 commit comments