- Introduce `-config-overlay` flag and `config.LoadOverlay()` to merge a base config with an overlay file, only overriding fields the overlay sets. This enables docker-compose to mount the base config from the host and apply only deployment-specific overrides. - Create `internal/natsrpc` package with reusable NATS request/reply primitives (Envelope, Client, Call, RegisterAll, Respond). Migrate storerpc, worktreerpc, and forgerpc to use it, eliminating duplicated marshal/unmarshal and error handling. - Create `internal/yaegiutil` package with shared interpreter construction (stdlib + extra symbols), generic export resolution (Resolve), and panic recovery (Safe). Migrate all Yaegi-based surfaces (gate scripts, daemon plugins, skill plugins, workflow stages, skill scripts) to use it, reducing boilerplate and centralizing panic safety. - Simplify `config.docker.toml` to contain only overlay fields (paths, container config) and remove the duplicated repos list – the base config is now the single source of truth. - Update docker-compose.yml to pass both -config and -config-overlay flags and mount the base config from the host. - Add tests for LoadOverlay, DockerConfigOverlaysExampleConfig, Envelope, and yaegiutil utilities.
79 lines
2.4 KiB
Go
79 lines
2.4 KiB
Go
// Package wfeval discovers and interprets a repo's custom workflow
|
|
// stages: .archie/stages/*.go files, each exporting a Stage() function
|
|
// that returns a workflow.Stage. Split from internal/workflow (and its
|
|
// generated symbol table in wfextract) to avoid the import cycle that
|
|
// would result from workflow depending on its own extracted symbols.
|
|
package wfeval
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
|
|
"github.com/traefik/yaegi/interp"
|
|
|
|
"github.com/samcharles93/archie-core/internal/workflow"
|
|
"github.com/samcharles93/archie-core/internal/workflow/wfextract"
|
|
"github.com/samcharles93/archie-core/internal/yaegiutil"
|
|
)
|
|
|
|
// stagesDir is where a repo's custom stage scripts live, relative to
|
|
// the worktree root.
|
|
const stagesDir = ".archie/stages"
|
|
|
|
// Discover loads every .archie/stages/*.go file in dir and returns the
|
|
// workflow.Stage each exports, in filename order. A missing directory is
|
|
// not an error — it returns (nil, nil), meaning no custom stages are
|
|
// configured for this repo.
|
|
func Discover(dir string) ([]workflow.Stage, error) {
|
|
entries, err := os.ReadDir(filepath.Join(dir, stagesDir))
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil, nil
|
|
}
|
|
return nil, fmt.Errorf("read %s: %w", stagesDir, err)
|
|
}
|
|
|
|
var names []string
|
|
for _, e := range entries {
|
|
if !e.IsDir() && filepath.Ext(e.Name()) == ".go" {
|
|
names = append(names, e.Name())
|
|
}
|
|
}
|
|
sort.Strings(names)
|
|
|
|
stages := make([]workflow.Stage, 0, len(names))
|
|
for _, name := range names {
|
|
stage, err := loadStage(filepath.Join(dir, stagesDir, name))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("%s: %w", filepath.Join(stagesDir, name), err)
|
|
}
|
|
stages = append(stages, stage)
|
|
}
|
|
return stages, nil
|
|
}
|
|
|
|
// loadStage interprets one custom stage script and calls its exported
|
|
// Stage() function. The script runs in-process (interpreted, not
|
|
// sandboxed), so a panic inside it is recovered and returned as an error
|
|
// rather than taking down the daemon.
|
|
func loadStage(path string) (workflow.Stage, error) {
|
|
src, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return workflow.Stage{}, err
|
|
}
|
|
|
|
return yaegiutil.Safe(path, func() (workflow.Stage, error) {
|
|
i, err := yaegiutil.New(interp.Options{}, wfextract.Symbols)
|
|
if err != nil {
|
|
return workflow.Stage{}, err
|
|
}
|
|
factory, err := yaegiutil.Resolve[func() workflow.Stage](i, string(src), "stages.Stage")
|
|
if err != nil {
|
|
return workflow.Stage{}, fmt.Errorf("yaegi: %w", err)
|
|
}
|
|
return factory(), nil
|
|
})
|
|
}
|