mirror of
https://github.com/go-task/task.git
synced 2025-03-03 14:52:13 +02:00
feat(remote): global tempDir when the path is absolute (#1661)
* feat(remote): global tempDir is the path is absolute * --wip-- [skip ci] * fix lint * rename checksum to fingerprint * chore: Empty-Commit to trigger CI * feat: add TASK_REMOTE_DIR * handle relative path for TASK_REMOTE_DIR * Remove unneedded extra blank lines Co-authored-by: Andrey Nering <andrey@nering.com.br> * add docs about TASK_REMOTE_DIR --------- Co-authored-by: Andrey Nering <andrey@nering.com.br>
This commit is contained in:
parent
b52d4e4f40
commit
830b745112
2
help.go
2
help.go
@ -190,7 +190,7 @@ func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Ta
|
|||||||
}
|
}
|
||||||
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
upToDate, err := fingerprint.IsTaskUpToDate(context.Background(), task,
|
||||||
fingerprint.WithMethod(method),
|
fingerprint.WithMethod(method),
|
||||||
fingerprint.WithTempDir(e.TempDir),
|
fingerprint.WithTempDir(e.TempDir.Fingerprint),
|
||||||
fingerprint.WithDry(e.Dry),
|
fingerprint.WithDry(e.Dry),
|
||||||
fingerprint.WithLogger(e.Logger),
|
fingerprint.WithLogger(e.Logger),
|
||||||
)
|
)
|
||||||
|
32
setup.go
32
setup.go
@ -69,7 +69,7 @@ func (e *Executor) readTaskfile(node taskfile.Node) error {
|
|||||||
e.Download,
|
e.Download,
|
||||||
e.Offline,
|
e.Offline,
|
||||||
e.Timeout,
|
e.Timeout,
|
||||||
e.TempDir,
|
e.TempDir.Remote,
|
||||||
e.Logger,
|
e.Logger,
|
||||||
)
|
)
|
||||||
graph, err := reader.Read()
|
graph, err := reader.Read()
|
||||||
@ -104,12 +104,15 @@ func (e *Executor) setupFuzzyModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) setupTempDir() error {
|
func (e *Executor) setupTempDir() error {
|
||||||
if e.TempDir != "" {
|
if e.TempDir != (TempDir{}) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getenv("TASK_TEMP_DIR") == "" {
|
if os.Getenv("TASK_TEMP_DIR") == "" {
|
||||||
e.TempDir = filepathext.SmartJoin(e.Dir, ".task")
|
e.TempDir = TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(e.Dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(e.Dir, ".task"),
|
||||||
|
}
|
||||||
} else if filepath.IsAbs(os.Getenv("TASK_TEMP_DIR")) || strings.HasPrefix(os.Getenv("TASK_TEMP_DIR"), "~") {
|
} else if filepath.IsAbs(os.Getenv("TASK_TEMP_DIR")) || strings.HasPrefix(os.Getenv("TASK_TEMP_DIR"), "~") {
|
||||||
tempDir, err := execext.Expand(os.Getenv("TASK_TEMP_DIR"))
|
tempDir, err := execext.Expand(os.Getenv("TASK_TEMP_DIR"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,9 +120,28 @@ func (e *Executor) setupTempDir() error {
|
|||||||
}
|
}
|
||||||
projectDir, _ := filepath.Abs(e.Dir)
|
projectDir, _ := filepath.Abs(e.Dir)
|
||||||
projectName := filepath.Base(projectDir)
|
projectName := filepath.Base(projectDir)
|
||||||
e.TempDir = filepathext.SmartJoin(tempDir, projectName)
|
e.TempDir = TempDir{
|
||||||
|
Remote: tempDir,
|
||||||
|
Fingerprint: filepathext.SmartJoin(tempDir, projectName),
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
e.TempDir = filepathext.SmartJoin(e.Dir, os.Getenv("TASK_TEMP_DIR"))
|
e.TempDir = TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(e.Dir, os.Getenv("TASK_TEMP_DIR")),
|
||||||
|
Fingerprint: filepathext.SmartJoin(e.Dir, os.Getenv("TASK_TEMP_DIR")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getenv("TASK_REMOTE_DIR") != "" {
|
||||||
|
if filepath.IsAbs(os.Getenv("TASK_TEMP_DIR")) || strings.HasPrefix(os.Getenv("TASK_TEMP_DIR"), "~") {
|
||||||
|
remoteTempDir, err := execext.Expand(filepathext.SmartJoin(e.Dir, ".task"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
e.TempDir.Remote = remoteTempDir
|
||||||
|
} else {
|
||||||
|
e.TempDir.Remote = filepathext.SmartJoin(e.Dir, ".task")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -27,7 +27,7 @@ func (e *Executor) Status(ctx context.Context, calls ...*ast.Call) error {
|
|||||||
// Check if the task is up-to-date
|
// Check if the task is up-to-date
|
||||||
isUpToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
isUpToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
||||||
fingerprint.WithMethod(method),
|
fingerprint.WithMethod(method),
|
||||||
fingerprint.WithTempDir(e.TempDir),
|
fingerprint.WithTempDir(e.TempDir.Fingerprint),
|
||||||
fingerprint.WithDry(e.Dry),
|
fingerprint.WithDry(e.Dry),
|
||||||
fingerprint.WithLogger(e.Logger),
|
fingerprint.WithLogger(e.Logger),
|
||||||
)
|
)
|
||||||
@ -46,7 +46,7 @@ func (e *Executor) statusOnError(t *ast.Task) error {
|
|||||||
if method == "" {
|
if method == "" {
|
||||||
method = e.Taskfile.Method
|
method = e.Taskfile.Method
|
||||||
}
|
}
|
||||||
checker, err := fingerprint.NewSourcesChecker(method, e.TempDir, e.Dry)
|
checker, err := fingerprint.NewSourcesChecker(method, e.TempDir.Fingerprint, e.Dry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
9
task.go
9
task.go
@ -34,13 +34,18 @@ const (
|
|||||||
MaximumTaskCall = 1000
|
MaximumTaskCall = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TempDir struct {
|
||||||
|
Remote string
|
||||||
|
Fingerprint string
|
||||||
|
}
|
||||||
|
|
||||||
// Executor executes a Taskfile
|
// Executor executes a Taskfile
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
Taskfile *ast.Taskfile
|
Taskfile *ast.Taskfile
|
||||||
|
|
||||||
Dir string
|
Dir string
|
||||||
Entrypoint string
|
Entrypoint string
|
||||||
TempDir string
|
TempDir TempDir
|
||||||
Force bool
|
Force bool
|
||||||
ForceAll bool
|
ForceAll bool
|
||||||
Insecure bool
|
Insecure bool
|
||||||
@ -212,7 +217,7 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error {
|
|||||||
|
|
||||||
upToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
upToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
||||||
fingerprint.WithMethod(method),
|
fingerprint.WithMethod(method),
|
||||||
fingerprint.WithTempDir(e.TempDir),
|
fingerprint.WithTempDir(e.TempDir.Fingerprint),
|
||||||
fingerprint.WithDry(e.Dry),
|
fingerprint.WithDry(e.Dry),
|
||||||
fingerprint.WithLogger(e.Logger),
|
fingerprint.WithLogger(e.Logger),
|
||||||
)
|
)
|
||||||
|
29
task_test.go
29
task_test.go
@ -63,7 +63,10 @@ func (fct fileContentTest) Run(t *testing.T) {
|
|||||||
|
|
||||||
e := &task.Executor{
|
e := &task.Executor{
|
||||||
Dir: fct.Dir,
|
Dir: fct.Dir,
|
||||||
TempDir: filepathext.SmartJoin(fct.Dir, ".task"),
|
TempDir: task.TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(fct.Dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(fct.Dir, ".task"),
|
||||||
|
},
|
||||||
Entrypoint: fct.Entrypoint,
|
Entrypoint: fct.Entrypoint,
|
||||||
Stdout: io.Discard,
|
Stdout: io.Discard,
|
||||||
Stderr: io.Discard,
|
Stderr: io.Discard,
|
||||||
@ -273,7 +276,10 @@ func TestStatus(t *testing.T) {
|
|||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
e := &task.Executor{
|
e := &task.Executor{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
TempDir: filepathext.SmartJoin(dir, ".task"),
|
TempDir: task.TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
},
|
||||||
Stdout: &buff,
|
Stdout: &buff,
|
||||||
Stderr: &buff,
|
Stderr: &buff,
|
||||||
Silent: true,
|
Silent: true,
|
||||||
@ -468,7 +474,10 @@ func TestStatusChecksum(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
tempdir := filepathext.SmartJoin(dir, ".task")
|
tempdir := task.TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
}
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
TempDir: tempdir,
|
TempDir: tempdir,
|
||||||
@ -485,7 +494,7 @@ func TestStatusChecksum(t *testing.T) {
|
|||||||
|
|
||||||
// Capture the modification time, so we can ensure the checksum file
|
// Capture the modification time, so we can ensure the checksum file
|
||||||
// is not regenerated when the hash hasn't changed.
|
// is not regenerated when the hash hasn't changed.
|
||||||
s, err := os.Stat(filepathext.SmartJoin(tempdir, "checksum/"+test.task))
|
s, err := os.Stat(filepathext.SmartJoin(tempdir.Fingerprint, "checksum/"+test.task))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
time := s.ModTime()
|
time := s.ModTime()
|
||||||
|
|
||||||
@ -493,7 +502,7 @@ func TestStatusChecksum(t *testing.T) {
|
|||||||
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.task}))
|
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.task}))
|
||||||
assert.Equal(t, `task: Task "`+test.task+`" is up to date`+"\n", buff.String())
|
assert.Equal(t, `task: Task "`+test.task+`" is up to date`+"\n", buff.String())
|
||||||
|
|
||||||
s, err = os.Stat(filepathext.SmartJoin(tempdir, "checksum/"+test.task))
|
s, err = os.Stat(filepathext.SmartJoin(tempdir.Fingerprint, "checksum/"+test.task))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, time, s.ModTime())
|
assert.Equal(t, time, s.ModTime())
|
||||||
})
|
})
|
||||||
@ -815,7 +824,10 @@ func TestStatusVariables(t *testing.T) {
|
|||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
TempDir: filepathext.SmartJoin(dir, ".task"),
|
TempDir: task.TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
},
|
||||||
Stdout: &buff,
|
Stdout: &buff,
|
||||||
Stderr: &buff,
|
Stderr: &buff,
|
||||||
Silent: false,
|
Silent: false,
|
||||||
@ -964,7 +976,10 @@ func TestDryChecksum(t *testing.T) {
|
|||||||
|
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
TempDir: filepathext.SmartJoin(dir, ".task"),
|
TempDir: task.TempDir{
|
||||||
|
Remote: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
Fingerprint: filepathext.SmartJoin(dir, ".task"),
|
||||||
|
},
|
||||||
Stdout: io.Discard,
|
Stdout: io.Discard,
|
||||||
Stderr: io.Discard,
|
Stderr: io.Discard,
|
||||||
Dry: true,
|
Dry: true,
|
||||||
|
@ -222,8 +222,8 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(origTask.Status) > 0 {
|
if len(origTask.Status) > 0 {
|
||||||
timestampChecker := fingerprint.NewTimestampChecker(e.TempDir, e.Dry)
|
timestampChecker := fingerprint.NewTimestampChecker(e.TempDir.Fingerprint, e.Dry)
|
||||||
checksumChecker := fingerprint.NewChecksumChecker(e.TempDir, e.Dry)
|
checksumChecker := fingerprint.NewChecksumChecker(e.TempDir.Fingerprint, e.Dry)
|
||||||
|
|
||||||
for _, checker := range []fingerprint.SourcesCheckable{timestampChecker, checksumChecker} {
|
for _, checker := range []fingerprint.SourcesCheckable{timestampChecker, checksumChecker} {
|
||||||
value, err := checker.Value(&new)
|
value, err := checker.Value(&new)
|
||||||
|
@ -112,6 +112,9 @@ and look for a cached copy instead. This timeout can be configured by setting
|
|||||||
the `--timeout` flag and specifying a duration. For example, `--timeout 5s` will
|
the `--timeout` flag and specifying a duration. For example, `--timeout 5s` will
|
||||||
set the timeout to 5 seconds.
|
set the timeout to 5 seconds.
|
||||||
|
|
||||||
|
By default, the cache is stored in the Task temp directory, represented by the `TASK_TEMP_DIR` [environment variable](../reference/environment.mdx)
|
||||||
|
You can override the location of the cache by setting the `TASK_REMOTE_DIR` environment variable. This way, you can share the cache between different projects.
|
||||||
|
|
||||||
{/* prettier-ignore-start */}
|
{/* prettier-ignore-start */}
|
||||||
[enabling-experiments]: ./experiments.mdx#enabling-experiments
|
[enabling-experiments]: ./experiments.mdx#enabling-experiments
|
||||||
[man-in-the-middle-attacks]: https://en.wikipedia.org/wiki/Man-in-the-middle_attack
|
[man-in-the-middle-attacks]: https://en.wikipedia.org/wiki/Man-in-the-middle_attack
|
||||||
|
@ -9,8 +9,9 @@ Task allows you to configure some behavior using environment variables. This
|
|||||||
page lists all the environment variables that Task supports.
|
page lists all the environment variables that Task supports.
|
||||||
|
|
||||||
| ENV | Default | Description |
|
| ENV | Default | Description |
|
||||||
| --------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
|
| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
| `TASK_TEMP_DIR` | `.task` | Location of the temp dir. Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||||
|
| `TASK_REMOTE_DIR` | `TASK_TEMP_DIR` | Location of the remote temp dir (used for caching). Can relative to the project like `tmp/task` or absolute like `/tmp/.task` or `~/.task`. |
|
||||||
| `FORCE_COLOR` | | Force color output usage. |
|
| `FORCE_COLOR` | | Force color output usage. |
|
||||||
|
|
||||||
## Custom Colors
|
## Custom Colors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user