feat: wire configured harness execution
This commit is contained in:
@@ -10,6 +10,9 @@ import (
|
||||
"orchestra/internal/domain"
|
||||
"orchestra/internal/herdr"
|
||||
"orchestra/internal/store"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -20,6 +23,43 @@ type Adapters interface {
|
||||
Adapter(string) (herdr.Adapter, error)
|
||||
}
|
||||
|
||||
// GitWorktrees creates one isolated checkout per task. The root is expected
|
||||
// to be a clone containing the project's remote; callers may set a separate
|
||||
// root per deployment.
|
||||
type GitWorktrees struct {
|
||||
Root string
|
||||
Repo string
|
||||
}
|
||||
|
||||
func (w GitWorktrees) Create(ctx context.Context, t domain.Task) (string, error) {
|
||||
if w.Root == "" || w.Repo == "" {
|
||||
return "", fmt.Errorf("worktree: root and repo required")
|
||||
}
|
||||
if err := os.MkdirAll(w.Root, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
p := filepath.Join(w.Root, t.ID)
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p, nil
|
||||
}
|
||||
branch := "orchestra/" + t.ID
|
||||
cmd := exec.CommandContext(ctx, "git", "-C", w.Repo, "worktree", "add", "-b", branch, p, "HEAD")
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return "", fmt.Errorf("%s: %w", string(out), err)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
type AdapterFactory struct{ Herdrs map[string]herdr.Adapter }
|
||||
|
||||
func (f AdapterFactory) Adapter(id string) (herdr.Adapter, error) {
|
||||
a, ok := f.Herdrs[id]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("adapter %q not registered", id)
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
type Coordinator struct {
|
||||
Store *store.Store
|
||||
Worktrees Worktrees
|
||||
|
||||
Reference in New Issue
Block a user