mirror of
https://github.com/go-task/task.git
synced 2026-07-09 06:55:14 +00:00
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:
@@ -1,34 +1,36 @@
|
||||
package read
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
"github.com/go-task/task/v3/internal/filepathext"
|
||||
"github.com/go-task/task/v3/taskfile"
|
||||
)
|
||||
|
||||
// A FileNode is a node that reads a taskfile from the local filesystem.
|
||||
type FileNode struct {
|
||||
BaseNode
|
||||
*BaseNode
|
||||
Dir string
|
||||
Entrypoint string
|
||||
}
|
||||
|
||||
func NewFileNode(parent Node, path string, optional bool) (*FileNode, error) {
|
||||
path, err := exists(path)
|
||||
func NewFileNode(uri string, opts ...NodeOption) (*FileNode, error) {
|
||||
base := NewBaseNode(opts...)
|
||||
if uri == "" {
|
||||
d, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uri = d
|
||||
}
|
||||
path, err := existsWalk(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &FileNode{
|
||||
BaseNode: BaseNode{
|
||||
parent: parent,
|
||||
optional: optional,
|
||||
},
|
||||
BaseNode: base,
|
||||
Dir: filepath.Dir(path),
|
||||
Entrypoint: filepath.Base(path),
|
||||
}, nil
|
||||
@@ -38,33 +40,15 @@ func (node *FileNode) Location() string {
|
||||
return filepathext.SmartJoin(node.Dir, node.Entrypoint)
|
||||
}
|
||||
|
||||
func (node *FileNode) Read() (*taskfile.Taskfile, error) {
|
||||
if node.Dir == "" {
|
||||
d, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node.Dir = d
|
||||
}
|
||||
func (node *FileNode) Remote() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
path, err := existsWalk(node.Location())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node.Dir = filepath.Dir(path)
|
||||
node.Entrypoint = filepath.Base(path)
|
||||
|
||||
f, err := os.Open(path)
|
||||
func (node *FileNode) Read(ctx context.Context) ([]byte, error) {
|
||||
f, err := os.Open(node.Location())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var t taskfile.Taskfile
|
||||
if err := yaml.NewDecoder(f).Decode(&t); err != nil {
|
||||
return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(path), Err: err}
|
||||
}
|
||||
|
||||
t.Location = path
|
||||
return &t, nil
|
||||
return io.ReadAll(f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user