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 90e8904 commit 5427609
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"

Check failure on line 6 in taskfile/reader.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

File is not `gofumpt`-ed (gofumpt)
"os"
"time"

Check failure on line 8 in taskfile/reader.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

File is not `gofumpt`-ed (gofumpt)

Check failure on line 9 in taskfile/reader.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

File is not `goimports`-ed with -local github.com/go-task (goimports)
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://my-token@raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml`
Expand Down

0 comments on commit 5427609

Please sign in to comment.