Skip to content

[WIP, version with cache] experiment with manual go download #2782

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

Closed
wants to merge 13 commits into from
Closed
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
29 changes: 21 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,28 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Go
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
shell: bash
run: |
python3 tools/get_go.py
echo "GOROOT=${{ github.workspace }}/_go_binary/go" >> $GITHUB_ENV
if [ "${{ runner.os }}" = "Windows" ]; then
echo "${{ github.workspace }}/_go_binary/go/bin" >> $GITHUB_PATH
else
echo "PATH=${{ github.workspace }}/_go_binary/go/bin:$PATH" >> $GITHUB_ENV
fi

- name: Print Go version
run: go version

- name: Setup cache for Go modules
uses: actions/cache@v4
with:
go-version-file: go.mod
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-manual-${{ hashFiles('go.sum', 'go.mod') }}
restore-keys: |
${{ runner.os }}-go-manual-

- name: Setup Python
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
Expand All @@ -62,12 +81,6 @@ jobs:
with:
version: "0.6.5"

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
go install gotest.tools/[email protected]

- name: Pull external libraries
run: |
make vendor
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default: tidy vendor fmt lint ws
PACKAGES=./acceptance/... ./libs/... ./internal/... ./cmd/... ./bundle/... .

GOTESTSUM_FORMAT ?= pkgname-and-test-fails
GOTESTSUM_CMD ?= gotestsum --format ${GOTESTSUM_FORMAT} --no-summary=skipped
GOTESTSUM_CMD ?= go tool gotestsum --format ${GOTESTSUM_FORMAT} --no-summary=skipped


lint:
Expand Down Expand Up @@ -55,7 +55,7 @@ schema:
docs:
go run ./bundle/docsgen ./bundle/internal/schema ./bundle/docsgen

INTEGRATION = gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./acceptance ./integration/..." -- -parallel 4 -timeout=2h
INTEGRATION = go tool gotestsum --format github-actions --rerun-fails --jsonfile output.json --packages "./acceptance ./integration/..." -- -parallel 4 -timeout=2h

integration: vendor
$(INTEGRATION)
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ require (
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bitfield/gotestdox v0.2.2 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cloudflare/circl v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
Expand All @@ -60,6 +63,7 @@ require (
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand Down Expand Up @@ -114,4 +118,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc v1.69.4 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gotest.tools/gotestsum v1.12.1 // indirect
)

tool gotest.tools/gotestsum
14 changes: 14 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions tools/get_go.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
import platform
import os
import time
import re
import shutil
import sys
import tarfile
import zipfile
from pathlib import Path
from urllib.request import urlretrieve


def get_go_version_from_mod(file_path):
with open(file_path) as f:
content = f.read()
match = re.search(r"^toolchain\s+go(\d+\.\d+(\.\d+)?)", content, re.MULTILINE)
if match:
return match.group(1)


def detect_os_arch():
system = platform.system().lower()
machine = platform.machine().lower()
arch = {"x86_64": "amd64", "amd64": "amd64", "aarch64": "arm64", "arm64": "arm64"}.get(machine, machine)
print(f"Platform: {system=} {arch=} {machine=}")
return system, arch


def download_and_extract(go_version, os_name, arch):
ext = "zip" if os_name == "windows" else "tar.gz"
filename = f"go{go_version}.{os_name}-{arch}.{ext}"
url = f"https://go.dev/dl/{filename}"

print(f"Downloading {url} to {filename}")
start = time.time()
urlretrieve(url, filename)
took = time.time() - start
size = os.stat(filename).st_size
print(f"Downloaded {size / 1024.0 / 1024.0:.1f}MB in {took:.1f}s")

try:
os.mkdir("_go_binary")
except FileExistsError:
pass

if ext == "zip":
with zipfile.ZipFile(filename, "r") as zip_ref:
zip_ref.extractall("_go_binary")
else:
with tarfile.open(filename, "r:gz") as tar_ref:
tar_ref.extractall("_go_binary")


def main():
go_version = get_go_version_from_mod("go.mod")
assert go_version
os_name, arch = detect_os_arch()
download_and_extract(go_version, os_name, arch)


if __name__ == "__main__":
main()
Loading