From c6e40ce27e2f5c59edf2b988b715207cf98b0b07 Mon Sep 17 00:00:00 2001 From: Bracken Dawson Date: Mon, 13 Sep 2021 21:22:36 +0100 Subject: [PATCH 1/3] Optionally choose the go version from go.mod --- .testdata/go.mod | 3 +++ .testdata/source-darwin | 1 + .testdata/source-linux | 1 + .travis.yml | 1 + README.md | 6 ++++++ gimme | 16 ++++++++++++++++ 6 files changed, 28 insertions(+) create mode 100644 .testdata/go.mod 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..515991d 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,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" +} + _file_older_than_secs() { local file="${1}" local age_secs="${2}" @@ -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 "$@" From f46d7570210122ce1e3351ec7e476acd5172cb51 Mon Sep 17 00:00:00 2001 From: Bracken Date: Mon, 13 Sep 2021 21:56:19 +0100 Subject: [PATCH 2/3] Read go.mod once and avoid pipe Co-authored-by: Tianon Gravi --- gimme | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gimme b/gimme index 515991d..62ab0c0 100755 --- a/gimme +++ b/gimme @@ -700,10 +700,12 @@ _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 + 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 "$(grep '^go' "${GIMME_MODULE_PREFIX}go.mod" | awk '{ print $2 }').x" + _resolve_version "$version" } _file_older_than_secs() { From 570bb51e5cf5ca807c7636695d2f0ac3ad740d36 Mon Sep 17 00:00:00 2001 From: Bracken Date: Tue, 18 Oct 2022 13:50:45 +0100 Subject: [PATCH 3/3] Update README.md Co-authored-by: Tianon Gravi --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad2cb61..a994f8e 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,9 @@ To install the previous minor release of Go: gimme oldstable ``` -To install the most recent patch of relase specified in the go.mod file: +To install the most recent patch of the release specified in the `go.mod` file: -``` +``` bash gimme module ```