Skip to content

Commit 5dab162

Browse files
committed
fix: do not rely on google nor github APIs anymore
to bypass rate limiting of non authenticated calls. https://www.zetta.rocks/golang/go.json is updated twice per hour from gihub API.. Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
1 parent f55dfcf commit 5dab162

2 files changed

Lines changed: 20 additions & 29 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ jobs:
5252
test:
5353
strategy:
5454
matrix:
55-
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, tip]
55+
go-version: [1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, 1.25.x, 1.26.x, tip]
5656
os: [ubuntu-latest, windows-latest, macos-latest]
5757

5858
runs-on: ${{ matrix.os }}
5959

6060
steps:
6161
- name: Setup go
6262
run: |
63-
curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.7/install-go.pl |
63+
curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.8/install-go.pl |
6464
perl - ${{ matrix.go-version }} $HOME/go
6565
6666
- name: Checkout code

install-go.pl

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use File::Spec;
1111
use Getopt::Long;
1212

13+
# Cache of github API tags to avoid rate limiting (updated twice per hour)
14+
my $GO_TAGS_URL = 'https://www.zetta.rocks/golang/go.json';
15+
1316
my($NO_GITHUB_PATH, $NO_GITHUB_ENV);
1417
GetOptions('p|dont-alter-github-path' => \$NO_GITHUB_PATH,
1518
'e|dont-alter-github-env' => \$NO_GITHUB_ENV)
@@ -88,30 +91,18 @@
8891
}
8992

9093
say "Need to build tip, get required golang version...";
91-
my $dist_url = 'https://api.github.com/repos/golang/go/contents/src/cmd/dist';
92-
my $r = http_get($dist_url);
93-
$r->{success} or die "Cannot retrieve $dist_url: $r->{status} $r->{reason}\n";
94-
9594
my $required_version;
96-
foreach my $file (@{decode_json($r->{content})})
95+
my $r = http_get($GO_TAGS_URL);
96+
if ($r->{success})
9797
{
98-
if ($file->{download_url} =~ m,/notgo.*\.go\z,)
99-
{
100-
$r = http_get($file->{download_url});
101-
unless ($r->{success})
102-
{
103-
say "Cannot retrieve $file->{download_url}: $r->{status} $r->{reason}\n";
104-
last
105-
}
106-
unless ($r->{content} =~ /^package building_Go_requires_Go_(\d+(?:_\d+)+)_or_later/m)
107-
{
108-
say "package line not found in $file->{download_url}\n";
109-
last
110-
}
111-
$required_version = eval { version->parse('v' . ($1 =~ tr/_/./r)) };
112-
last
113-
}
98+
$required_version = decode_json($r->{content})->{tip_require_version};
99+
}
100+
else
101+
{
102+
warn "Cannot retrieve $GO_TAGS_URL: $r->{status} $r->{reason}\n";
103+
$required_version = '1.26.4'; # should be safe for several years
114104
}
105+
$required_version = eval { version->parse("v$required_version") };
115106

116107
$required_version
117108
or die "Cannot determine which golang version is required to build tip";
@@ -176,7 +167,7 @@ sub resolve_target
176167
$target = $1;
177168

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

181172
$last_minor = -1;
182173
}
@@ -185,27 +176,27 @@ sub resolve_target
185176
die "Bad target $target, should be 1.12 or 1.12.1 or 1.12.x or tip\n"
186177
}
187178

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

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

193184
my $found;
194185
if (defined $vreg)
195186
{
196-
foreach (keys %$versions)
187+
foreach (keys %$tags)
197188
{
198189
if (/$vreg/ and $last_minor < ($1 // 0))
199190
{
200-
$last_minor = $1;
191+
$last_minor = $1 // 0;
201192
$found = 1;
202193
}
203194
}
204195
}
205196
else
206197
{
207198
# exact match expected
208-
$found = exists $versions->{"go$target"};
199+
$found = exists $tags->{"go$target"};
209200
}
210201

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

0 commit comments

Comments
 (0)