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

Programmatically enable experiments #2014

Open
rektdeckard opened this issue Jan 22, 2025 · 1 comment
Open

Programmatically enable experiments #2014

rektdeckard opened this issue Jan 22, 2025 · 1 comment
Labels
area: package api Changes related to the usage of Task as a Go package.

Comments

@rektdeckard
Copy link

rektdeckard commented Jan 22, 2025

Description

I am using Task in library/package mode, as an embedded task runner within a larger CLI application. I would like to be able to permanently and programmatically enable experiments (specifically Remote Taskfiles) so that the end user is unaware of it and does not need to explicitly set environment variables, whether in a file or at the command line. Is it possible to expose this option to the Executor? Or is there some undocumented way of doing this?

Thanks!

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jan 22, 2025
@rektdeckard
Copy link
Author

rektdeckard commented Jan 23, 2025

Adding: the current implementation of reading experiments from the env during init() makes it extra challenging to override programmatically, since you can't manually set environment variables within a a running program before the init function runs, I.E.:

package main

import (
	"context"
	"os"
	"github.com/go-task/task/v3"
	"github.com/go-task/task/v3/taskfile/ast"
)

func main() {
	os.Setenv("TASK_X_REMOTE_TASKFILES", "1") // too late; `experiments` has already been `init()`

	exe := &task.Executor{
		Dir:       ".",
		Force:     false,
		ForceAll:  false,
		Insecure:  false,
		Download:  true,
		Offline:   false,
		Watch:     false,
		Verbose:   false,
		Silent:    true,
		AssumeYes: false,
		Dry:       false,
		Summary:   false,
		Parallel:  false,
		Color:     true,
		Stdin:     os.Stdin,
		Stdout:    os.Stdout,
		Stderr:    os.Stderr,
	}
	// internally, here is where the value of `experiments.RemoteTaskfiles.Enabled` is accessed
	// but it was *read* before the start of `main()`
	err := exe.Setup()
	if err != nil {
		os.Exit(1)
	}

	task := &ast.Call{ Task: "foo" }
	if _, err := exe.GetTask(task); err != nil {
		os.Exit(2)
	}

	_ = exe.Run(context.Background(), task)
}

@pd93 pd93 added area: package api Changes related to the usage of Task as a Go package. and removed state: needs triage Waiting to be triaged by a maintainer. labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: package api Changes related to the usage of Task as a Go package.
Projects
None yet
Development

No branches or pull requests

3 participants