Skip to content

Commit

Permalink
feat: add ROOT_TASKFILE special variable (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 authored Jan 26, 2024
1 parent 6ebe2e7 commit 3ff8fdb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ There are some special variables that is available on the templating system:
| `CLI_ARGS` | Contain all extra arguments passed after `--` when calling Task through the CLI. |
| `CLI_FORCE` | A boolean containing whether the `--force` or `--force-all` flags were set. |
| `TASK` | The name of the current task. |
| `ROOT_DIR` | The absolute path of the root Taskfile. |
| `TASKFILE_DIR` | The absolute path of the included Taskfile. |
| `ROOT_TASKFILE` | The absolute path of the root Taskfile. |
| `ROOT_DIR` | The absolute path of the root Taskfile directory. |
| `TASKFILE_DIR` | The absolute path of the included Taskfile directory. |
| `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`. |
Expand Down
2 changes: 2 additions & 0 deletions internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type Compiler struct {
Dir string
Entrypoint string
UserWorkingDir string

TaskfileEnv *ast.Vars
Expand Down Expand Up @@ -214,6 +215,7 @@ func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {

return map[string]string{
"TASK": t.Task,
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
"ROOT_DIR": c.Dir,
"TASKFILE_DIR": taskfileDir,
"USER_WORKING_DIR": c.UserWorkingDir,
Expand Down
1 change: 1 addition & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (e *Executor) setupCompiler() error {

e.Compiler = &compiler.Compiler{
Dir: e.Dir,
Entrypoint: e.Entrypoint,
UserWorkingDir: e.UserWorkingDir,
TaskfileEnv: e.Taskfile.Env,
TaskfileVars: e.Taskfile.Vars,
Expand Down

0 comments on commit 3ff8fdb

Please sign in to comment.