Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-detect the minimum required go version to build tip #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6/install-go.pl |
curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.7/install-go.pl |
perl - ${{ matrix.go-version }} $HOME/go

- name: Checkout code
Expand Down
38 changes: 35 additions & 3 deletions install-go.pl
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,47 @@
$goroot = go_env('go', 'GOROOT');
}

# If go is already installed somewhere *and* ≥ 1.22.6, no need to install it
if ($goroot and go_version("$goroot/bin/go") ge v1.22.6)
say "Need to build tip, get required golang version...";
my $dist_url = 'https://api.github.com/repos/golang/go/contents/src/cmd/dist';
my $r = http_get($dist_url);
$r->{success} or die "Cannot retrieve $dist_url: $r->{status} $r->{reason}\n";

my $required_version;
foreach my $file (@{decode_json($r->{content})})
{
if ($file->{download_url} =~ m,/notgo.*\.go\z,)
{
$r = http_get($file->{download_url});
unless ($r->{success})
{
say "Cannot retrieve $file->{download_url}: $r->{status} $r->{reason}\n";
last
}
unless ($r->{content} =~ /^package building_Go_requires_Go_(\d+(?:_\d+)+)_or_later/m)
{
say "package line not found in $file->{download_url}\n";
last
}
$required_version = eval { version->parse('v' . ($1 =~ tr/_/./r)) };
last
}
}

$required_version
or die "Cannot determine which golang version is required to build tip";

# If go is already installed somewhere *and* ≥ $required_version,
# no need to install it
if ($goroot and go_version("$goroot/bin/go") ge $required_version)
{
say "At least go $required_version is required: OK";
my $goroot_tip = install_tip($goroot, $DESTDIR);
export_env("$DESTDIR/go", $goroot_tip);
exit 0;
}

$TARGET = '1.22.x';
say "Go $required_version is required...";
$TARGET = "$required_version" =~ s/^v//r;
$TIP = 1;
}

Expand Down
Loading