Skip to content
quarry Artifact [6945fea91d]
Login

Artifact [6945fea91d]

Artifact 6945fea91d7dec575aa43768189b2f142ad6167516353bf13b78376abead593b:


package runner

import (
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strings"
	"testing"
)

// THE RUNNER BUILDS FOR EVERY PLATFORM THE FORGE SERVES IT FOR.
//
// The downloads are built by scripts/build-linux.sh, and a runner that
// fails to build for one platform broke the whole published set
// (isolate.go called syscall.Dup2, which linux/arm64 and windows lack).
// The list is read from the script, so a platform added there is
// covered here.
func TestTheRunnerBuildsForEveryPlatformItShips(t *testing.T) {
	if testing.Short() {
		t.Skip("cross-builds are slow")
	}
	root, err := filepath.Abs("../..")
	if err != nil {
		t.Fatal(err)
	}
	script, err := os.ReadFile(filepath.Join(root, "scripts", "build-linux.sh"))
	if err != nil {
		t.Fatal(err)
	}
	// RUNNER_TARGETS is the one list: the build loops over it and
	// scripts/runner-check.sh judges a published set complete against it.
	m := regexp.MustCompile(`(?m)^RUNNER_TARGETS="([^"]+)"$`).FindSubmatch(script)
	if m == nil {
		t.Fatal("FAIL: scripts/build-linux.sh has no RUNNER_TARGETS=\"...\" list to read")
	}
	targets := strings.Fields(string(m[1]))
	if len(targets) < 2 {
		t.Fatalf("FAIL: read targets %v", targets)
	}
	for _, target := range targets {
		goos, goarch, ok := strings.Cut(target, "/")
		if !ok {
			t.Fatalf("FAIL: target %q is not os/arch", target)
		}
		cmd := exec.Command("go", "build", "-o", os.DevNull, "./cmd/quarry-runner")
		cmd.Dir = root
		cmd.Env = append(os.Environ(), "CGO_ENABLED=0", "GOOS="+goos, "GOARCH="+goarch)
		if out, err := cmd.CombinedOutput(); err != nil {
			t.Errorf("FAIL: quarry-runner does not build for %s: %v\n%s", target, err, out)
		}
	}
	t.Logf("ok: quarry-runner builds for %v", targets)
}