Skip to content

Commit

Permalink
use templating system instead of os.ExpandEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaerten committed Apr 29, 2024
1 parent 91898ae commit 5aaf6b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,10 @@ func TestIncludesInterpolation(t *testing.T) {
expectedOutput string
}{
{"include", "include", false, "include\n"},
{"include_with_env_variable", "include-with-env-variable", false, "include_with_env_variable\n"},
{"include_with_dir", "include-with-dir", false, "included\n"},
}
t.Setenv("MODULE", "included")

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions taskfile/node_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"time"

Expand All @@ -30,8 +29,7 @@ func NewHTTPNode(
opts ...NodeOption,
) (*HTTPNode, error) {
base := NewBaseNode(dir, opts...)
entrypointWithEnv := os.ExpandEnv(entrypoint)
url, err := url.Parse(entrypointWithEnv)
url, err := url.Parse(entrypoint)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion taskfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package taskfile
import (
"context"
"fmt"
"github.com/go-task/task/v3/internal/compiler"
"os"
"time"

Expand Down Expand Up @@ -97,9 +98,11 @@ func (r *Reader) include(node Node) error {

// Loop over each included taskfile
_ = vertex.Taskfile.Includes.Range(func(namespace string, include ast.Include) error {
vars := compiler.GetEnviron()
vars.Merge(vertex.Taskfile.Vars, nil)
// Start a goroutine to process each included Taskfile
g.Go(func() error {
cache := &templater.Cache{Vars: vertex.Taskfile.Vars}
cache := &templater.Cache{Vars: vars}
include = ast.Include{
Namespace: include.Namespace,
Taskfile: templater.Replace(include.Taskfile, cache),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "3"

includes:
include-with-env-variable: '../{{.MODULE}}/Taskfile.yml'
4 changes: 2 additions & 2 deletions website/docs/experiments/remote_taskfiles.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ tasks:
and you run `task my-remote-namespace:hello`, it will print the text: "Hello
from the remote Taskfile!" to your console.

You can also reference environment variable in your URL to have authentication, for example :
URL is processed by the templating system, so you can reference environment variable in your URL to have authentication, for example :

```yaml
version: '3'
includes:
my-remote-namespace: https://${TOKEN}@raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml
my-remote-namespace: https://{{.TOKEN}}@raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml
```

`TOKEN=my-token task my-remote-namespace:hello` will be resolved by Task to `https://[email protected]/my-org/my-repo/main/Taskfile.yml`
Expand Down

0 comments on commit 5aaf6b2

Please sign in to comment.