-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fingreprinting): add .taskignore
- Loading branch information
1 parent
c28eb20
commit 9102660
Showing
9 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package taskfile | ||
|
||
import ( | ||
"context" | ||
"path" | ||
"strings" | ||
"time" | ||
|
||
"github.com/go-task/task/v3/internal/logger" | ||
"github.com/go-task/task/v3/taskfile/ast" | ||
) | ||
|
||
const taskignore = ".taskignore" | ||
|
||
func GetTasksWithSources(t *ast.Taskfile) []*ast.Task { | ||
var tasksWithSources []*ast.Task | ||
|
||
for _, task := range t.Tasks.Values() { | ||
if len(task.Sources) > 0 { | ||
tasksWithSources = append(tasksWithSources, task) | ||
} | ||
} | ||
|
||
return tasksWithSources | ||
} | ||
|
||
func ReadTaskignore(l *logger.Logger, dir string, timeout time.Duration) []string { | ||
bytes := read(l, dir, timeout) | ||
globs := filterGlobs(bytes) | ||
|
||
return globs | ||
} | ||
|
||
func read(l *logger.Logger, dir string, timeout time.Duration) []byte { | ||
fileNode, err := NewFileNode(l, "", path.Join(dir, taskignore)) | ||
|
||
if err != nil { | ||
return nil | ||
} | ||
|
||
ctx, cf := context.WithTimeout(context.Background(), timeout) | ||
defer cf() | ||
|
||
bytes, err := fileNode.Read(ctx) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return bytes | ||
} | ||
|
||
func filterGlobs(bytes []byte) []string { | ||
if len(bytes) == 0 { | ||
return nil | ||
} | ||
|
||
lines := strings.Split(string(bytes), "\n") | ||
var validGlobs []string | ||
|
||
for _, line := range lines { | ||
trimmed := strings.TrimSpace(line) | ||
if trimmed != "" && !strings.HasPrefix(trimmed, "#") { | ||
validGlobs = append(validGlobs, trimmed) | ||
} | ||
} | ||
|
||
return validGlobs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./**/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3' | ||
|
||
tasks: | ||
txt: | ||
desc: Echo file names | ||
sources: | ||
- ./nested/ignore_me_too.json | ||
- ./ignore_me.json | ||
- ./dont_ignore.txt | ||
cmds: | ||
- for: sources | ||
cmd: echo {{.ITEM}} |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters