forked from paketo-buildpacks/dep-ensure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
43 lines (38 loc) · 963 Bytes
/
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
package depensure
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
)
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
_, err := os.Stat(filepath.Join(context.WorkingDir, "Gopkg.toml"))
if err != nil {
if os.IsNotExist(err) {
return packit.DetectResult{}, packit.Fail
}
return packit.DetectResult{}, fmt.Errorf("failed to stat Gopkg.toml: %w", err)
}
_, err = os.Stat(filepath.Join(context.WorkingDir, "vendor"))
if err == nil {
return packit.DetectResult{}, packit.Fail
} else {
if !os.IsNotExist(err) {
return packit.DetectResult{}, fmt.Errorf("failed to stat vendor directory: %w", err)
}
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Requires: []packit.BuildPlanRequirement{
{
Name: "dep",
Metadata: map[string]interface{}{
"build": true,
},
},
},
},
}, nil
}
}