Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4834ac7
chore: changelog for #2166
pd93 Apr 19, 2025
7eebf6e
chore: delete unused exp package
pd93 Apr 19, 2025
672b394
feat: mockery v3 (#2110)
pd93 Apr 19, 2025
84cd4df
chore(deps): update all non-major dependencies (#2188)
renovate[bot] Apr 21, 2025
7169bf6
fix: interpolate vars in defer (#2173)
vmaerten Apr 21, 2025
0a6cd1e
chore: add changelog entry for #2173
andreynering Apr 21, 2025
c2123dc
v3.43.0
andreynering Apr 21, 2025
3976e83
chore: move the `experiments` package out of the `internal/` dir
andreynering Apr 21, 2025
3d36616
v3.43.1
andreynering Apr 21, 2025
bf4e796
chore: show right version on changelog
andreynering Apr 21, 2025
3970610
fix: CLI_ARGS is a string and not an array (#2191)
vmaerten Apr 21, 2025
0805692
chore: add changelog entry for #2191
andreynering Apr 21, 2025
6cb0a5a
v3.43.2
andreynering Apr 21, 2025
68d5095
Revert "fix: `.USER_WORKING_DIR` should contain the value of `--dir` …
pd93 Apr 27, 2025
8162b05
Revert "feat: process variables in include vars (#2113)"
pd93 Apr 27, 2025
bd8ccb8
chore: changelogs for reverts
pd93 Apr 27, 2025
20c1ffe
docs: update variables example so that it doesn't error
pd93 Apr 27, 2025
13daa6d
feat: formatting with golangci-lint and gci
pd93 Apr 27, 2025
1c35358
v3.43.3
pd93 Apr 27, 2025
a335441
fix: fuzzy model was not instanciated (#2200)
vmaerten Apr 27, 2025
9e8fd54
chore: changelog for #2200
pd93 Apr 27, 2025
b3c4007
fix: double escaped paths (#2216)
pd93 Apr 28, 2025
0058f18
chore: changelog for #2216
pd93 Apr 28, 2025
d850d03
feat: add yaml templating functions (#2219)
pd93 Apr 28, 2025
d3e9be1
chore: changelog for #2219
pd93 Apr 28, 2025
fc17343
chore(deps): update all non-major dependencies (#2214)
renovate[bot] Apr 28, 2025
d1bfd3e
docs: move yaml templating functions to the correct section
pd93 Apr 28, 2025
c12ed49
chore: remove unused any2 testdata
pd93 Apr 28, 2025
6896acc
feat: cli args list (#2140)
pd93 May 1, 2025
f8736c5
chore: changelog for #2140
pd93 May 1, 2025
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
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ formatters:
- gofmt
- gofumpt
- goimports
- gci
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any
Expand All @@ -15,6 +17,12 @@ formatters:
goimports:
local-prefixes:
- github.com/go-task
gci:
sections:
- standard
- default
- prefix(github.com/go-task)
- localmodule
exclusions:
generated: lax
paths:
Expand Down
12 changes: 8 additions & 4 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
with-expecter: true
keeptree: true
case: underscore
output: ./internal/mocks
all: False
template: testify
filename: '{{base (trimSuffix ".go" .InterfaceFile)}}_mock.go'
packages:
github.com/go-task/task/v3/internal/fingerprint:
interfaces:
SourcesCheckable:
StatusCheckable:
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.14.0
22.15.0
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

## Unreleased

- Added new `CLI_ARGS_LIST` array variable which contains the arguments passed
to Task after the `--` (the same as `CLI_ARGS`, but an array instead of a
string). (#2138, #2139, #2140 by @pd93).
- Added `toYaml` and `fromYaml` templating functions (#2217, #2219 by @pd93).
- Fixed fuzzy suggestions not working when misspelling a task name (#2192, #2200
by @vmaerten).
- Fixed a bug where taskfiles in directories containing spaces created
directories in the wrong location (#2208, #2216 by @pd93).

## v3.43.3 - 2025-04-27

Reverted the changes made in #2113 and #2186 that affected the
`USER_WORKING_DIR` and built-in variables. This fixes #2206, #2195, #2207 and
#2208.

## v3.43.2 - 2025-04-21

- Fixed regresion of `CLI_ARGS` being exposed as the wrong type (#2190, #2191 by
@vmaerten).

## v3.43.1 - 2025-04-21

- Significant improvements were made to the watcher. We migrated from
[watcher](https://github.com/radovskyb/watcher) to
[fsnotify](https://github.com/fsnotify/fsnotify). The former library used
Expand Down Expand Up @@ -30,6 +52,9 @@
- Added an `--expiry` flag which sets the TTL for a remote file cache. By
default the value will be 0 (caching disabled). If Task is running in
offline mode or fails to make a connection, it will fallback on the cache.
- `.taskrc` files can now be used from subdirectories and will be searched for
recursively up the file tree in the same way that Taskfiles are (#2159, #2166
by @pd93).
- The default taskfile (output when using the `--init` flag) is now an embedded
file in the binary instead of being stored in the code (#2112 by @pd93).
- Improved the way we report the Task version when using the `--version` flag or
Expand All @@ -46,6 +71,7 @@
- The `USER_WORKING_DIR` special now will now properly account for the `--dir`
(`-d`) flag, if given (#2102, #2103 by @jaynis, #2186 by @andreynering).
- Fix Fish completions when `--global` (`-g`) is given (#2134 by @atusy).
- Fixed variables not available when using `defer:` (#1909, #2173 by @vmaerten).

#### Package API

Expand Down
26 changes: 21 additions & 5 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,23 @@ tasks:
- go install -v ./cmd/task

generate:
desc: Runs Mockery to create mocks
aliases: [gen, g]
desc: Runs all generate tasks
cmds:
- task: generate:mocks
- task: generate:fixtures

generate:mocks:
desc: Runs Mockery to create mocks
aliases: [gen:mocks, g:mocks]
deps: [install:mockery]
sources:
- "internal/fingerprint/checker.go"
generates:
- "internal/mocks/*.go"
cmds:
- "{{.BIN}}/mockery --dir ./internal/fingerprint --name SourcesCheckable"
- "{{.BIN}}/mockery --dir ./internal/fingerprint --name StatusCheckable"
- find . -type f -name *_mock.go -delete
- "{{.BIN}}/mockery"

generate:fixtures:
desc: Runs tests and generates golden fixture files
Expand All @@ -53,13 +60,13 @@ tasks:
install:mockery:
desc: Installs mockgen; a tool to generate mock files
vars:
MOCKERY_VERSION: v2.24.0
MOCKERY_VERSION: v3.2.2
env:
GOBIN: "{{.BIN}}"
status:
- go version -m {{.BIN}}/mockery | grep github.com/vektra/mockery | grep {{.MOCKERY_VERSION}}
cmds:
- go install github.com/vektra/mockery/v2@{{.MOCKERY_VERSION}}
- GOBIN="{{.BIN}}" go install github.com/vektra/mockery/v3@{{.MOCKERY_VERSION}}

mod:
desc: Downloads and tidy Go modules
Expand Down Expand Up @@ -91,6 +98,15 @@ tasks:
cmds:
- golangci-lint run --fix

format:
desc: Runs golangci-lint and formats any Go files
aliases: [fmt, f]
sources:
- './**/*.go'
- .golangci.yml
cmds:
- golangci-lint fmt

sleepit:build:
desc: Builds the sleepit test helper
sources:
Expand Down
24 changes: 13 additions & 11 deletions args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ func Get() ([]string, []string, error) {
if doubleDashPos == -1 {
return args, nil, nil
}

var quotedCliArgs []string
for _, arg := range args[doubleDashPos:] {
quotedCliArg, err := syntax.Quote(arg, syntax.LangBash)
if err != nil {
return nil, nil, err
}
quotedCliArgs = append(quotedCliArgs, quotedCliArg)
}

return args[:doubleDashPos], quotedCliArgs, nil
return args[:doubleDashPos], args[doubleDashPos:], nil
}

// Parse parses command line argument: tasks and global variables
Expand All @@ -51,6 +41,18 @@ func Parse(args ...string) ([]*task.Call, *ast.Vars) {
return calls, globals
}

func ToQuotedString(args []string) (string, error) {
var quotedCliArgs []string
for _, arg := range args {
quotedCliArg, err := syntax.Quote(arg, syntax.LangBash)
if err != nil {
return "", err
}
quotedCliArgs = append(quotedCliArgs, quotedCliArg)
}
return strings.Join(quotedCliArgs, " "), nil
}

func splitVar(s string) (string, string) {
pair := strings.SplitN(s, "=", 2)
return pair[0], pair[1]
Expand Down
15 changes: 10 additions & 5 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/go-task/task/v3"
"github.com/go-task/task/v3/args"
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/experiments"
"github.com/go-task/task/v3/experiments"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/internal/flags"
"github.com/go-task/task/v3/internal/logger"
Expand Down Expand Up @@ -76,7 +76,7 @@ func run() error {
if err != nil {
return err
}
_, args, err := args.Get()
args, _, err := args.Get()
if err != nil {
return err
}
Expand Down Expand Up @@ -144,18 +144,23 @@ func run() error {
}

// Parse the remaining arguments
argv, cliArgs, err := args.Get()
cliArgsPreDash, cliArgsPostDash, err := args.Get()
if err != nil {
return err
}
calls, globals := args.Parse(argv...)
calls, globals := args.Parse(cliArgsPreDash...)

// If there are no calls, run the default task instead
if len(calls) == 0 {
calls = append(calls, &task.Call{Task: "default"})
}

globals.Set("CLI_ARGS", ast.Var{Value: cliArgs})
cliArgsPostDashQuoted, err := args.ToQuotedString(cliArgsPostDash)
if err != nil {
return err
}
globals.Set("CLI_ARGS", ast.Var{Value: cliArgsPostDashQuoted})
globals.Set("CLI_ARGS_LIST", ast.Var{Value: cliArgsPostDash})
globals.Set("CLI_FORCE", ast.Var{Value: flags.Force || flags.ForceAll})
globals.Set("CLI_SILENT", ast.Var{Value: flags.Silent})
globals.Set("CLI_VERBOSE", ast.Var{Value: flags.Verbose})
Expand Down
2 changes: 0 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io"
"os"
"path/filepath"
"sync"
"time"

Expand Down Expand Up @@ -123,7 +122,6 @@ type dirOption struct {
}

func (o *dirOption) ApplyToExecutor(e *Executor) {
e.UserWorkingDir, _ = filepath.Abs(o.dir)
e.Dir = o.dir
}

Expand Down
23 changes: 22 additions & 1 deletion executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/go-task/task/v3"
"github.com/go-task/task/v3/internal/experiments"
"github.com/go-task/task/v3/experiments"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/taskfile/ast"
)
Expand Down Expand Up @@ -937,3 +937,24 @@ func TestVarInheritance(t *testing.T) {
)
}
}

func TestFuzzyModel(t *testing.T) {
t.Parallel()

NewExecutorTest(t,
WithName("fuzzy"),
WithExecutorOptions(
task.WithDir("testdata/fuzzy"),
),
WithTask("instal"),
WithRunError(),
)

NewExecutorTest(t,
WithName("not-fuzzy"),
WithExecutorOptions(
task.WithDir("testdata/fuzzy"),
),
WithTask("install"),
)
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/go-task/task/v3/internal/experiments"
"github.com/go-task/task/v3/experiments"
"github.com/go-task/task/v3/taskrc/ast"
)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/go-task/task/v3"
"github.com/go-task/task/v3/internal/experiments"
"github.com/go-task/task/v3/experiments"
"github.com/go-task/task/v3/taskfile/ast"
)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.23.0
require (
github.com/Ladicle/tabwriter v1.0.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/alecthomas/chroma/v2 v2.16.0
github.com/alecthomas/chroma/v2 v2.17.0
github.com/chainguard-dev/git-urls v1.0.2
github.com/davecgh/go-spew v1.1.1
github.com/dominikbraun/graph v0.23.0
github.com/elliotchance/orderedmap/v3 v3.1.0
github.com/fatih/color v1.18.0
github.com/fsnotify/fsnotify v1.9.0
github.com/go-git/go-billy/v5 v5.6.2
github.com/go-git/go-git/v5 v5.15.0
github.com/go-git/go-git/v5 v5.16.0
github.com/go-task/slim-sprig/v3 v3.0.0
github.com/go-task/template v0.1.0
github.com/joho/godotenv v1.5.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/alecthomas/chroma/v2 v2.15.0 h1:LxXTQHFoYrstG2nnV9y2X5O94sOBzf0CIUpST
github.com/alecthomas/chroma/v2 v2.15.0/go.mod h1:gUhVLrPDXPtp/f+L1jo9xepo9gL4eLwRuGAunSZMkio=
github.com/alecthomas/chroma/v2 v2.16.0 h1:QC5ZMizk67+HzxFDjQ4ASjni5kWBTGiigRG1u23IGvA=
github.com/alecthomas/chroma/v2 v2.16.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk=
github.com/alecthomas/chroma/v2 v2.17.0 h1:3r2Cgk+nXNICMBxIFGnTRTbQFUwMiLisW+9uos0TtUI=
github.com/alecthomas/chroma/v2 v2.17.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
Expand Down Expand Up @@ -66,6 +68,8 @@ github.com/go-git/go-git/v5 v5.14.0 h1:/MD3lCrGjCen5WfEAzKg00MJJffKhC8gzS80ycmCi
github.com/go-git/go-git/v5 v5.14.0/go.mod h1:Z5Xhoia5PcWA3NF8vRLURn9E5FRhSl7dGj9ItW3Wk5k=
github.com/go-git/go-git/v5 v5.15.0 h1:f5Qn0W0F7ry1iN0ZwIU5m/n7/BKB4hiZfc+zlZx7ly0=
github.com/go-git/go-git/v5 v5.15.0/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
github.com/go-git/go-git/v5 v5.16.0 h1:k3kuOEpkc0DeY7xlL6NaaNg39xdgQbtH5mwCafHO9AQ=
github.com/go-git/go-git/v5 v5.16.0/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
Expand Down
2 changes: 1 addition & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"github.com/go-task/task/v3/internal/experiments"
"github.com/go-task/task/v3/experiments"
"github.com/go-task/task/v3/taskfile/ast"
)

Expand Down
22 changes: 2 additions & 20 deletions internal/execext/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,31 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
return r.Run(ctx, p)
}

func escape(s string) string {
s = filepath.ToSlash(s)
s = strings.ReplaceAll(s, " ", `\ `)
s = strings.ReplaceAll(s, "&", `\&`)
s = strings.ReplaceAll(s, "(", `\(`)
s = strings.ReplaceAll(s, ")", `\)`)
return s
}

// ExpandLiteral is a wrapper around [expand.Literal]. It will escape the input
// string, expand any shell symbols (such as '~') and resolve any environment
// variables.
func ExpandLiteral(s string) (string, error) {
if s == "" {
return "", nil
}
s = escape(s)
p := syntax.NewParser()
var words []*syntax.Word
err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {
words = append(words, w)
return true
})
word, err := p.Document(strings.NewReader(s))
if err != nil {
return "", err
}
if len(words) == 0 {
return "", nil
}
cfg := &expand.Config{
Env: expand.FuncEnviron(os.Getenv),
ReadDir2: os.ReadDir,
GlobStar: true,
}
return expand.Literal(cfg, words[0])
return expand.Literal(cfg, word)
}

// ExpandFields is a wrapper around [expand.Fields]. It will escape the input
// string, expand any shell symbols (such as '~') and resolve any environment
// variables. It also expands brace expressions ({a.b}) and globs (*/**) and
// returns the results as a list of strings.
func ExpandFields(s string) ([]string, error) {
s = escape(s)
p := syntax.NewParser()
var words []*syntax.Word
err := p.Words(strings.NewReader(s), func(w *syntax.Word) bool {
Expand Down
Loading