Skip to content

Commit

Permalink
Migrate to the new go-steputils/ruby package. (#84)
Browse files Browse the repository at this point in the history
* Migrate to the new ruby package.

* Update to latest go-steputils.

* Update go-android package.

* Typo fix.

* Update to the master version of go-utils and go-steputils.
  • Loading branch information
godrei authored Sep 27, 2021
1 parent 8f26073 commit cb6dc87
Show file tree
Hide file tree
Showing 36 changed files with 1,207 additions and 1,168 deletions.
4 changes: 3 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/bitrise-io/bitrise-init/scanners/android"
androidCache "github.com/bitrise-io/go-android/cache"
"github.com/bitrise-io/go-steputils/cache"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/env"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
)
Expand Down Expand Up @@ -79,7 +81,7 @@ func androidDeps(dir string) ([]string, []string, error) {
var include []string
var exclude []string
for _, dir := range scanner.ProjectRoots {
i, e, err := androidCache.NewAndroidGradleCacheItemCollector().Collect(dir, cache.LevelDeps)
i, e, err := androidCache.NewAndroidGradleCacheItemCollector(command.NewFactory(env.NewRepository())).Collect(dir, cache.LevelDeps)
if err != nil {
return nil, nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.12

require (
github.com/bitrise-io/bitrise-init v0.0.0-20210520122036-d213de321eb8
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5
github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d
github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892
github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d
github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
)
21 changes: 15 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ github.com/bitrise-io/colorstring v0.0.0-20180614154802-a8cd70115192/go.mod h1:C
github.com/bitrise-io/envman v0.0.0-20200512105748-919e33f391ee/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI=
github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5 h1:3jVXjsejV+1EW9Sp7ef+sMinD0J3HFsPgh4Du6ctqZc=
github.com/bitrise-io/envman v0.0.0-20210517135508-b2b4fe89eac5/go.mod h1:m8pTp1o3Sw9uzDxb1WRm5IBRnMau2iOvPMSnRCAhQNI=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e h1:lkJnz+yXbIqFGpDTdRBBshqxeX0UCndJmEOp0yy2GRQ=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e/go.mod h1:gGXmY8hJ1x44AC98TIvZZvxP7o+hs4VI6wgmO4JMfEg=
github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d h1:F4VCaMk4hZZSwI5MiyBwVnkxmgmvkOz4+uXAacEaRC0=
github.com/bitrise-io/go-android v0.0.0-20210913151943-e1ea0b4df36d/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc=
github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10/go.mod h1:pARutiL3kEuRLV3JvswidvfCj+9Y3qMZtji2BDqLFsA=
github.com/bitrise-io/go-steputils v0.0.0-20210507072936-92fde382fb33/go.mod h1:YCtb1VETn/rF9tCt9oInhd/cwbt1ETPm+dTlDIfyD+A=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1 h1:gi29hTdxGXAGQvZckPZ9V8BAEfP3eK/tiZgTC5s6h1c=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210819160244-b3962254d553/go.mod h1:gPr5wQVOi3wZCY1RkMzk/Ij0rmdgEIP0Og84YgHmVSU=
github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892 h1:aD5jTvdf5zIngQ5HeR7Idteae4yaXLqJGn8PE4k2xtI=
github.com/bitrise-io/go-steputils v0.0.0-20210924114124-851d30b88892/go.mod h1:6Y7Dl40gwgW9YG1RAWcjFBk1u9uotuix8g2IkVTXK34=
github.com/bitrise-io/go-utils v0.0.0-20210505091801-98b7dc39ee61/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA=
github.com/bitrise-io/go-utils v0.0.0-20210505121718-07411d72e36e/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA=
github.com/bitrise-io/go-utils v0.0.0-20210506064210-b22e2b7b3ad3/go.mod h1:nhdaDQFvaMny1CugVV6KjK92/q97ENo0RuKSW5I4fbA=
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce/go.mod h1:15EZZf02noI5nWFqXMZEoyb1CyqYRXTMz5Fyu4CWFzI=
github.com/bitrise-io/go-utils v0.0.0-20210514083430-4d1fb0330dfe/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5 h1:kclxBfygfNK6kWUB+9xcsfPLBen8Us9gubhitfL/Z6c=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ=
github.com/bitrise-io/go-utils v0.0.0-20210819105546-07a5bda18d68/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI=
github.com/bitrise-io/go-utils v0.0.0-20210819143908-bbd923881fab/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI=
github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d h1:jU5wvShTLKSo2gYlIBoXONS2MRRL8UwiPOSqi88JF2k=
github.com/bitrise-io/go-utils v0.0.0-20210924090918-3e7a04d0da9d/go.mod h1:Vi4MHnaZVL3PVoPPA/Yp6g2pzntkDH8LGiRSY7qw6KQ=
github.com/bitrise-io/go-xcode v0.0.0-20210520114025-bdbec53ee59f/go.mod h1:a5IANtAnyazHgNjI6/kwQw5vU/WJo1zQ4Lja9WRUNmA=
github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b h1:JyTlzvdOBOxtYZ7aZVCog2dZUv8LgA8UftT+TpVWtZY=
github.com/bitrise-io/go-xcode v0.0.0-20210521101355-fb6a1eb6e05b/go.mod h1:6Nv5RAsAVS745xN5IihUExVmCA9n9f7s/DSVow4hXrI=
Expand All @@ -45,8 +49,9 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
Expand Down Expand Up @@ -85,6 +90,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -95,8 +101,11 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210819072135-bce67f096156/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
153 changes: 84 additions & 69 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (

"github.com/bitrise-io/go-steputils/cache"
"github.com/bitrise-io/go-steputils/command/gems"
"github.com/bitrise-io/go-steputils/command/rubycommand"
"github.com/bitrise-io/go-steputils/ruby"
"github.com/bitrise-io/go-steputils/stepconf"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/env"
"github.com/bitrise-io/go-utils/errorutil"
"github.com/bitrise-io/go-utils/fileutil"
"github.com/bitrise-io/go-utils/log"
Expand Down Expand Up @@ -78,20 +79,26 @@ func failf(format string, v ...interface{}) {
}

func fastlaneDebugInfo(workDir string, useBundler bool, bundlerVersion gems.Version) (string, error) {
envCmd := []string{"fastlane", "env"}
if useBundler {
envCmd = append(gems.BundleExecPrefix(bundlerVersion), envCmd...)
}

cmd, err := rubycommand.NewFromSlice(envCmd)
factory, err := ruby.NewCommandFactory(command.NewFactory(env.NewRepository()), env.NewCommandLocator())
if err != nil {
return "", fmt.Errorf("failed to create command model, error: %s", err)
return "", err
}

name := "fastlane"
args := []string{"env"}
var outBuffer bytes.Buffer
cmd.SetStdin(strings.NewReader("n"))
cmd.SetStdout(bufio.NewWriter(&outBuffer)).SetStderr(os.Stderr)
cmd.SetDir(workDir)
opts := &command.Opts{
Stdin: strings.NewReader("n"),
Stdout: bufio.NewWriter(&outBuffer),
Stderr: os.Stderr,
Dir: workDir,
}
var cmd command.Command
if useBundler {
cmd = factory.CreateBundleExec(name, args, bundlerVersion.Version, opts)
} else {
cmd = factory.Create(name, args, opts)
}

log.Debugf("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -131,7 +138,8 @@ func handleSessionDataError(err error) {

func main() {
var config Config
if err := stepconf.Parse(&config); err != nil {
parser := stepconf.NewInputParser(env.NewRepository())
if err := parser.Parse(&config); err != nil {
failf("Issue with input: %s", err)
}

Expand Down Expand Up @@ -180,10 +188,22 @@ func main() {

log.Donef("Expanded WorkDir: %s", workDir)

if rbenvVersionsCommand := gems.RbenvVersionsCommand(); rbenvVersionsCommand != nil {
cmdLocator := env.NewCommandLocator()
factory, err := ruby.NewCommandFactory(command.NewFactory(env.NewRepository()), cmdLocator)
if err != nil {
panic(err)
}

if _, err := cmdLocator.LookPath("rbenv"); err != nil {
cmd := factory.Create("rbenv", []string{"versions"}, &command.Opts{
Stderr: os.Stderr,
Stdout: os.Stdout,
Dir: workDir,
})

fmt.Println()
log.Donef("$ %s", rbenvVersionsCommand.PrintableCommandArgs())
if err := rbenvVersionsCommand.SetStdout(os.Stdout).SetStderr(os.Stderr).SetDir(workDir).Run(); err != nil {
log.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
log.Warnf("%s", err)
}
}
Expand Down Expand Up @@ -245,51 +265,48 @@ func main() {
log.Infof("Install bundler")

// install bundler with `gem install bundler [-v version]`
// in some configurations, the command "bunder _1.2.3_" can return 'Command not found', installing bundler solves this
installBundlerCommand := gems.InstallBundlerCommand(gemVersions.bundler)

log.Donef("$ %s", installBundlerCommand.PrintableCommandArgs())
fmt.Println()

installBundlerCommand.SetStdout(os.Stdout).SetStderr(os.Stderr)
installBundlerCommand.SetDir(workDir)
// in some configurations, the command "bundler _1.2.3_" can return 'Command not found', installing bundler solves this
cmds := factory.CreateGemInstall("bundler", gemVersions.bundler.Version, false, true, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: workDir,
})
for _, cmd := range cmds {
log.Donef("$ %s", cmd.PrintableCommandArgs())
fmt.Println()

if err := installBundlerCommand.Run(); err != nil {
failf("command failed, error: %s", err)
if err := cmd.Run(); err != nil {
failf("command failed, error: %s", err)
}
}

// install Gemfile.lock gems with `bundle [_version_] install ...`
fmt.Println()
log.Infof("Install Fastlane with bundler")

cmd, err := gems.BundleInstallCommand(gemVersions.bundler)
if err != nil {
failf("failed to create bundle command, error: %s", err)
}
cmd := factory.CreateBundleInstall(gemVersions.bundler.Version, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: workDir,
})

log.Donef("$ %s", cmd.PrintableCommandArgs())
fmt.Println()

cmd.SetStdout(os.Stdout).SetStderr(os.Stderr)
cmd.SetDir(workDir)

if err := cmd.Run(); err != nil {
failf("Command failed, error: %s", err)
}
} else if config.UpdateFastlane {
log.Infof("Update system installed Fastlane")

cmds, err := rubycommand.GemInstall("fastlane", "", false)
if err != nil {
failf("Failed to create command model, error: %s", err)
}

cmds := factory.CreateGemInstall("fastlane", "", false, false, &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: workDir,
})
for _, cmd := range cmds {
log.Donef("$ %s", cmd.PrintableCommandArgs())

cmd.SetStdout(os.Stdout).SetStderr(os.Stderr)
cmd.SetDir(workDir)

if err := cmd.Run(); err != nil {
failf("Command failed, error: %s", err)
}
Expand All @@ -301,20 +318,21 @@ func main() {
fmt.Println()
log.Infof("Fastlane version")

versionCmd := []string{"fastlane", "--version"}
if useBundler {
versionCmd = append(gems.BundleExecPrefix(gemVersions.bundler), versionCmd...)
name := "fastlane"
args := []string{"--version"}
opts := &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: workDir,
}

log.Donef("$ %s", command.PrintableCommandArgs(false, versionCmd))

cmd, err := rubycommand.NewFromSlice(versionCmd)
if err != nil {
failf("Command failed, error: %s", err)
var cmd command.Command
if useBundler {
cmd = factory.CreateBundleExec(name, args, gemVersions.bundler.Version, opts)
} else {
cmd = factory.Create(name, args, opts)
}

cmd.SetStdout(os.Stdout).SetStderr(os.Stderr)
cmd.SetDir(workDir)
log.Donef("$ %s", cmd.PrintableCommandArgs())

if err := cmd.Run(); err != nil {
failf("Command failed, error: %s", err)
Expand Down Expand Up @@ -342,32 +360,29 @@ func main() {
log.Infof("To stop overriding authentication-related environment variables, please set Bitrise Apple Developer Connection input to 'off' and leave authentication-related inputs empty.")
}

fastlaneCmd := []string{"fastlane"}
fastlaneCmd = append(fastlaneCmd, laneOptions...)
if useBundler {
fastlaneCmd = append(gems.BundleExecPrefix(gemVersions.bundler), fastlaneCmd...)
}

log.Donef("$ %s", command.PrintableCommandArgs(false, fastlaneCmd))

cmd, err = rubycommand.NewFromSlice(fastlaneCmd)
if err != nil {
failf("Failed to create command model, error: %s", err)
}

cmd.SetStdout(os.Stdout).SetStderr(os.Stderr)
cmd.SetDir(workDir)

buildlogPth := ""

if tempDir, err := pathutil.NormalizedOSTempDirPath("fastlane_logs"); err != nil {
log.Errorf("Failed to create temp dir for fastlane logs, error: %s", err)
} else {
buildlogPth = tempDir
envs = append(envs, "FL_BUILDLOG_PATH="+buildlogPth)
}

cmd.AppendEnvs(envs...)
name = "fastlane"
args = laneOptions
opts = &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
Dir: workDir,
Env: append(os.Environ(), envs...),
}
if useBundler {
cmd = factory.CreateBundleExec(name, args, gemVersions.bundler.Version, opts)
} else {
cmd = factory.Create(name, args, opts)
}

log.Donef("$ %s", cmd.PrintableCommandArgs())

deployDir := os.Getenv("BITRISE_DEPLOY_DIR")
if deployDir == "" {
Expand Down
Loading

0 comments on commit cb6dc87

Please sign in to comment.