diff --git a/.testdata/go.mod b/.testdata/go.mod new file mode 100644 index 0000000..98b3887 --- /dev/null +++ b/.testdata/go.mod @@ -0,0 +1,3 @@ +module githib.com/travis-ci/gimme/testdata + +go 1.17 diff --git a/.testdata/source-darwin b/.testdata/source-darwin index f9d1184..995b905 100644 --- a/.testdata/source-darwin +++ b/.testdata/source-darwin @@ -1,5 +1,6 @@ tip stable +module master go1.4rc1 1.5rc1 diff --git a/.testdata/source-linux b/.testdata/source-linux index f9d1184..995b905 100644 --- a/.testdata/source-linux +++ b/.testdata/source-linux @@ -1,5 +1,6 @@ tip stable +module master go1.4rc1 1.5rc1 diff --git a/.travis.yml b/.travis.yml index 79593c7..4d776f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/README.md b/README.md index ddfaad9..ba377ce 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/gimme b/gimme index 16f4d1e..62ab0c0 100755 --- a/gimme +++ b/gimme @@ -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 @@ -597,6 +598,10 @@ _resolve_version() { echo "tip" return 0 ;; + module) + _get_module + return 0 + ;; *.x) true ;; @@ -691,6 +696,18 @@ _last_mod_timestamp() { esac } +_get_module() { + if [[ ! -f "${GIMME_MODULE_PREFIX}go.mod" ]]; then + die 'not a module' + fi + local version + version="$(awk '$1 == "go" { print $2 ".x"; exit }' "${GIMME_MODULE_PREFIX}go.mod")" + if [ -z "$version" ]; then + die 'module has no go directive' + fi + _resolve_version "$version" +} + _file_older_than_secs() { local file="${1}" local age_secs="${2}" @@ -903,6 +920,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 "$@"