Skip to content

Commit a736fde

Browse files
committed
✨ feat: implement GOWORK environment handling in buildexec
Add logic to set the GOWORK environment variable in the build execution steps. This helps ensure that the appropriate Go workspace is used during command execution, improving compatibility with Go modules. Additionally, modify the build plan for the "vibeaura" module to check for the existence of the cmd/vibeaura directory, allowing for targeted compilation.
1 parent 7884f36 commit a736fde

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

internal/cli/buildexec.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"path/filepath"
89
"strings"
910
)
1011

@@ -18,9 +19,18 @@ func runBuildStep(ctx context.Context, workDir, step, toolchain string) error {
1819

1920
fmt.Printf("Executing: %s\n", step)
2021

22+
goworkVal := "off"
23+
absWorkDir, err := filepath.Abs(workDir)
24+
if err == nil {
25+
if _, err := os.Stat(filepath.Join(absWorkDir, "go.work")); err == nil {
26+
goworkVal = filepath.Join(absWorkDir, "go.work")
27+
}
28+
}
29+
2130
if toolchain == "shell" || needsShell(step) {
2231
cmd := exec.CommandContext(ctx, "bash", "-c", step)
2332
cmd.Dir = workDir
33+
cmd.Env = append(os.Environ(), "GOWORK="+goworkVal)
2434
cmd.Stdout = os.Stdout
2535
cmd.Stderr = os.Stderr
2636
if err := cmd.Run(); err != nil {
@@ -46,8 +56,9 @@ func runBuildStep(ctx context.Context, workDir, step, toolchain string) error {
4656

4757
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
4858
cmd.Dir = workDir
59+
cmd.Env = append(os.Environ(), "GOWORK="+goworkVal)
4960
if len(env) > 0 {
50-
cmd.Env = append(os.Environ(), env...)
61+
cmd.Env = append(cmd.Env, env...)
5162
}
5263
cmd.Stdout = os.Stdout
5364
cmd.Stderr = os.Stderr

internal/cli/submodules.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func buildPlanForGoModule(name, dir string) agent.BuildPlan {
6262
}
6363
if name == "vibeauracle" {
6464
outName = "vibeaura"
65+
// If cmd/vibeaura exists inside the dir, compile from there
66+
if _, err := os.Stat(filepath.Join(dir, "cmd", "vibeaura")); err == nil {
67+
target = "./cmd/vibeaura"
68+
}
6569
}
6670
return agent.BuildPlan{
6771
Steps: []string{fmt.Sprintf("CGO_ENABLED=0 go build -ldflags '-s -w' -o %s %s", outName, target)},
@@ -79,13 +83,17 @@ func (i *Ingestor) resolveSubmoduleTargets(workDir string) ([]submoduleTarget, e
7983

8084
var targets []submoduleTarget
8185
lines := strings.Split(string(data), "\n")
82-
var currentPath string
8386
for _, line := range lines {
8487
line = strings.TrimSpace(line)
85-
if strings.HasPrefix(line, "path = ") {
86-
currentPath = strings.TrimSpace(strings.TrimPrefix(line, "path = "))
88+
if !strings.HasPrefix(line, "path =") && !strings.HasPrefix(line, "path=") {
89+
continue
90+
}
91+
92+
parts := strings.SplitN(line, "=", 2)
93+
if len(parts) < 2 {
8794
continue
8895
}
96+
currentPath := strings.TrimSpace(parts[1])
8997
if currentPath == "" {
9098
continue
9199
}
@@ -100,8 +108,11 @@ func (i *Ingestor) resolveSubmoduleTargets(workDir string) ([]submoduleTarget, e
100108
WorkDir: subDir,
101109
Manifest: m,
102110
})
111+
continue
103112
}
104-
} else if _, err := os.Stat(filepath.Join(subDir, "go.mod")); err == nil {
113+
}
114+
115+
if _, err := os.Stat(filepath.Join(subDir, "go.mod")); err == nil {
105116
name := filepath.Base(currentPath)
106117
targets = append(targets, submoduleTarget{
107118
Name: name,
@@ -112,7 +123,6 @@ func (i *Ingestor) resolveSubmoduleTargets(workDir string) ([]submoduleTarget, e
112123
},
113124
})
114125
}
115-
currentPath = ""
116126
}
117127
return targets, nil
118128
}
@@ -182,6 +192,12 @@ func (i *Ingestor) buildSubmoduleBinary(ctx context.Context, target submoduleTar
182192
dst = filepath.Join(binDir, target.Manifest.BinName)
183193
}
184194

195+
if _, err := os.Stat(dst); err == nil {
196+
oldBin := dst + ".bak"
197+
_ = os.Remove(oldBin)
198+
_ = os.Rename(dst, oldBin)
199+
}
200+
185201
data, err := os.ReadFile(src)
186202
if err != nil {
187203
return err

0 commit comments

Comments
 (0)