-
Notifications
You must be signed in to change notification settings - Fork 3
/
detect.go
57 lines (49 loc) · 1.45 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
package dotnetcoresdk
import (
"fmt"
"os"
"github.com/Masterminds/semver"
"github.com/paketo-buildpacks/packit/v2"
)
//go:generate faux --interface BuildpackYMLParser --output fakes/buildpack_yml_parser.go
type BuildpackYMLParser interface {
Parse(workingDir string) (string, error)
}
func Detect(buildpackYMLParser BuildpackYMLParser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
plan := packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{
Name: "dotnet-sdk",
},
},
}
if frameworkVersion, ok := os.LookupEnv("BP_DOTNET_FRAMEWORK_VERSION"); ok {
frameworkSemver, err := semver.NewVersion(frameworkVersion)
if err != nil {
return packit.DetectResult{}, err
}
plan.Requires = append(plan.Requires, packit.BuildPlanRequirement{
Name: "dotnet-sdk",
Metadata: map[string]interface{}{
"version-source": "BP_DOTNET_FRAMEWORK_VERSION",
"version": fmt.Sprintf("%d.%d.*", frameworkSemver.Major(), frameworkSemver.Minor()),
},
})
}
version, err := buildpackYMLParser.Parse(context.WorkingDir)
if err != nil {
return packit.DetectResult{}, err
}
if version != "" {
plan.Requires = append(plan.Requires, packit.BuildPlanRequirement{
Name: "dotnet-sdk",
Metadata: map[string]interface{}{
"version": version,
"version-source": "buildpack.yml",
},
})
}
return packit.DetectResult{Plan: plan}, nil
}
}