diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3cbef41..8c71280 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,6 +35,7 @@ jobs: TARGET: ${{ matrix.env.target }} GOOS: ${{ matrix.env.goos }} GOARCH: ${{ matrix.env.goarch }} + GIMME_MODULE_PREFIX: .testdata/ steps: - uses: actions/checkout@v3 - uses: actions/cache@v3 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/README.md b/README.md index 1bcdc2b..a994f8e 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 the release specified in the `go.mod` file: + +``` bash +gimme module +``` + Or to install and use the development version (master branch) of Go: ``` bash diff --git a/gimme b/gimme index bbe196b..5064913 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 "$@"