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

Optionally choose the go version from go.mod #200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .testdata/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module githib.com/travis-ci/gimme/testdata

go 1.17
1 change: 1 addition & 0 deletions .testdata/source-darwin
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tip
stable
module
master
go1.4rc1
1.5rc1
1 change: 1 addition & 0 deletions .testdata/source-linux
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tip
stable
module
master
go1.4rc1
1.5rc1
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
- PATH="${HOME}/bin:${PATH}"
- SHELLCHECK_URL="https://www.googleapis.com/download/storage/v1/b/shellcheck/o/shellcheck-v0.4.7.linux.x86_64.tar.xz?alt=media"
- SHFMT_URL="https://github.com/mvdan/sh/releases/download/v2.2.0/shfmt_v2.2.0_linux_amd64"
- GIMME_MODULE_PREFIX='.testdata/'
matrix:
- TARGET=native GO_VERSIONS="$(sed -n -e '/^[^#]/p' < .testdata/sample-binary-$UNAME) $(sed -n -e '/^[^#]/p' < .testdata/source-$UNAME)"
- TARGET=arm GO_VERSIONS="master"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ To install the previous minor release of Go:
gimme oldstable
```

To install the most recent patch of relase specified in the go.mod file:

```
gimme module
```

Or to install and use the development version (master branch) of Go:

``` bash
Expand Down
16 changes: 16 additions & 0 deletions gimme
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#+ GIMME_DOWNLOAD_BASE - override base URL dir for download (default '${GIMME_DOWNLOAD_BASE}')
#+ GIMME_LIST_KNOWN - override base URL for known go versions (default '${GIMME_LIST_KNOWN}')
#+ GIMME_KNOWN_CACHE_MAX - seconds the cache for --known is valid for (default '${GIMME_KNOWN_CACHE_MAX}')
#+ GIMME_MODULE_PREFIX - directory prefix for go.mod file in 'module' mode (default './')
#+ -
#
set -e
Expand Down Expand Up @@ -597,6 +598,10 @@ _resolve_version() {
echo "tip"
return 0
;;
module)
_get_module
return 0
;;
*.x)
true
;;
Expand Down Expand Up @@ -691,6 +696,16 @@ _last_mod_timestamp() {
esac
}

_get_module() {
if [[ ! -f "${GIMME_MODULE_PREFIX}go.mod" ]]; then
die 'not a module'
fi
if ! grep '^go' "${GIMME_MODULE_PREFIX}go.mod" >/dev/null; then
die 'module has no go directive'
fi
_resolve_version "$(grep '^go' "${GIMME_MODULE_PREFIX}go.mod" | awk '{ print $2 }').x"
brackendawson marked this conversation as resolved.
Show resolved Hide resolved
}

_file_older_than_secs() {
local file="${1}"
local age_secs="${2}"
Expand Down Expand Up @@ -903,6 +918,7 @@ esac
case "${GIMME_GO_VERSION}" in
stable) GIMME_GO_VERSION=$(_get_curr_stable) ;;
oldstable) GIMME_GO_VERSION=$(_get_old_stable) ;;
module) GIMME_GO_VERSION=$(_resolve_version module) ;;
esac

_assert_version_given "$@"
Expand Down