From 787c1621b9a8860287f752e69a7079b29880f6bd Mon Sep 17 00:00:00 2001 From: jaynis Date: Fri, 7 Mar 2025 23:26:29 +0100 Subject: [PATCH] added TASK_WORKING_DIR variable Signed-off-by: jaynis --- cmd/task/task.go | 37 ++++++++++++------------ compiler.go | 2 ++ setup.go | 1 + task.go | 41 ++++++++++++++------------- website/docs/reference/templating.mdx | 3 +- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index afa8945eb5..b983473ed7 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -134,24 +134,25 @@ func run() error { } e := task.Executor{ - Dir: dir, - Entrypoint: entrypoint, - Force: flags.Force, - ForceAll: flags.ForceAll, - Insecure: flags.Insecure, - Download: flags.Download, - Offline: flags.Offline, - Timeout: flags.Timeout, - Watch: flags.Watch, - Verbose: flags.Verbose, - Silent: flags.Silent, - AssumeYes: flags.AssumeYes, - Dry: flags.Dry || flags.Status, - Summary: flags.Summary, - Parallel: flags.Parallel, - Color: flags.Color, - Concurrency: flags.Concurrency, - Interval: flags.Interval, + Dir: dir, + TaskWorkingDir: flags.Dir, + Entrypoint: entrypoint, + Force: flags.Force, + ForceAll: flags.ForceAll, + Insecure: flags.Insecure, + Download: flags.Download, + Offline: flags.Offline, + Timeout: flags.Timeout, + Watch: flags.Watch, + Verbose: flags.Verbose, + Silent: flags.Silent, + AssumeYes: flags.AssumeYes, + Dry: flags.Dry || flags.Status, + Summary: flags.Summary, + Parallel: flags.Parallel, + Color: flags.Color, + Concurrency: flags.Concurrency, + Interval: flags.Interval, Stdin: os.Stdin, Stdout: os.Stdout, diff --git a/compiler.go b/compiler.go index 1426db080a..c973c27fa7 100644 --- a/compiler.go +++ b/compiler.go @@ -22,6 +22,7 @@ type Compiler struct { Dir string Entrypoint string UserWorkingDir string + TaskWorkingDir string TaskfileEnv *ast.Vars TaskfileVars *ast.Vars @@ -202,6 +203,7 @@ func (c *Compiler) getSpecialVars(t *ast.Task, call *Call) (map[string]string, e "ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint), "ROOT_DIR": c.Dir, "USER_WORKING_DIR": c.UserWorkingDir, + "TASK_WORKING_DIR": filepathext.SmartJoin(c.UserWorkingDir, c.TaskWorkingDir), "TASK_VERSION": version.GetVersion(), } if t != nil { diff --git a/setup.go b/setup.go index b188e40f26..8ae954de27 100644 --- a/setup.go +++ b/setup.go @@ -201,6 +201,7 @@ func (e *Executor) setupCompiler() error { Dir: e.Dir, Entrypoint: e.Entrypoint, UserWorkingDir: e.UserWorkingDir, + TaskWorkingDir: e.TaskWorkingDir, TaskfileEnv: e.Taskfile.Env, TaskfileVars: e.Taskfile.Vars, Logger: e.Logger, diff --git a/task.go b/task.go index cf690c662a..fb67d4b3a5 100644 --- a/task.go +++ b/task.go @@ -43,26 +43,27 @@ type TempDir struct { type Executor struct { Taskfile *ast.Taskfile - Dir string - Entrypoint string - TempDir TempDir - Force bool - ForceAll bool - Insecure bool - Download bool - Offline bool - Timeout time.Duration - Watch bool - Verbose bool - Silent bool - AssumeYes bool - AssumeTerm bool // Used for testing - Dry bool - Summary bool - Parallel bool - Color bool - Concurrency int - Interval time.Duration + Dir string + TaskWorkingDir string + Entrypoint string + TempDir TempDir + Force bool + ForceAll bool + Insecure bool + Download bool + Offline bool + Timeout time.Duration + Watch bool + Verbose bool + Silent bool + AssumeYes bool + AssumeTerm bool // Used for testing + Dry bool + Summary bool + Parallel bool + Color bool + Concurrency int + Interval time.Duration Stdin io.Reader Stdout io.Writer diff --git a/website/docs/reference/templating.mdx b/website/docs/reference/templating.mdx index 98d45bae00..56d4d0e941 100644 --- a/website/docs/reference/templating.mdx +++ b/website/docs/reference/templating.mdx @@ -114,7 +114,8 @@ special variable will be overridden. | `ROOT_DIR` | The absolute path of the root Taskfile directory. | | `TASKFILE` | The absolute path of the included Taskfile. | | `TASKFILE_DIR` | The absolute path of the included Taskfile directory. | -| `TASK_DIR` | The absolute path of the directory where the task is executed. | +| `TASK_DIR` | The absolute path of the directory which has been configured on the task in the `Taskfile.yml`. | +| `TASK_WORKING_DIR` | The absolute path of the directory where the task is executed. | | `USER_WORKING_DIR` | The absolute path of the directory `task` was called from. | | `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. | | `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |