forked from paketo-buildpacks/go-dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
49 lines (42 loc) · 1.23 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
package godist
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/fs"
)
type BuildPlanMetadata struct {
VersionSource string `toml:"version-source"`
Build bool `toml:"build"`
Version string `toml:"version"`
}
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
bpYML, err := fs.Exists(filepath.Join(context.WorkingDir, "buildpack.yml"))
if err != nil {
return packit.DetectResult{}, fmt.Errorf("failed to check for buildpack.yml: %w", err)
}
if bpYML {
return packit.DetectResult{}, fmt.Errorf("working directory contains deprecated 'buildpack.yml'; use environment variables for configuration")
}
var requirements []packit.BuildPlanRequirement
if version, ok := os.LookupEnv("BP_GO_VERSION"); ok {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: GoDependency,
Metadata: BuildPlanMetadata{
VersionSource: "BP_GO_VERSION",
Version: version,
},
})
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: GoDependency},
},
Requires: requirements,
},
}, nil
}
}