summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-07-27 03:29:20 +0700
committerShulhan <ms@kilabit.info>2022-07-27 03:29:20 +0700
commitb1e829a026bd7809cebe689f1178570074b3312c (patch)
tree9b73d20828ca5c2b053a9996286b43870f95e601
parentedf46a7816b689288fbe1b57265cf3980517dbdd (diff)
downloadpakakeh.go-b1e829a026bd7809cebe689f1178570074b3312c.tar.xz
_bin: add script go-mod-tip.sh
The go-mod-tip shell script get and print the latest Go module version based on the last tag and the latest commit hash from the current working directory. This command usually used to fix go.mod due to force commit.
-rwxr-xr-x_bin/go-mod-tip.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/_bin/go-mod-tip.sh b/_bin/go-mod-tip.sh
new file mode 100755
index 00000000..b581a6c2
--- /dev/null
+++ b/_bin/go-mod-tip.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+## Script to get and print the latest Go module version based on the last tag
+## and the latest commit hash from current working git directory.
+##
+## For example, if the last tag is v0.39.1 and the latest commit hash is
+## 38f9f1fb1ebc,
+##
+## $ gomod-latest.sh
+## commit timestamp: 1658864676
+## github.com/shuLhan/share v0.39.1-0.20220726194436-38f9f1fb1ebc
+##
+## This command usually used to fix go.mod due to force commit.
+
+MODNAME=$(go list -m)
+COMMIT_TS=$(git log -n 1 --pretty=format:'%at')
+DATE=$(date -u --date="@${COMMIT_TS}" +%Y%m%d%H%M%S)
+HASH=$(git log -n 1 --pretty=format:'%h' --abbrev=12)
+TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
+PREFIX=
+
+echo "commit timestamp: ${COMMIT_TS}"
+
+if [[ "${TAG}" == "" ]]; then
+ TAG="v0.0.0"
+else
+ IFS=. read MAJOR MINOR PATCH <<<"${TAG}"
+ PATCH=$((PATCH+1))
+ TAG=${MAJOR}.${MINOR}.${PATCH}
+ PREFIX=0.
+fi
+
+echo ${MODNAME} ${TAG}-${PREFIX}${DATE}-${HASH}