Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: taskfile special variable #1523

Merged
merged 1 commit into from
Mar 3, 2024
Merged
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: 1 addition & 0 deletions docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ There are some special variables that is available on the templating system:
| `TASK` | The name of the current task. |
| `ROOT_TASKFILE` | The absolute path of the root Taskfile. |
| `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. |
| `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`. |
Expand Down
16 changes: 3 additions & 13 deletions internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strings"
"sync"

Expand Down Expand Up @@ -208,24 +209,13 @@ func (c *Compiler) ResetCache() {
}

func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {
taskfileDir, err := c.getTaskfileDir(t)
if err != nil {
return nil, err
}

return map[string]string{
"TASK": t.Task,
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
"ROOT_DIR": c.Dir,
"TASKFILE_DIR": taskfileDir,
"TASKFILE": t.Location.Taskfile,
"TASKFILE_DIR": filepath.Dir(t.Location.Taskfile),
"USER_WORKING_DIR": c.UserWorkingDir,
"TASK_VERSION": version.GetVersion(),
}, nil
}

func (c *Compiler) getTaskfileDir(t *ast.Task) (string, error) {
if t.IncludedTaskfile != nil {
return t.IncludedTaskfile.FullDirPath()
}
return c.Dir, nil
}
2 changes: 0 additions & 2 deletions taskfile/ast/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Task struct {
Run string
IncludeVars *Vars
IncludedTaskfileVars *Vars
IncludedTaskfile *Include
Platforms []*Platform
Location *Location
Watch bool
Expand Down Expand Up @@ -207,7 +206,6 @@ func (t *Task) DeepCopy() *Task {
Run: t.Run,
IncludeVars: t.IncludeVars.DeepCopy(),
IncludedTaskfileVars: t.IncludedTaskfileVars.DeepCopy(),
IncludedTaskfile: t.IncludedTaskfile.DeepCopy(),
Platforms: deepcopy.Slice(t.Platforms),
Location: t.Location.DeepCopy(),
Requires: t.Requires.DeepCopy(),
Expand Down
1 change: 0 additions & 1 deletion taskfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func Read(
}
task.IncludeVars.Merge(include.Vars)
task.IncludedTaskfileVars = includedTaskfile.Vars
task.IncludedTaskfile = &include
}
}

Expand Down
Loading