From 90eacc6b6c843a79fd570ccea8ef8fbc4db7845d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Soul=C3=A9?= Date: Wed, 1 Jul 2026 22:17:47 +0200 Subject: [PATCH] fix: do not rely on google nor github APIs anymore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- .github/workflows/test.yml | 4 ++-- README.md | 4 ++-- install-go.pl | 45 +++++++++++++++----------------------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f76474..023cec0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -140,7 +140,7 @@ jobs: mkdir zzz ./install-go.pl tip zzz ./zzz/go/bin/go version | tee zzz/go-version - fgrep -q 'go version devel' zzz/go-version + grep -q 'go version .*devel' zzz/go-version if [ ! -s "$GITHUB_PATH" ]; then echo "*** GITHUB_PATH file is empty" false @@ -158,7 +158,7 @@ jobs: mkdir zzz ALWAYS_BUILD_TIP=1 ./install-go.pl tip zzz ./zzz/go/bin/go version | tee zzz/go-version - fgrep -q 'go version devel' zzz/go-version + grep -q 'go version .*devel' zzz/go-version if [ ! -s "$GITHUB_PATH" ]; then echo "*** GITHUB_PATH file is empty" false diff --git a/README.md b/README.md index 32c912a..416d6dd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, tip] + go-version: [1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, 1.25.x, 1.26.x, tip] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} @@ -60,7 +60,7 @@ jobs: steps: - name: Setup go run: | - curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.7/install-go.pl | + curl -sL https://raw.githubusercontent.com/maxatome/install-go/v3.8/install-go.pl | perl - ${{ matrix.go-version }} $HOME/go - name: Checkout code diff --git a/install-go.pl b/install-go.pl index 6409f3c..bba5a14 100755 --- a/install-go.pl +++ b/install-go.pl @@ -10,6 +10,9 @@ use File::Spec; use Getopt::Long; +# Cache of github API tags to avoid rate limiting (updated twice per hour) +my $GO_TAGS_URL = 'https://www.zetta.rocks/golang/go.json'; + my($NO_GITHUB_PATH, $NO_GITHUB_ENV); GetOptions('p|dont-alter-github-path' => \$NO_GITHUB_PATH, 'e|dont-alter-github-env' => \$NO_GITHUB_ENV) @@ -88,30 +91,18 @@ } 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})}) + my $r = http_get($GO_TAGS_URL); + if ($r->{success}) { - 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 = decode_json($r->{content})->{tip_require_version}; + } + else + { + warn "Cannot retrieve $GO_TAGS_URL: $r->{status} $r->{reason}\n"; + $required_version = '1.26.4'; # should be safe for several years } + $required_version = eval { version->parse("v$required_version") }; $required_version or die "Cannot determine which golang version is required to build tip"; @@ -176,7 +167,7 @@ sub resolve_target $target = $1; $vreg = quotemeta($target) . '(?:\.([0-9]+))?'; - $vreg = qr/^go$vreg\z/; + $vreg = qr,^go$vreg\z,; $last_minor = -1; } @@ -185,19 +176,19 @@ sub resolve_target die "Bad target $target, should be 1.12 or 1.12.1 or 1.12.x or tip\n" } - my $r = http_get('https://go.googlesource.com/go/+refs/tags?format=JSON'); + my $r = http_get($GO_TAGS_URL); $r->{success} or die "Cannot retrieve tags: $r->{status} $r->{reason}\n$r->{content}\n"; - my $versions = decode_json($r->{content} =~ s/^[^{]+//r); + my $tags = decode_json($r->{content})->{tags}; my $found; if (defined $vreg) { - foreach (keys %$versions) + foreach (keys %$tags) { if (/$vreg/ and $last_minor < ($1 // 0)) { - $last_minor = $1; + $last_minor = $1 // 0; $found = 1; } } @@ -205,7 +196,7 @@ sub resolve_target else { # exact match expected - $found = exists $versions->{"go$target"}; + $found = exists $tags->{"go$target"}; } $found or die "Version $target not found\n";