mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	feat: taskfile special variable (#1523)
This commit is contained in:
		| @@ -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`.                               | | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"path/filepath" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
|  | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -40,7 +40,6 @@ type Task struct { | ||||
| 	Run                  string | ||||
| 	IncludeVars          *Vars | ||||
| 	IncludedTaskfileVars *Vars | ||||
| 	IncludedTaskfile     *Include | ||||
| 	Platforms            []*Platform | ||||
| 	Location             *Location | ||||
| 	Watch                bool | ||||
| @@ -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(), | ||||
|   | ||||
| @@ -136,7 +136,6 @@ func Read( | ||||
| 					} | ||||
| 					task.IncludeVars.Merge(include.Vars) | ||||
| 					task.IncludedTaskfileVars = includedTaskfile.Vars | ||||
| 					task.IncludedTaskfile = &include | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user