-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
120 lines (103 loc) · 3.28 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"fmt"
"os"
"github.com/bitrise-io/go-steputils/v2/ruby"
"github.com/bitrise-io/go-steputils/v2/stepconf"
"github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/env"
"github.com/bitrise-io/go-utils/v2/errorutil"
. "github.com/bitrise-io/go-utils/v2/exitcode"
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/pathutil"
)
func main() {
exitCode := run()
os.Exit(int(exitCode))
}
func run() ExitCode {
logger := log.NewLogger()
buildStep := createStep(logger)
config, err := buildStep.ProcessConfig()
if err != nil {
buildStep.logger.Println()
buildStep.logger.Errorf(errorutil.FormattedError(fmt.Errorf("Failed to process Step inputs: %w", err)))
return Failure
}
dependenciesOpts := EnsureDependenciesOpts{
GemVersions: config.GemVersions,
UseBundler: config.GemVersions.fastlane.Found,
WorkDir: config.WorkDir,
UpdateFastlane: config.UpdateFastlane,
}
if err := buildStep.InstallDependencies(dependenciesOpts); err != nil {
buildStep.logger.Println()
buildStep.logger.Errorf(errorutil.FormattedError(fmt.Errorf("Failed to install Step dependencies: %w", err)))
return Failure
}
runOpts := createRunOptions(config)
if err := buildStep.Run(runOpts); err != nil {
buildStep.logger.Println()
logger.Errorf(errorutil.FormattedError(fmt.Errorf("Failed to execute Step: %w", err)))
return Failure
}
buildStep.tracker.wait()
return Success
}
func createStep(logger log.Logger) FastlaneRunner {
envRepository := env.NewRepository()
inputParser := stepconf.NewInputParser(envRepository)
cmdFactory := command.NewFactory(envRepository)
cmdLocator := env.NewCommandLocator()
rbyFactory, err := ruby.NewCommandFactory(cmdFactory, cmdLocator)
if err != nil {
logger.Warnf("%s", err)
}
rubyEnv := ruby.NewEnvironment(rbyFactory, cmdLocator, logger)
pathModifier := pathutil.NewPathModifier()
tracker := newStepTracker(envRepository, logger)
return NewFastlaneRunner(inputParser, logger, cmdLocator, cmdFactory, rbyFactory, rubyEnv, pathModifier, tracker)
}
// FastlaneRunner ...
type FastlaneRunner struct {
inputParser stepconf.InputParser
logger log.Logger
cmdFactory command.Factory
cmdLocator env.CommandLocator
rbyFactory ruby.CommandFactory
rubyEnvironment ruby.Environment
pathModifier pathutil.PathModifier
tracker stepTracker
}
// NewFastlaneRunner ...
func NewFastlaneRunner(
stepInputParser stepconf.InputParser,
logger log.Logger,
commandLocator env.CommandLocator,
cmdFactory command.Factory,
rbyFactory ruby.CommandFactory,
rubyEnvironment ruby.Environment,
pathModifier pathutil.PathModifier,
tracker stepTracker,
) FastlaneRunner {
return FastlaneRunner{
inputParser: stepInputParser,
logger: logger,
cmdLocator: commandLocator,
cmdFactory: cmdFactory,
rbyFactory: rbyFactory,
rubyEnvironment: rubyEnvironment,
pathModifier: pathModifier,
tracker: tracker,
}
}
func createRunOptions(config Config) RunOpts {
return RunOpts{
WorkDir: config.WorkDir,
AuthCredentials: config.AuthCredentials,
LaneOptions: config.LaneOptions,
UseBundler: config.GemVersions.fastlane.Found,
GemVersions: config.GemVersions,
EnableCache: config.EnableCache,
}
}