Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remote): replace env variable in include remote URL #1610

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion taskfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/compiler"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/templater"
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'
11 changes: 11 additions & 0 deletions website/docs/experiments/remote_taskfiles.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ tasks:
and you run `task my-remote-namespace:hello`, it will print the text: "Hello
from the remote Taskfile!" to your console.

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
```

`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`

## Security

Running commands from sources that you do not control is always a potential
Expand Down
Loading