Skip to content

Commit 987b181

Browse files
authored
fix: misc (#96)
2 parents 3e2b0f9 + c792609 commit 987b181

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

.bin/git-tag-mod.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,33 @@ LogshRun() { _dlm="####R#E#C#D#E#L#I#M#I#T#E#R####" && _all=$({ _out=$("$@") &&
2626
__main__() {
2727
cd "${REPO_ROOT:?}" || return $? # cd repo root
2828

29+
git fetch --tags
30+
2931
trap "git switch -" EXIT
3032

31-
latest_git_tag=$(git tag --sort v:refname | tail -n 1)
33+
latest_git_tag=$(git tag --sort=v:refname | grep -E "^v[0-9]+" | tail -n 1)
3234
latest_git_tag_commit=$(git rev-list -n 1 "${latest_git_tag:?}")
3335

3436
git switch --detach "${latest_git_tag:?}"
3537
targets=$(
36-
find "${REPO_ROOT:?}" -name go.mod -print | # find go.mod
37-
sed "s@${REPO_ROOT:?}/@@g" | # trim repo root path
38-
grep -v "^go\.mod$" | # ignore root go.mod
39-
grep -v "^tests/go\.mod$" | # ignore tests/go.mod
40-
sed "s@/go\.mod@@g" | # trim go.mod for extract module dir
41-
: || true
38+
find "${REPO_ROOT:?}" -name go.mod -print | # find go.mod
39+
sed "s@${REPO_ROOT:?}/@@g; s@/*go\.mod@@g" | # trim repo root path
40+
grep -v "^$" | # ignore root go.mod
41+
grep -v "^tests$" | # ignore tests/go.mod
42+
cat || true
4243
)
4344
LogshInfo "$(printf "targets: %s" "${targets:-none}")"
44-
while read -r mod; do
45-
git tag -a "${mod:?}/${latest_git_tag:?}" -m "${mod:?}/${latest_git_tag:?}" "${latest_git_tag_commit:?}"
46-
done <<<"${targets:-}"
45+
if [ -n "${targets:-}" ]; then
46+
while read -r mod; do
47+
mod_tag="${mod:?}/${latest_git_tag:?}"
48+
if git tag --sort=v:refname | grep -qE "^${mod_tag:?}$"; then
49+
LogshInfo "$(printf "tag already exists: %s" "${mod_tag:?}")"
50+
continue
51+
fi
52+
git tag -a "${mod_tag:?}" -m "${mod_tag:?}" "${latest_git_tag_commit:?}"
53+
done <<<"${targets:?}"
54+
git push --tags
55+
fi
4756
}
4857

4958
__main__ "$@"

0 commit comments

Comments
 (0)