1
0
mirror of https://github.com/go-task/task.git synced 2025-11-27 22:38:20 +02:00
This commit is contained in:
Valentin Maerten
2025-11-15 16:19:09 +01:00
parent f53ad3f36a
commit 5c8a387cd4
3 changed files with 26 additions and 7 deletions

15
https.yml Normal file
View File

@@ -0,0 +1,15 @@
# https://taskfile.dev
version: '3'
includes:
app:
taskfile: https://github.com/pbstck/taskfiles.git//taskfile/rust.yml?ref=main
vars:
GREETING: Hello, World!
tasks:
default:
cmds:
- echo "{{.GREETING}}"
silent: true

View File

@@ -152,7 +152,7 @@ func init() {
if experiments.RemoteTaskfiles.Enabled() {
pflag.BoolVar(&Download, "download", false, "Downloads a cached version of a remote Taskfile.")
pflag.BoolVar(&Offline, "offline", getConfig(config, func() *bool { return config.Remote.Offline }, false), "Forces Task to only use local or cached Taskfiles.")
pflag.DurationVar(&Timeout, "timeout", getConfig(config, func() *time.Duration { return config.Remote.Timeout }, time.Second*10), "Timeout for downloading remote Taskfiles.")
pflag.DurationVar(&Timeout, "timeout", getConfig(config, func() *time.Duration { return config.Remote.Timeout }, time.Minute*10), "Timeout for downloading remote Taskfiles.")
pflag.BoolVar(&ClearCache, "clear-cache", false, "Clear the remote cache.")
pflag.DurationVar(&CacheExpiryDuration, "expiry", getConfig(config, func() *time.Duration { return config.Remote.CacheExpiry }, 0), "Expiry duration for cached remote Taskfiles.")
}

View File

@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
giturls "github.com/chainguard-dev/git-urls"
"github.com/hashicorp/go-getter"
@@ -83,11 +84,15 @@ func (node *GitNode) buildURL() string {
}
func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
// Create temporary directory for git clone
tmpDir, err := os.MkdirTemp("", "task-git-*")
if err != nil {
return nil, fmt.Errorf("failed to create temp dir: %w", err)
}
return node.readWithGoGetter(ctx)
}
func (node *GitNode) readWithGoGetter(ctx context.Context) ([]byte, error) {
// IMPORTANT: Do NOT create tmpDir in advance!
// If the directory exists, go-getter will use update() instead of clone()
// which is 3x slower (git init + fetch --tags + pull instead of a simple clone)
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("task-git-getter-%d", time.Now().UnixNano()))
defer func() {
_ = os.RemoveAll(tmpDir)
}()
@@ -107,7 +112,6 @@ func (node *GitNode) ReadContext(ctx context.Context) ([]byte, error) {
}
// Build path to Taskfile in tmpdir
// If no path specified, use default Taskfile.yml
taskfilePath := node.path
if taskfilePath == "" {
taskfilePath = "Taskfile.yml"