github.com/octohelm/wagon@v0.0.0-20240308040401-88662650dc0b/pkg/engine/plan/task/fs_source.go (about) 1 package task 2 3 import ( 4 "dagger.io/dagger" 5 "fmt" 6 "github.com/octohelm/wagon/pkg/engine/daggerutil" 7 "github.com/octohelm/wagon/pkg/engine/plan" 8 "github.com/octohelm/wagon/pkg/engine/plan/task/core" 9 "github.com/octohelm/wagon/pkg/fsutil" 10 "github.com/octohelm/wagon/pkg/version/gomod" 11 "golang.org/x/net/context" 12 "time" 13 ) 14 15 func init() { 16 core.DefaultFactory.Register(&Source{}) 17 } 18 19 type Source struct { 20 core.Task 21 22 Path string `json:"path" default:"."` 23 Include []string `json:"include"` 24 Exclude []string `json:"exclude"` 25 26 Output core.FS `json:"-" wagon:"generated,name=output"` 27 } 28 29 func (s *Source) Do(ctx context.Context) error { 30 return daggerutil.Do(ctx, func(c *dagger.Client) error { 31 fs := plan.WorkdirFor(ctx, plan.WorkdirProject, s.Path) 32 33 p, err := fsutil.RealPath(fs) 34 if err != nil { 35 return err 36 } 37 38 cacheHitsFile := fmt.Sprintf(".fake-cache-hits-%d", time.Now().Unix()) 39 40 if version, _ := gomod.LocalRevInfo(p); version != nil { 41 cacheHitsFile = cacheHitsFile + "-" + version.Version 42 } 43 44 hostDir := c.Host().Directory(p, dagger.HostDirectoryOpts{ 45 Include: s.Include, 46 Exclude: append( 47 s.Exclude, 48 cacheHitsFile, 49 ), 50 }) 51 52 return s.Output.SetDirectoryIDBy(ctx, hostDir) 53 }) 54 }