Skip to content

Commit

Permalink
Merge branch 'main' into imp
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Aug 10, 2023
2 parents 8ab4fb7 + a8a2fe6 commit eb5514c
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: ci
on: [ push, workflow_dispatch ]
on:
push:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
jobs:
cibuild:
name: cibuild
Expand Down
113 changes: 112 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: integration
on: [ push, workflow_dispatch ]
on:
push:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
jobs:
install_go_tip:
name: install tip
Expand Down Expand Up @@ -137,3 +141,110 @@ jobs:
[[ "$(go version)" == *"1.13"* ]]
[[ '${{steps.setup_go_1_13_x.outputs.GOROOT}}' == *"1.13"* ]]
[[ '${{steps.setup_go_1_13_x.outputs.GOTOOLDIR}}' == *"1.13"* ]]
- id: setup_go_1_21
name: install 1.21
uses: ./
with:
go-version: '1.21'
ignore-local: true
- name: outputs
run: |
echo '*********** env ************'
env
echo '*********** go env ***********'
go env
echo '${{ toJson( steps.setup_go_1_21.outputs ) }}' | jq .
go version
set -ex
[[ "$(go version)" == *"1.21.0"* ]]
[[ '${{steps.setup_go_1_21.outputs.GOROOT}}' == *"1.21.0"* ]]
[[ '${{steps.setup_go_1_21.outputs.GOTOOLDIR}}' == *"1.21.0"* ]]
- id: setup_go_1_21_0
name: install 1.21.0
uses: ./
with:
go-version: '1.21.0'
ignore-local: true
- name: outputs
run: |
echo '*********** env ************'
env
echo '*********** go env ***********'
go env
echo '${{ toJson( steps.setup_go_1_21.outputs ) }}' | jq .
go version
set -ex
[[ "$(go version)" == *"1.21.0"* ]]
[[ '${{steps.setup_go_1_21.outputs.GOROOT}}' == *"1.21.0"* ]]
[[ '${{steps.setup_go_1_21.outputs.GOTOOLDIR}}' == *"1.21.0"* ]]
- name: create_go_mod 1.15
run: |
mkdir -p tmp/go_mod_1_15
cat >> tmp/go_mod_1_15/go.mod << EOF
module example.com/some-module
go 1.15

require (
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691
golang.org/x/sync v0.3.0
)
- id: setup_go_1_15_from_go_mod
name: install 1.15 from go.mod
uses: ./
with:
go-version-file: 'tmp/go_mod_1_15/go.mod'
ignore-local: true
- name: outputs
run: |
echo '*********** env ************'
env
echo '*********** go env ***********'
go env
echo '${{ toJson( steps.setup_go_1_15_from_go_mod.outputs ) }}' | jq .
go version
set -ex
requested_min_version='1.15'
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_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"* ]]
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

It's like actions/setup-go but faster.

### A Note About Go 1.21.0

**Use [email protected] or later** if you want to install Go 1.21.0.

With the release of go1.21.0, the Go team has changed the way they style
dot-zero releases. They used to be styled like `go1.N`, but now they are
`go1.N.0`. This caused issues with earlier versions of setup-go-faster.

### Faster

Setup-go-faster takes about a third as long as setup-go to install go on a
Expand Down Expand Up @@ -57,8 +65,6 @@ accordingly. If there is good use case for `stable`, it can be added.

### go-version

__Required__

The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'.
Do not add "go" or "v" to the beginning of the version.

Expand Down Expand Up @@ -96,6 +102,13 @@ For those who learn best from examples:
| tip | installs gotip from source |


### go-version-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

