mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
feat: root remote taskfiles
This commit is contained in:
@@ -5,8 +5,13 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
"github.com/go-task/task/v3/internal/execext"
|
||||
"github.com/go-task/task/v3/internal/filepathext"
|
||||
"github.com/go-task/task/v3/internal/logger"
|
||||
"github.com/go-task/task/v3/taskfile/ast"
|
||||
)
|
||||
|
||||
// An HTTPNode is a node that reads a Taskfile from a remote location via HTTP.
|
||||
@@ -15,14 +20,19 @@ type HTTPNode struct {
|
||||
URL *url.URL
|
||||
}
|
||||
|
||||
func NewHTTPNode(uri string, insecure bool, opts ...NodeOption) (*HTTPNode, error) {
|
||||
func NewHTTPNode(l *logger.Logger, entrypoint, dir string, insecure bool, opts ...NodeOption) (*HTTPNode, error) {
|
||||
base := NewBaseNode(opts...)
|
||||
url, err := url.Parse(uri)
|
||||
base.dir = dir
|
||||
url, err := url.Parse(entrypoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if url.Scheme == "http" && !insecure {
|
||||
return nil, &errors.TaskfileNotSecureError{URI: uri}
|
||||
return nil, &errors.TaskfileNotSecureError{URI: entrypoint}
|
||||
}
|
||||
url, err = RemoteExists(l, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &HTTPNode{
|
||||
BaseNode: base,
|
||||
@@ -66,6 +76,26 @@ func (node *HTTPNode) Read(ctx context.Context) ([]byte, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (node *HTTPNode) BaseDir() string {
|
||||
return ""
|
||||
func (node *HTTPNode) ResolveIncludeEntrypoint(include ast.Include) (string, error) {
|
||||
ref, err := url.Parse(include.Taskfile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return node.URL.ResolveReference(ref).String(), nil
|
||||
}
|
||||
|
||||
func (node *HTTPNode) ResolveIncludeDir(include ast.Include) (string, error) {
|
||||
path, err := execext.Expand(include.Dir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if filepathext.IsAbs(path) {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
// NOTE: Uses the directory of the entrypoint (Taskfile), not the current working directory
|
||||
// This means that files are included relative to one another
|
||||
entrypointDir := filepath.Dir(node.Dir())
|
||||
return filepathext.SmartJoin(entrypointDir, path), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user