Skip to content

Commit 519359b

Browse files
committed
feat: add dir field to bootstrap steps and hooks
1 parent e5eb084 commit 519359b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919

2020
type BootstrapStep struct {
2121
Name string `yaml:"name"`
22+
Dir string `yaml:"dir"`
2223
Check string `yaml:"check"`
2324
Run string `yaml:"run"`
2425
}
@@ -36,6 +37,7 @@ type Hooks struct {
3637

3738
type Hook struct {
3839
Name string `yaml:"name"`
40+
Dir string `yaml:"dir"`
3941
Run string `yaml:"run"`
4042
EnvFile string `yaml:"env_file"`
4143
}

engine/bootstrap.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ import (
1010
// RunBootstrap runs each bootstrap step in order. Skips if check passes. Fails fast on error.
1111
func RunBootstrap(ctx context.Context, dir string, steps []config.BootstrapStep, env []string) error {
1212
for _, step := range steps {
13-
if CheckShell(ctx, dir, step.Check, env) {
13+
d := stepDir(dir, step.Dir)
14+
if CheckShell(ctx, d, step.Check, env) {
1415
continue
1516
}
16-
if err := RunShell(ctx, dir, step.Run, env); err != nil {
17+
if err := RunShell(ctx, d, step.Run, env); err != nil {
1718
return fmt.Errorf("bootstrap %q: %w", step.Name, err)
1819
}
1920
}
2021
return nil
2122
}
23+
24+
func stepDir(base, override string) string {
25+
if override != "" {
26+
return override
27+
}
28+
return base
29+
}

engine/hooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ func RunHooks(ctx context.Context, dir string, hooks []config.Hook, bestEffort b
2020
}
2121
return fmt.Errorf("hook %q: %w", hook.Name, err)
2222
}
23-
if err := RunShell(ctx, dir, hook.Run, env); err != nil {
23+
d := stepDir(dir, hook.Dir)
24+
if err := RunShell(ctx, d, hook.Run, env); err != nil {
2425
if bestEffort {
2526
continue
2627
}

0 commit comments

Comments
 (0)