Skip to content

Commit

Permalink
Allow auto detect with key (#40)
Browse files Browse the repository at this point in the history
* test

* Cache Intel: support bazel and node

* Cache Intel: support bazel and node

* Cache Intel: support bazel and node

* ignore linter error

* ignore linter error

* allow autodectect with key

* allow autodectect with key
  • Loading branch information
jamie-harness authored Feb 10, 2023
1 parent a88806a commit 415a22c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,39 @@ func (p *Plugin) Exec() error { // nolint:funlen
var generator key.Generator

switch {
case cfg.CacheKeyTemplate != "":
{
generator = keygen.NewMetadata(p.logger, cfg.CacheKeyTemplate, p.Metadata)
if err := generator.Check(); err != nil {
return fmt.Errorf("parse failed, falling back to default, %w", err)
}

options = append(options, cache.WithFallbackGenerator(keygen.NewHash(p.Metadata.Commit.Branch)))
}
case cfg.AutoDetect:
{
dirs, buildTools, hash, err := autodetect.DetectDirectoriesToCache()
dirs, buildTools, cacheKey, err := autodetect.DetectDirectoriesToCache()
if err != nil {
return fmt.Errorf("autodetect enabled but failed to detect, falling back to default, %w", err)
}
p.logger.Log("msg", "build tools detected: "+strings.Join(buildTools, ", "))
if len(buildTools) > 0 {
p.logger.Log("msg", "build tools detected: "+strings.Join(buildTools, ", ")) //nolint: errcheck
} else {
p.logger.Log("msg", "no supported build tool detected") //nolint: errcheck
}
if len(p.Config.Mount) == 0 {
p.Config.Mount = dirs
}
generator = keygen.NewMetadata(p.logger, cfg.AccountID+"/"+hash, p.Metadata)
if cfg.CacheKeyTemplate != "" {
cacheKey = cfg.CacheKeyTemplate
} else if cacheKey == "" {
cacheKey = "default"
}
generator = keygen.NewMetadata(p.logger, cfg.AccountID+"/"+cacheKey, p.Metadata)
if err := generator.Check(); err != nil {
return fmt.Errorf("parse failed, falling back to default, %w", err)
}

options = append(options, cache.WithFallbackGenerator(keygen.NewHash(cfg.AccountID+p.Metadata.Commit.Branch)))
}
case cfg.CacheKeyTemplate != "":
generator = keygen.NewMetadata(p.logger, cfg.CacheKeyTemplate, p.Metadata)
if err := generator.Check(); err != nil {
return fmt.Errorf("parse failed, falling back to default, %w", err)
}

options = append(options, cache.WithFallbackGenerator(keygen.NewHash(p.Metadata.Commit.Branch)))
default:
{
generator = keygen.NewHash(p.Metadata.Commit.Branch)
Expand Down

0 comments on commit 415a22c

Please sign in to comment.