package store import "strings" // Satisfies reports whether this machine can take a job that asked for these labels. func (r Runner) Satisfies(want []string) bool { // A job that asks for nothing runs anywhere, which is what [build] command has always done. if len(want) == 0 { return true } for _, label := range want { if !r.has(label) { return false } } return true } // has answers one label, translating GitHub's hosted names into what a runner reports about itself. func (r Runner) has(label string) bool { label = strings.ToLower(strings.TrimSpace(label)) // Every barerepo runner is self-hosted, so the label that says so is always true here. if label == "self-hosted" { return true } for _, own := range r.Labels { if strings.EqualFold(strings.TrimSpace(own), label) { return true } } if os, ok := hostedOS(label); ok { return strings.EqualFold(r.OS, os) } return strings.EqualFold(r.OS, label) || strings.EqualFold(r.Arch, label) } // hostedOS maps GitHub's runner images to an operating system, which is all barerepo can check. func hostedOS(label string) (string, bool) { switch { case strings.HasPrefix(label, "ubuntu-"), label == "ubuntu", strings.HasPrefix(label, "linux-"), label == "linux": return "linux", true case strings.HasPrefix(label, "macos-"), label == "macos", label == "darwin": return "darwin", true case strings.HasPrefix(label, "windows-"), label == "windows": return "windows", true } return "", false }