Files
flake-hub/ci/build.py
T
Oleks d971b72ba4 ci: stream build logs and add env context
setup.sh now traces each command (set -ex) so /etc/hosts, nix.conf,
and netrc setup are visible in pipeline logs.

build.py replaces capture() with a streaming build() helper for
nix builds: stderr is inherited (live --print-build-logs output)
while stdout is captured for the out path. Also dumps nix version,
uname, disk, and memory at the start so failures have context.
2026-04-29 11:16:57 +03:00

62 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Build all flake-hub packages and push to attic."""
import os
import subprocess
import sys
def run(cmd):
print(f"+ {cmd}", flush=True)
r = subprocess.run(cmd, shell=True)
if r.returncode != 0:
sys.exit(r.returncode)
def build(cmd):
"""Run a `nix build`, streaming stderr live; return stdout (the out path)."""
print(f"+ {cmd}", flush=True)
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, text=True)
out, _ = proc.communicate()
if proc.returncode != 0:
sys.exit(proc.returncode)
return out.strip()
ARCH = sys.argv[1]
ATTIC_CACHE = "attic-infra-cache-k3s-1"
ATTIC_SERVER = "https://nix-cache-upload.oleks.space"
ATTIC_TOKEN = os.environ["ATTIC_TOKEN"]
print(f"=== Building flake-hub packages for {ARCH} ===")
# Environment context for log readers
run("nix --version")
run("uname -a")
run("df -h /nix 2>/dev/null || df -h /")
run("free -h")
# Setup attic
attic = (
build("nix build --inputs-from . nixpkgs#attic-client --print-build-logs --print-out-paths --no-link")
+ "/bin/attic"
)
run(f"'{attic}' login ci {ATTIC_SERVER} '{ATTIC_TOKEN}'")
# Packages per arch
packages = ["hello-world", "geesefs", "xonsh"]
if ARCH == "x86_64-linux":
packages += ["google-antigravity", "google-antigravity-no-fhs"]
if ARCH == "s390x-linux":
packages += ["attic-client"]
print("Building packages...")
for pkg in packages:
print(f"--- {pkg} ---")
out = build(
f"nix build '.#packages.{ARCH}.{pkg}' --print-build-logs --print-out-paths --no-link"
)
run(f"'{attic}' push {ATTIC_CACHE} {out}")
print(f"Build completed for {ARCH}")