Skip to content

Commit 0502f99

Browse files
committed
improved tag script
1 parent 5f9e3b1 commit 0502f99

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

scripts/tag.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22

33
set -e
44

5+
DRY_RUN=1
6+
7+
while getopts "t" opt; do
8+
case $opt in
9+
t)
10+
DRY_RUN=0
11+
;;
12+
\?)
13+
echo "Invalid option: -$OPTARG" >&2
14+
exit 1
15+
;;
16+
esac
17+
done
18+
519
help() {
620
cat <<- EOF
7-
Usage: TAG=tag $0
21+
Usage: TAG=tag $0 [-t]
822
923
Creates git tags for public Go packages.
24+
The default behaviour is a dry-run.
1025
1126
VARIABLES:
1227
TAG git tag, for example, v1.0.0
28+
29+
OPTIONS:
30+
-t Tag mode - executes git commands
1331
EOF
1432
exit 0
1533
}
@@ -31,12 +49,21 @@ PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
3149
| sed 's/^\.\///' \
3250
| sort)
3351

34-
git tag ${TAG}
35-
git push origin ${TAG}
52+
53+
execute_git_command() {
54+
if [ "$DRY_RUN" -eq 0 ]; then
55+
"$@"
56+
else
57+
echo "DRY-RUN: Would execute: $@"
58+
fi
59+
}
60+
61+
execute_git_command git tag ${TAG}
62+
execute_git_command git push origin ${TAG}
3663

3764
for dir in $PACKAGE_DIRS
3865
do
3966
printf "tagging ${dir}/${TAG}\n"
40-
git tag ${dir}/${TAG}
41-
git push origin ${dir}/${TAG}
67+
execute_git_command git tag ${dir}/${TAG}
68+
execute_git_command git push origin ${dir}/${TAG}
4269
done

0 commit comments

Comments
 (0)