-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
53 lines (44 loc) · 1.21 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
48
49
50
51
52
53
package rake
import (
"fmt"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/scribe"
)
//go:generate faux --interface Parser --output fakes/parser.go
type Parser interface {
Parse(path string) (hasRakeGem bool, err error)
}
func Build(gemfileParser Parser, logger scribe.Emitter) packit.BuildFunc {
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
logger.Debug.Process("Checking Gemfile for rake")
hasRakeGem, err := gemfileParser.Parse(filepath.Join(context.WorkingDir, "Gemfile"))
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to parse Gemfile: %w", err)
}
command := "rake"
var args []string
if hasRakeGem {
logger.Debug.Subprocess("Gemfile contains rake gem")
command = "bundle"
args = []string{"exec rake"}
}
logger.Debug.Break()
processes := []packit.Process{
{
Type: "web",
Command: command,
Args: args,
Default: true,
Direct: true,
},
}
logger.LaunchProcesses(processes)
return packit.BuildResult{
Launch: packit.LaunchMetadata{
Processes: processes,
},
}, nil
}
}