feat: remote taskfiles (HTTP) (#1152)

* feat: remote taskfiles over http

* feat: allow insecure connections when --insecure flag is provided

* feat: better error handling for fetch errors

* fix: ensure cache directory always exists

* fix: setup logger before everything else

* feat: put remote taskfiles behind an experiment

* feat: --download and --offline flags for remote taskfiles

* feat: node.Read accepts a context

* feat: experiment docs

* chore: changelog

* chore: remove unused optional param from Node interface

* chore: tidy up and generalise NewNode function

* fix: use sha256 in remote checksum

* feat: --download by itself will not run a task

* feat: custom error if remote taskfiles experiment is not enabled

* refactor: BaseNode functional options and simplified FileNode

* fix: use hex encoding for checksum instead of b64
This commit is contained in:
Pete Davison
2023-09-12 16:42:54 -05:00
committed by GitHub
parent 84ad0056e4
commit 22ce67c5e5
19 changed files with 611 additions and 120 deletions

View File

@@ -1,30 +1,39 @@
package read
import (
"context"
"strings"
"github.com/go-task/task/v3/taskfile"
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/experiments"
)
type Node interface {
Read() (*taskfile.Taskfile, error)
Read(ctx context.Context) ([]byte, error)
Parent() Node
Optional() bool
Location() string
Optional() bool
Remote() bool
}
func NewNodeFromIncludedTaskfile(parent Node, includedTaskfile taskfile.IncludedTaskfile) (Node, error) {
switch getScheme(includedTaskfile.Taskfile) {
// TODO: Add support for other schemes.
// If no other scheme matches, we assume it's a file.
// This also allows users to explicitly set a file:// scheme.
func NewNode(
uri string,
insecure bool,
opts ...NodeOption,
) (Node, error) {
var node Node
var err error
switch getScheme(uri) {
case "http", "https":
node, err = NewHTTPNode(uri, insecure, opts...)
default:
path, err := includedTaskfile.FullTaskfilePath()
if err != nil {
return nil, err
}
return NewFileNode(parent, path, includedTaskfile.Optional)
// If no other scheme matches, we assume it's a file
node, err = NewFileNode(uri, opts...)
}
if node.Remote() && !experiments.RemoteTaskfiles {
return nil, errors.New("task: Remote taskfiles are not enabled. You can read more about this experiment and how to enable it at https://taskfile.dev/experiments/remote-taskfiles")
}
return node, err
}
func getScheme(uri string) string {