Skip to content
Closed
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
1 change: 0 additions & 1 deletion cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func main() {
v, err := e.Taskfile.ParsedVersion()
if err != nil {
log.Fatal(err)
return
}

if list {
Expand Down
7 changes: 6 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ This installation method is community owned.
First, make sure you have [Go][go] properly installed and setup.

Task requires [Go Modules](https://github.com/golang/go/wiki/Modules) and
doesn't officially support installing via `go get` anymore.
can be installed got `go get` given that you have a recent version of [Go][go].

```bash
go get -u github.com/go-task/task/cmd/task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can no longer install task with go get as of 1.18.

https://tip.golang.org/doc/go1.18#introduction

This document should reflect the use of go install

```


Installing in another directory:

Expand Down
15 changes: 15 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,21 @@ func TestLabelInStatus(t *testing.T) {
}
}

func TestTaskfileParentDirectory(t *testing.T) {
const dir = "testdata/walk_up/child1/child2"

var buff bytes.Buffer

e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "hello"}))
assert.Equal(t, "Hello World from Task!\n", buff.String())
}

func TestLabelWithVariableExpansion(t *testing.T) {
const dir = "testdata/label_var"

Expand Down
29 changes: 26 additions & 3 deletions taskfile/read/taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

"github.com/go-task/task/v3/internal/templater"
"github.com/go-task/task/v3/taskfile"
Expand All @@ -23,9 +24,12 @@ var (

// Taskfile reads a Taskfile for a given directory
func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
path := filepath.Join(dir, entrypoint)
if _, err := os.Stat(path); err != nil {
return nil, fmt.Errorf(`task: No Taskfile found on "%s". Use "task --init" to create a new one`, path)
// we need the full path to iterate
dir, _ = filepath.Abs(dir)

path, err := findPath(dir, entrypoint)
if err != nil {
return nil, err
}
t, err := readTaskfile(path)
if err != nil {
Expand Down Expand Up @@ -133,6 +137,25 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
return t, nil
}

func findPath(dir string, entrypoint string) (path string, err error) {
found := false
anker := filepath.Join(dir, entrypoint)
for !found {
path = filepath.Join(dir, entrypoint)
if _, err := os.Stat(path); err != nil {
if dir == "/" {
return "", fmt.Errorf(`task: No Taskfile found on "%s". Use "task --init" to create a new one`, anker)
}
dirFragments := strings.Split(dir, string(os.PathSeparator))
dir = "/" + strings.Join(dirFragments[1:len(dirFragments)-1], string(os.PathSeparator))
Comment on lines +149 to +150
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using instead:

Suggested change
dirFragments := strings.Split(dir, string(os.PathSeparator))
dir = "/" + strings.Join(dirFragments[1:len(dirFragments)-1], string(os.PathSeparator))
dir, _ := path.Split(dir)


} else {
found = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, you don't even need found here, you can just break.

}
}
return
}

func readTaskfile(file string) (*taskfile.Taskfile, error) {
f, err := os.Open(file)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions testdata/walk_up/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

tasks:
hello:
cmds:
- echo 'Hello World from Task!'
silent: true