Skip to content

Commit

Permalink
Merge pull request #7 from maxatome/test
Browse files Browse the repository at this point in the history
Fix specific version
  • Loading branch information
maxatome authored Mar 9, 2022
2 parents 1e131c3 + 336e34c commit d87ba91
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions install-go.pl
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,45 @@ sub resolve_target
my($vreg, $last_minor);
if ($target =~ /^\d+\.\d+(?:\.\d+)?\z/a)
{
$vreg = quotemeta $target;
# exact match expected
}
elsif ($target =~ /^(\d+\.\d+)\.x\z/a)
{
$target = $1;

$vreg = quotemeta($target) . '(?:\.([0-9]+))?';
$vreg = qr/^go$vreg\z/;

$last_minor = -1;
}
else
{
die "Bad target $target, should be 1.12 or 1.12.1 or 1.12.x\n"
}
$vreg = qr/^go$vreg\z/;

my $r = http_get('https://go.googlesource.com/go/+refs/tags?format=JSON');
$r->{success} or die "Cannot retrieve tags: $r->{status} $r->{reason}\n$r->{content}\n";

my $versions = decode_json($r->{content} =~ s/^[^{]+//r);

my $found;
foreach (keys %{decode_json($r->{content} =~ s/^[^{]+//r)})
if (defined $vreg)
{
if (/$vreg/)
foreach (keys %$versions)
{
$last_minor // return ($target, undef); # OK found

if ($last_minor < ($1 // 0))
if (/$vreg/ and $last_minor < ($1 // 0))
{
$last_minor = $1;
$found = 1;
}
}
}
else
{
# exact match expected
$found = exists $versions->{"go$target"};
}

$found or die "Version $target not found\n";

return ($target, $last_minor);
Expand Down

0 comments on commit d87ba91

Please sign in to comment.