diff --git a/README.md b/README.md index 30e74c9..d82ac29 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ jobs: steps: - name: Setup go run: | - curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.4/install-go.pl | + curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.5/install-go.pl | perl - ${{ matrix.go-version }} $HOME/go - name: Checkout code diff --git a/install-go.pl b/install-go.pl index 360e3d8..a8c75ba 100755 --- a/install-go.pl +++ b/install-go.pl @@ -95,7 +95,7 @@ exit 0; } - $TARGET = '1.18.x'; + $TARGET = '1.20.x'; $TIP = 1; } @@ -224,10 +224,11 @@ sub link_github_go_if_available say "Find already installed go version $target"; mkdir_p("$dest_dir/go"); - foreach my $subdir (qw(bin src pkg)) + foreach my $file (qw(bin src pkg), + (at_least($target, v1.21) ? 'go.env' : ())) { - symlink("$goroot/$subdir", "$dest_dir/go/$subdir") - or die "symlink($goroot/$subdir, $dest_dir/go/$subdir): $!\n"; + symlink("$goroot/$file", "$dest_dir/go/$file") + or die "symlink($goroot/$file, $dest_dir/go/$file): $!\n"; } say "go version $target symlinked and available as $dest_dir/go/bin/go"; return 1; @@ -273,12 +274,14 @@ sub install_go if ($EXT eq 'zip') { exe(qw(curl -L -s -o x.zip), $url); - exe(qw(unzip -q x.zip go/bin/* go/pkg/**/* go/src/**/*)); + exe(qw(unzip -q x.zip go/bin/* go/pkg/**/* go/src/**/*), + (at_least($version, v1.21) ? 'go/go.env' : ())); unlink 'x.zip'; } else { - exe("curl -L -s \Q$url\E | tar zxf - go/bin go/pkg go/src"); + exe("curl -L -s \Q$url\E | tar zxf - go/bin go/pkg go/src" + . (at_least($version, v1.21) ? ' go/go.env' : '')); } my $goroot_env; @@ -373,7 +376,8 @@ sub install_prebuilt_tip mkdir_p("$dest_dir/go"); - $status = exe_status(qw(tar zxf gotip.tar.gz -C), "$dest_dir/go", qw(bin pkg src)); + $status = exe_status(qw(tar zxf gotip.tar.gz -C), "$dest_dir/go", + qw(bin pkg src go.env)); unlink 'gotip.tar.gz'; if ($status != 0) { @@ -605,3 +609,15 @@ sub go_env return $res; } + +sub at_least +{ + my($version, $cmp) = @_; + + unless (ref $version) + { + $version = eval { version->parse("v$version") } // return; + } + + return $version ge $cmp +}