Normally a pre-installed version of go that meets the go-version constraints will be used instead
Expand Down
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Setup Go Faster'
description: It's like actions/setup-go but faster.
inputs:
go-version:
required: true
required: false
description: |
The version of go to install. It can be an exact version or a semver constraint like '1.14.x' or '^1.14.4'.
Do not add "go" or "v" to the beginning of the version.
Expand Down Expand Up @@ -40,6 +40,12 @@ inputs:
| < 1.15.6 >= 1.15.4 | installs a go that is >= 1.15.4 and < 1.15.6 |
| tip | installs gotip from source |
go-version-file:
required: false
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 Expand Up @@ -72,6 +78,7 @@ runs:
DEBUG: ""
IGNORE_LOCAL_GO: ${{ inputs.ignore-local }}
GO_VERSION: ${{ inputs.go-version }}
GO_VERSION_FILE: ${{ inputs.go-version-file }}
shell: bash
run: src/run
branding:
Expand Down
Empty file added bindown.yml
Empty file.
34 changes: 30 additions & 4 deletions src/lib
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ download_go_url() {
install_go() {
local go_version="$1"
local target_dir="$2"
debug_out "installing go $go_version to $target_dir"
rm -rf "$target_dir"
mkdir -p "$(dirname "$target_dir")"
tmpdir="$(init_tmpdir)"
Expand Down Expand Up @@ -113,8 +114,9 @@ exe_name() {
}

is_precise_version() {
[[ $1 =~ ^[0-9]+(.[0-9]+(.[0-9]+)?)?([A-Za-z0-9]+)?$ ]] && return
return 1
[[ $1 =~ ^[0-9]+(.([0-9]+)(.[0-9]+)?)?([A-Za-z0-9]+)?$ ]] || return 1
# false when minor is >= 21 and patch is empty
[ -z "${BASH_REMATCH[2]}" ] || [ "${BASH_REMATCH[2]}" -lt 21 ] || [ -n "${BASH_REMATCH[3]}" ]
}

select_go_version() {
Expand Down Expand Up @@ -149,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 @@ -170,5 +172,29 @@ 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() {
local go_file_path="$1"

file_name="$(basename "$go_file_path")"
if [ "$file_name" != "go.mod" ] && [ "$file_name" != "go.work" ]; then
echo "::error ::File is not go.mod nor go.work"
return 1
fi

found_version="$(perl -nle 'print $1 if /^\s*go\s+(\S+)\s*(?:$|(?:\/\/))/' < "$go_file_path")"
if [ -z "$found_version" ]; then
found_version="1.16"
fi

normalize_go_version "$found_version"
}
3 changes: 3 additions & 0 deletions src/lib_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ test_is_precise_version() {
9999.9999.9999
1.15beta1
1.16rc1
1.21.0
1.21.1
'

for v in $versions; do
Expand All @@ -48,6 +50,7 @@ test_is_precise_version() {
done

not_versions='
1.21
*
1.x
1.15.x
Expand Down
18 changes: 17 additions & 1 deletion src/run
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash

# required global vars:
# GO_VERSION= version constraint
# RUNNER_TOOL_CACHE # provided by action
# RUNNER_WORKSPACE # provided by action
# GITHUB_ACTION_PATH # provided by action
# GITHUB_OUTPUT # provided by action
#
# optional vars:
# GO_VERSION= version constraint
# GO_VERSION_FILE= path to go.mod or go.work
# INSTALL_GO_FORCE # set to non-empty to force the install
# IGNORE_LOCAL_GO # set to non-empty to ignore local go installations
#
Expand All @@ -28,13 +29,28 @@ debug_out starting run

export INSTALL_GO_TIP

# shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version
if [ -z "$GO_VERSION" ] && [ -z "$GO_VERSION_FILE" ]; then
echo "::error ::Either go-version or go-version-file must be specified"
exit 1
fi

# shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version
if [ -n "$GO_VERSION" ] && [ -n "$GO_VERSION_FILE" ]; then
echo "::warning ::Both go-version or go-version-file are set, but only go-version will be used"
fi

# shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version
constraint="$GO_VERSION"
if [ "$constraint" = "tip" ] || [ "$constraint" = "gotip" ]; then
constraint='*'
INSTALL_GO_TIP=1
fi

if [ -z "$constraint" ]; then
constraint=">=$(select_go_version_from_file "$GITHUB_WORKSPACE/$GO_VERSION_FILE")"
fi

install_parent="$RUNNER_WORKSPACE/setup-go-faster/go"
mkdir -p "$install_parent"

Expand Down
2 changes: 1 addition & 1 deletion src/semver-select
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CDPATH="" cd -- "$(dirname -- "$0")/.."

. src/lib

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 eb5514c

Please sign in to comment.