Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
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:

```
Comment thread
brackendawson marked this conversation as resolved.
Outdated
gimme module
```

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

``` bash
Expand Down
18 changes: 18 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,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}"
Expand Down Expand Up @@ -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 "$@"
Expand Down