From 7da3fb0aced5800262d5e3d659081990fb42ad73 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 16:53:09 +0000 Subject: [PATCH] sqlc-test-setup: retry apt-get when the mirror fails PR runs on 2026-11-11 failed installing libossp-uuid16 because the runner could not resolve azure.archive.ubuntu.com. Run apt-get through one helper that retries downloads and, on failure, refreshes the package lists and tries once more. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LuRZ4KZiFRZfbAgYWP6ndH --- cmd/sqlc-test-setup/main.go | 23 +++++++++++++++++++++-- cmd/sqlc-test-setup/mssql.go | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/sqlc-test-setup/main.go b/cmd/sqlc-test-setup/main.go index 30c0280ac2..36366c723b 100644 --- a/cmd/sqlc-test-setup/main.go +++ b/cmd/sqlc-test-setup/main.go @@ -354,12 +354,31 @@ func installPostgreSQL() error { // runtime (e.g. libossp-uuid16 for uuid-ossp). func installPgDeps() error { log.Println("installing postgresql runtime dependencies") - if err := run("sudo", "apt-get", "install", "-y", "--no-install-recommends", "libossp-uuid16"); err != nil { + if err := aptGet("install", "-y", "--no-install-recommends", "libossp-uuid16"); err != nil { return fmt.Errorf("apt-get install libossp-uuid16: %w", err) } return nil } +// aptGet runs sudo apt-get with the given arguments. The runner's Ubuntu +// mirror occasionally fails to resolve or serve a package, so apt retries +// each download, and a failed run is tried once more after refreshing the +// package lists, which also picks up a package the stale lists point at a +// version the mirror no longer has. +func aptGet(args ...string) error { + cmd := append([]string{"env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-o", "Acquire::Retries=5"}, args...) + err := run("sudo", cmd...) + if err == nil { + return nil + } + log.Printf("apt-get %s failed (%v), refreshing package lists and retrying", strings.Join(args, " "), err) + time.Sleep(10 * time.Second) + if uerr := run("sudo", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-o", "Acquire::Retries=5", "update"); uerr != nil { + log.Printf("apt-get update failed: %v", uerr) + } + return run("sudo", cmd...) +} + // supportedPlatforms returns a comma-separated list of supported platforms. func supportedPlatforms() string { platforms := make([]string, 0, len(pgBinaries)) @@ -485,7 +504,7 @@ func installMySQL() error { } log.Println("fixing missing dependencies with apt-get install -f") - if err := run("sudo", "apt-get", "install", "-f", "-y"); err != nil { + if err := aptGet("install", "-f", "-y"); err != nil { return fmt.Errorf("apt-get install -f: %w", err) } diff --git a/cmd/sqlc-test-setup/mssql.go b/cmd/sqlc-test-setup/mssql.go index 132aa5461d..8ddbecdd68 100644 --- a/cmd/sqlc-test-setup/mssql.go +++ b/cmd/sqlc-test-setup/mssql.go @@ -81,11 +81,11 @@ func installMSSQL() error { return err } - if err := run("sudo", "apt-get", "update"); err != nil { + if err := aptGet("update"); err != nil { return fmt.Errorf("apt-get update: %w", err) } log.Println("installing mssql-server") - if err := run("sudo", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "install", "-y", "mssql-server"); err != nil { + if err := aptGet("install", "-y", "mssql-server"); err != nil { return fmt.Errorf("apt-get install mssql-server: %w", err) }