-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
56 lines (49 loc) · 1.16 KB
/
detect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package sidekiq
import (
"fmt"
"path/filepath"
"github.com/paketo-buildpacks/packit"
)
//go:generate faux --interface Parser --output fakes/parser.go
type Parser interface {
Parse(path string, gemName string) (hasSidekiq bool, err error)
}
type BuildPlanMetadata struct {
Launch bool `toml:"launch"`
}
func Detect(gemfileParser Parser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
hasSidekiq, err := gemfileParser.Parse(filepath.Join(context.WorkingDir, "Gemfile"), "sidekiq")
if err != nil {
return packit.DetectResult{}, fmt.Errorf("failed to parse Gemfile: %w", err)
}
if !hasSidekiq {
return packit.DetectResult{}, packit.Fail
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{},
Requires: []packit.BuildPlanRequirement{
{
Name: "gems",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
{
Name: "bundler",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
{
Name: "mri",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
},
},
}, nil
}
}