forked from paketo-buildpacks/go-mod-vendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
47 lines (37 loc) · 1.17 KB
/
build.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
package gomodvendor
import (
"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/scribe"
)
//go:generate faux --interface BuildProcess --output fakes/build_process.go
type BuildProcess interface {
ShouldRun(workingDir string) (ok bool, reason string, err error)
Execute(path, workingDir string) error
}
func Build(buildProcess BuildProcess, logs scribe.Emitter) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logs.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
ok, reason, err := buildProcess.ShouldRun(context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
if !ok {
logs.Process("Skipping build process: %s", reason)
logs.Break()
return packit.BuildResult{}, nil
}
modCacheLayer, err := context.Layers.Get("mod-cache")
if err != nil {
return packit.BuildResult{}, err
}
modCacheLayer.Cache = true
err = buildProcess.Execute(modCacheLayer.Path, context.WorkingDir)
if err != nil {
return packit.BuildResult{}, err
}
return packit.BuildResult{
Plan: context.Plan,
Layers: []packit.Layer{modCacheLayer},
}, nil
}
}