-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdependencies.go
169 lines (143 loc) · 4.47 KB
/
dependencies.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"os"
"strings"
"github.com/bitrise-io/go-steputils/v2/ruby"
"github.com/bitrise-io/go-utils/v2/command"
)
// EnsureDependenciesOpts ...
type EnsureDependenciesOpts struct {
GemVersions gemVersions
UseBundler bool
WorkDir string
UpdateFastlane bool
}
// InstallDependencies ...
func (f FastlaneRunner) InstallDependencies(opts EnsureDependenciesOpts) error {
f.reportRubyVersion(opts.UseBundler, opts.GemVersions.bundler.Version, opts.WorkDir)
// Install desired Fastlane version
if opts.UseBundler {
f.logger.Println()
f.logger.Infof("Install bundler")
// install bundler with `gem install bundler [-v version]`
// in some configurations, the command "bundler _1.2.3_" can return 'Command not found', installing bundler solves this
cmds := f.rbyFactory.CreateGemInstall("bundler", opts.GemVersions.bundler.Version, false, true, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: opts.WorkDir,
})
for _, cmd := range cmds {
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
f.logger.Println()
if err := cmd.Run(); err != nil {
return err
}
}
// install Gemfile.lock gems with `bundle [_version_] install ...`
f.logger.Println()
f.logger.Infof("Install Fastlane with bundler")
cmd := f.rbyFactory.CreateBundleInstall(opts.GemVersions.bundler.Version, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: opts.WorkDir,
})
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
f.logger.Println()
if err := cmd.Run(); err != nil {
return err
}
} else if opts.UpdateFastlane {
f.logger.Println()
f.logger.Infof("Update system installed Fastlane")
cmds := f.rbyFactory.CreateGemInstall("fastlane", "", false, false, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: opts.WorkDir,
})
for _, cmd := range cmds {
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
return err
}
}
} else {
f.logger.Println()
f.logger.Infof("Using system installed Fastlane")
}
f.logger.Println()
f.logger.Infof("Fastlane version")
name := "fastlane"
args := []string{"--version"}
options := &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: opts.WorkDir,
}
var cmd command.Command
if opts.UseBundler {
cmd = f.rbyFactory.CreateBundleExec(name, args, opts.GemVersions.bundler.Version, options)
} else {
cmd = f.rbyFactory.Create(name, args, options)
}
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func (f FastlaneRunner) reportRubyVersion(useBundler bool, bundlerVersion string, workDir string) {
if f.rubyEnvironment.RubyInstallType() == ruby.ASDFRuby {
f.logger.Println()
f.logger.Infof("Checking selected Ruby version")
cmd := f.rbyFactory.Create("asdf", []string{"current", "ruby"}, &command.Opts{
Stderr: os.Stderr,
Stdout: os.Stdout,
Dir: workDir,
})
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
f.logger.Warnf("Failed to print selected Ruby version: %s", err)
}
} else if f.rubyEnvironment.RubyInstallType() == ruby.RbenvRuby {
f.logger.Println()
f.logger.Infof("Checking selected Ruby version")
if _, err := f.cmdLocator.LookPath("rbenv"); err == nil {
cmd := f.rbyFactory.Create("rbenv", []string{"versions"}, &command.Opts{
Stderr: os.Stderr,
Stdout: os.Stdout,
Dir: workDir,
})
f.logger.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
f.logger.Warnf(err.Error())
}
} else {
f.logger.Warnf("rbenv not found: %s", err)
}
}
var versionCmd command.Command
options := &command.Opts{
Dir: workDir,
}
if useBundler {
versionCmd = f.rbyFactory.CreateBundleExec("ruby", []string{"--version"}, bundlerVersion, options)
} else {
versionCmd = f.rbyFactory.Create("ruby", []string{"--version"}, options)
}
output, err := versionCmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
f.logger.Warnf("Failed to check active Ruby version: %s", err)
f.logger.Printf("Output: %s", output)
return
}
// Example output:
// ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin22]
versionSlice := strings.Split(output, " ")
if len(versionSlice) < 2 || versionSlice[0] != "ruby" {
f.logger.Warnf("Unrecognized Ruby version: %s", versionSlice)
}
version := versionSlice[1]
f.logger.Println()
f.logger.Infof("Active Ruby version: %s", version)
f.tracker.logEffectiveRubyVersion(version)
}