Pipeline runs use the workspace's directory environment
Resolve the run workspace's environment with workenv (direnv, parent .envrc, mise; same account rule as Claude chats) at run start and resume, and apply it to Pi stage processes, a per-environment Pipelines-owned OpenCode stage service (keyed by a hash of the change, reused across runs, idle ones stopped after PIPELINES_OPENCODE_STAGE_IDLE_TIMEOUT, revived per registration), delivery-gate checks and merges, plain-stage opencode CLI calls and file-change capture git reads. Record the directory, .envrc files, sources and variable names (never values) on the run detail; a blocked .envrc becomes a run warning.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/workenv"
|
||||
)
|
||||
|
||||
// withRunEnvironment resolves the workspace's own environment (direnv/mise,
|
||||
// with the same rules as Claude chats, a parent .envrc included), records its
|
||||
// files and variable names on the run, and returns ctx carrying it so stage
|
||||
// processes, the OpenCode stage service, delivery checks and file captures
|
||||
// start with it. A blocked .envrc becomes a run warning; nothing from it is
|
||||
// applied. A fresh run, a resumed decision and a reattached run all resolve
|
||||
// again, so an edited .envrc is seen at the next start.
|
||||
func (r *runner) withRunEnvironment(ctx context.Context, id int64, workspace string) context.Context {
|
||||
resolver := r.dirEnv
|
||||
if resolver == nil {
|
||||
resolver = workenv.Default
|
||||
}
|
||||
env := resolver.Environment(ctx, workspace, os.Environ())
|
||||
for _, warning := range env.Warnings {
|
||||
log.Printf("run %d workspace %s: %s", id, workspace, warning)
|
||||
}
|
||||
if env.Applies() {
|
||||
log.Printf("run %d workspace %s: applying its environment from %v (%d set, %d unset, %d inherited credentials dropped)", id, workspace, env.Sources, len(env.Set), len(env.Unset), len(env.Dropped))
|
||||
}
|
||||
save, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := r.store.SetRunEnvironment(save, id, runEnvironmentRecord(env)); err != nil {
|
||||
log.Printf("run %d: record workspace environment: %v", id, err)
|
||||
}
|
||||
return workenv.WithEnvironment(ctx, env)
|
||||
}
|
||||
|
||||
// runEnvironmentRecord keeps names and files only, never values.
|
||||
func runEnvironmentRecord(env workenv.Environment) *protocol.RunEnvironment {
|
||||
return &protocol.RunEnvironment{
|
||||
Directory: env.Directory,
|
||||
Files: env.Files,
|
||||
Sources: env.Sources,
|
||||
Set: env.Set,
|
||||
Unset: env.Unset,
|
||||
Dropped: env.Dropped,
|
||||
Warnings: env.Warnings,
|
||||
ServiceKey: env.Key,
|
||||
ResolvedAt: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user