Skip to content

Commit

Permalink
Merge pull request #23 from WillAbides/semver-select
Browse files Browse the repository at this point in the history
Semver-select v0.3.0
  • Loading branch information
WillAbides authored Aug 10, 2023
2 parents b25f96d + 84bfb85 commit a8a2fe6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
43 changes: 38 additions & 5 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ jobs:
with:
go-version: '1.21'
ignore-local: true
debug: true
- name: outputs
run: |
echo '*********** env ************'
Expand All @@ -168,7 +167,6 @@ jobs:
with:
go-version: '1.21.0'
ignore-local: true
debug: true
- name: outputs
run: |
echo '*********** env ************'
Expand All @@ -182,9 +180,10 @@ jobs:
[[ '${{steps.setup_go_1_21.outputs.GOROOT}}' == *"1.21.0"* ]]
[[ '${{steps.setup_go_1_21.outputs.GOTOOLDIR}}' == *"1.21.0"* ]]
- name: create_go_mod
- name: create_go_mod 1.15
run: |
cat >> go.mod << EOF
mkdir -p tmp/go_mod_1_15
cat >> tmp/go_mod_1_15/go.mod << EOF
module example.com/some-module
go 1.15
Expand All @@ -197,7 +196,7 @@ jobs:
name: install 1.15 from go.mod
uses: ./
with:
go-version-file: 'go.mod'
go-version-file: 'tmp/go_mod_1_15/go.mod'
ignore-local: true
- name: outputs
run: |
Expand All @@ -215,3 +214,37 @@ jobs:
[[ "$lowest_version" == "$requested_min_version" ]]
[[ '${{steps.setup_go_1_15_from_go_mod.outputs.GOROOT}}' == *"$installed_version"* ]]
[[ '${{steps.setup_go_1_15_from_go_mod.outputs.GOTOOLDIR}}' == *"$installed_version"* ]]
- name: create_go_mod 1.21rc1
run: |
mkdir -p tmp/go_mod_1_21rc1
cat >> tmp/go_mod_1_21rc1/go.mod << EOF
module example.com/some-module
go 1.21rc1
require (
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691
golang.org/x/sync v0.3.0
)
- id: setup_go_1_21rc1_from_go_mod
name: install 1.21rc1 from go.mod
uses: ./
with:
go-version-file: 'tmp/go_mod_1_21rc1/go.mod'
ignore-local: true
- name: outputs
run: |
echo '*********** env ************'
env
echo '*********** go env ***********'
go env
echo '${{ toJson( steps.setup_go_1_21rc1_from_go_mod.outputs ) }}' | jq .
go version
set -ex
requested_min_version='1.21rc1'
installed_version="$(go version | cut -d " " -f 3 | tr -d "go")"
lowest_version="$(echo -e "$requested_min_version\n$installed_version" | sort -rV | tail -1)"
[[ "$lowest_version" == "$requested_min_version" ]]
[[ '${{steps.setup_go_1_21rc1_from_go_mod.outputs.GOROOT}}' == *"$installed_version"* ]]
[[ '${{steps.setup_go_1_21rc1_from_go_mod.outputs.GOTOOLDIR}}' == *"$installed_version"* ]]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ For those who learn best from examples:

### go-version-file

Path to the go.mod or go.work file.
Path to a go.mod or go.work file. setup-go-faster will take the version from the "go" directive
in this file and convert it to a semver minimum version. For example, if the go directive is `go 1.21rc1`,
setup-go-faster will use the constraint `>= 1.21.0-rc1`.


### ignore-local

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ inputs:
go-version-file:
required: false
description: 'Path to the go.mod or go.work file.'
description: |
Path to a go.mod or go.work file. setup-go-faster will take the version from the "go" directive
in this file and convert it to a semver minimum version. For example, if the go directive is `go 1.21rc1`,
setup-go-faster will use the constraint `>= 1.21.0-rc1`.
ignore-local:
required: false
description: |
Expand Down
13 changes: 10 additions & 3 deletions src/lib
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ select_local_version() {
fi

# handle other constraints
local_matches="$(echo "$local_versions" | ./src/semver-select -c "$constraint" -n 1 -i -)"
local_matches="$(echo "$local_versions" | ./src/"semver-select" --go -c "$constraint" -n 1 -i -)"
if [ -n "$local_matches" ]; then
echo "$local_matches" | tail -1
fi
Expand All @@ -172,7 +172,14 @@ select_remote_version() {
return
fi

echo "$versions" | ./src/semver-select -c "$constraint" -n 1 -i -
echo "$versions" | ./src/"semver-select" --go -c "$constraint" -n 1 -i -
}

# uses semver-select to convert a go version to semver
# go1.2rc3 -> 1.2.0-rc3
# 1.2.3rc3 -> 1.2.3-rc3
normalize_go_version() {
./src/"semver-select" --go -c '*-0' "$1"
}

select_go_version_from_file() {
Expand All @@ -189,5 +196,5 @@ select_go_version_from_file() {
found_version="1.16"
fi

echo "$found_version"
normalize_go_version "$found_version"
}
2 changes: 1 addition & 1 deletion src/semver-select
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ goos() {
esac
}

target_version="0.1.0"
target_version="0.3.0"
bin_path="./bin/semver-select"
[ "$(goos)" = "windows" ] && bin_path+=".exe"

Expand Down

0 comments on commit a8a2fe6

Please sign in to comment.