Skip to content

Commit

Permalink
fix: 1.21 provides a new go.env file
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <[email protected]>
  • Loading branch information
maxatome committed Aug 16, 2023
1 parent 6d63a7d commit 07386de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 23 additions & 7 deletions install-go.pl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
exit 0;
}

$TARGET = '1.18.x';
$TARGET = '1.20.x';
$TIP = 1;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}

0 comments on commit 07386de

Please sign in to comment.