-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
62 lines (53 loc) · 1.5 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
57
58
59
60
61
62
package gobuild
import (
"fmt"
"os"
"strconv"
"github.com/paketo-buildpacks/packit/v2"
)
//go:generate faux --interface ConfigurationParser --output fakes/configuration_parser.go
type ConfigurationParser interface {
Parse(buildpackVersion, workingDir string) (BuildConfiguration, error)
}
func Detect(parser ConfigurationParser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
if _, err := parser.Parse(context.BuildpackInfo.Version, context.WorkingDir); err != nil {
return packit.DetectResult{}, packit.Fail.WithMessage("failed to parse build configuration: %w", err)
}
requirements := []packit.BuildPlanRequirement{
{
Name: "go",
Metadata: map[string]interface{}{
"build": true,
},
},
}
shouldEnableReload, err := checkLiveReloadEnabled()
if err != nil {
return packit.DetectResult{}, err
}
if shouldEnableReload {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: "watchexec",
Metadata: map[string]interface{}{
"launch": true,
},
})
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Requires: requirements,
},
}, nil
}
}
func checkLiveReloadEnabled() (bool, error) {
if reload, ok := os.LookupEnv("BP_LIVE_RELOAD_ENABLED"); ok {
shouldEnableReload, err := strconv.ParseBool(reload)
if err != nil {
return false, fmt.Errorf("failed to parse BP_LIVE_RELOAD_ENABLED value %s: %w", reload, err)
}
return shouldEnableReload, nil
}
return false, nil
}