Skip to content

Commit

Permalink
Merges [PR](#18)
Browse files Browse the repository at this point in the history
Add support for global dotenv files in task parsing
  • Loading branch information
nxtcoder17 authored Oct 20, 2024
2 parents 138ff91 + 2a1516e commit 8835533
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/runfile/task-parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func ParseTask(ctx Context, rf *Runfile, task Task) (*ParsedTask, *Error) {
}
}

if rf.DotEnv != nil {
m, err := parseDotEnvFiles(rf.DotEnv...)
if err != nil {
return nil, err
}
for k, v := range m {
globalEnv[k] = v
}
}

for _, requirement := range task.Requires {
if requirement == nil {
continue
Expand Down
57 changes: 57 additions & 0 deletions pkg/runfile/task-parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,66 @@ echo "hi"
},
}

testGlobalDotEnv := []test{
{
name: "1. testing global env key-value item",
args: args{
ctx: nil,
rf: &Runfile{
DotEnv: []string{
dotenvTestFile.Name(),
},
Tasks: map[string]Task{
"test": {
ignoreSystemEnv: true,
Commands: []any{
"echo hi",
},
},
},
},
taskName: "test",
},
want: &ParsedTask{
Shell: []string{"sh", "-c"},
WorkingDir: fn.Must(os.Getwd()),
Env: map[string]string{
"hello": "world",
},
Commands: []CommandJson{
{Command: "echo hi"},
},
},
wantErr: false,
},
{
name: "2. fails when dotenv file not found",
args: args{
ctx: nil,
rf: &Runfile{
DotEnv: []string{
dotenvTestFile.Name() + "2",
},
Tasks: map[string]Task{
"test": {
ignoreSystemEnv: true,
Commands: []any{
"echo hi",
},
},
},
},
taskName: "test",
},
want: nil,
wantErr: true,
},
}

tests = append(tests, testRequires...)
tests = append(tests, testEnviroments...)
tests = append(tests, testGlobalEnvVars...)
tests = append(tests, testGlobalDotEnv...)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8835533

Please sign in to comment.