Skip to content

Commit 174d62b

Browse files
committed
fix: dot-env insconsistency [issue: 29](#29)
1 parent e3477d9 commit 174d62b

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

examples/run1/Runfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ tasks:
1414
- node
1515

1616
printenv:
17+
dotenv:
18+
- ../../.secrets/env
1719
cmd:
1820
- printenv file1_env1
21+
- printenv key_id

examples/run2/Runfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
version: 0.0.1
22

3+
dotenv:
4+
- ../../.secrets/env
5+
36
tasks:
47
echo:
58
cmd:
69
- echo "hello from run2"
10+
- printenv key_id

parser/parse-command.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ func parseCommand(prf *types.ParsedRunfile, command any) (*types.ParsedCommandJs
3131
}
3232

3333
pcj := types.ParsedCommandJson{
34-
Env: cj.Env,
35-
Parallel: cj.Parallel,
34+
Env: cj.Env,
3635
}
3736

3837
switch {

parser/parse-task.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@ func ParseTask(ctx context.Context, prf *types.ParsedRunfile, task types.Task) (
3232
taskEnv = make(map[string]string)
3333
}
3434

35-
tdotenv, err := parseDotEnvFiles(task.DotEnv...)
35+
dotEnvs := make([]string, 0, len(task.DotEnv))
36+
for i := range task.DotEnv {
37+
de := task.DotEnv[i]
38+
if !filepath.IsAbs(de) {
39+
result := filepath.Join(filepath.Dir(*task.Metadata.RunfilePath), de)
40+
// fmt.Println("HERE", "runfilepath", prf.Metadata.RunfilePath, "dotenv", de, "result", result)
41+
de = result
42+
}
43+
44+
dotEnvs = append(dotEnvs, de)
45+
}
46+
47+
tdotenv, err := parseDotEnvFiles(dotEnvs...)
3648
if err != nil {
3749
return nil, err
3850
}

parser/parser-runfile.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ func parseRunfile(runfile *types.Runfile) (*types.ParsedRunfile, error) {
3838

3939
dotEnvFiles := make([]string, 0, len(runfile.DotEnv))
4040
for i := range runfile.DotEnv {
41-
dotEnvFiles = append(dotEnvFiles, fn.Must(filepath.Abs(runfile.DotEnv[i])))
41+
de := runfile.DotEnv[i]
42+
if !filepath.IsAbs(de) {
43+
result := filepath.Join(filepath.Dir(runfile.Filepath), de)
44+
// fmt.Println("HERE", "runfilepath", prf.Metadata.RunfilePath, "dotenv", de, "result", result)
45+
de = result
46+
}
47+
dotEnvFiles = append(dotEnvFiles, de)
4248
}
4349

4450
// dotenvVars, err := parseDotEnvFiles(runfile.DotEnv...)
@@ -69,12 +75,15 @@ func parseRunfileFromFile(file string) (*types.ParsedRunfile, error) {
6975
return nil, errors.ErrParseRunfile.Wrap(err)
7076
}
7177

78+
runfile.Filepath = fn.Must(filepath.Abs(file))
79+
7280
prf, err := parseRunfile(&runfile)
7381
if err != nil {
7482
return nil, err
7583
}
7684

77-
prf.Metadata.RunfilePath = file
85+
// prf.Metadata.RunfilePath = file
86+
prf.Metadata.RunfilePath = fn.Must(filepath.Abs(file))
7887
return prf, nil
7988
}
8089

types/parsed-types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ type ParsedRunfile struct {
1010
}
1111

1212
type ParsedTask struct {
13-
Shell []string `json:"shell"`
14-
WorkingDir string `json:"workingDir"`
15-
Watch *TaskWatch `json:"watch,omitempty"`
16-
Env map[string]string `json:"environ"`
17-
Interactive bool `json:"interactive,omitempty"`
18-
Commands []ParsedCommandJson `json:"commands"`
13+
Shell []string `json:"shell"`
14+
WorkingDir string `json:"workingDir"`
15+
Watch *TaskWatch `json:"watch,omitempty"`
16+
Env map[string]string `json:"environ"`
17+
Interactive bool `json:"interactive,omitempty"`
18+
19+
// Parallel allows you to run commands or run targets in parallel
20+
Parallel bool `json:"parallel"`
21+
22+
Commands []ParsedCommandJson `json:"commands"`
1923
}
2024

2125
type ParsedCommandJson struct {
@@ -25,9 +29,6 @@ type ParsedCommandJson struct {
2529

2630
// If is a go template expression, which must evaluate to true, for task to run
2731
If *bool `json:"if"`
28-
29-
// Parallel allows you to run commands or run targets in parallel
30-
Parallel bool `json:"parallel"`
3132
}
3233

3334
type ParsedIncludeSpec struct {

types/types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
type Runfile struct {
4+
Filepath string
45
Version string `json:"version,omitempty"`
56
Includes map[string]IncludeSpec `json:"includes"`
67
Env EnvVar `json:"env,omitempty"`
@@ -74,6 +75,9 @@ type Task struct {
7475

7576
Interactive bool `json:"interactive,omitempty"`
7677

78+
// Parallel allows you to run commands
79+
Parallel bool `json:"parallel"`
80+
7781
// List of commands to be executed in given shell (default: sh)
7882
// can take multiple forms
7983
// - simple string
@@ -95,6 +99,5 @@ type CommandJson struct {
9599
// If is a go template expression, which must evaluate to true, for task to run
96100
If *string `json:"if,omitempty"`
97101

98-
// Parallel allows you to run commands or run targets in parallel
99102
Parallel bool `json:"parallel"`
100103
}

0 commit comments

Comments
 (0)