Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go mod: script to get a usable mod version from a tag to use in a go.mod #11477

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions hack/get-usable-mod-version-from-tag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# get-usable-mod-version-from-tag.sh

Tags like `v3.X.Y` do not work with `go.mod` files.
This tiny script will compute a usable go module version to import from a tag (until the situation gets fixed).

## Usage
Get the usable version from a tag:
```
get-usable-mod-version-from-tag.sh -t tag_name
```
You can now use it in `go.mod` (the version here is for tag `v3.4.3`).
```
require go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
```
## go get

If you're using go get, fetch the package with:
```
go get v0.0.0-20191023171146-3cf2f69b5738
obsider marked this conversation as resolved.
Show resolved Hide resolved
```
And when it's done, add this line at the end of go.mod:
```
replace go.etcd.io/etcd => go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /bin/bash

function usage {
echo "${0} -t tag_name"
}

function tag_exists {
local tag="${1}"
git --no-pager tag | grep -q "${tag}"'$'
return $?
}

while getopts "t:h" option; do
case "${option}" in
t)
tag=${OPTARG}
;;
h)
usage
exit 0
;;
\?)
usage
exit 1
;;
esac
done


if [ -z "${tag}" ]; then
usage
exit 1
fi


REPO_ROOT=$(git -C "$(dirname $( readlink -f ${BASH_SOURCE[0]}))" rev-parse --show-toplevel)
pushd ${REPO_ROOT} > /dev/null 2>&1
if ! tag_exists "${tag}"; then
echo "tag ${tag} does not exist"
echo "use 'git tag' to list available ones"
exit 1
else
git checkout tags/$tag > /dev/null 2>&1
echo -n v0.0.0-
TZ=UTC git --no-pager show \
--quiet \
--abbrev=12 \
--date='format-local:%Y%m%d%H%M%S' \
--format="%cd-%h"
git checkout - > /dev/null 2>&1
fi
popd > /dev/null 2>&1