Skip to content

Commit

Permalink
Report active Ruby version (#95)
Browse files Browse the repository at this point in the history
* Report active Ruby version

* Move code around

* Fix swallowed error

* Flip error handling

* Disable test

* Fix

* Re-enable tests

* Implement step tracker

* Implement step tracker

* Extra version string validation for rbenv errors

* Define workdir in command
  • Loading branch information
ofalvai authored Mar 29, 2023
1 parent 6b45574 commit aec09a6
Show file tree
Hide file tree
Showing 88 changed files with 3,659 additions and 64,556 deletions.
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func (f FastlaneRunner) getWorkDir(config Config) (string, error) {
func (f FastlaneRunner) checkForRbenv(workDir string) {
f.logger.Println()
f.logger.Infof("Checking rbenv version")
if _, err := f.cmdLocator.LookPath("rbenv"); err != nil {
if _, err := f.cmdLocator.LookPath("rbenv"); err == nil {

cmd := f.rbyFactory.Create("rbenv", []string{"versions"}, &command.Opts{
Stderr: os.Stderr,
Stdout: os.Stdout,
Expand All @@ -194,6 +195,8 @@ func (f FastlaneRunner) checkForRbenv(workDir string) {
if err := cmd.Run(); err != nil {
f.logger.Warnf(err.Error())
}
} else {
f.logger.Warnf("rbenv not found: %s", err)
}
}

Expand Down
35 changes: 35 additions & 0 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os"
"strings"

"github.com/bitrise-io/go-utils/v2/command"
)
Expand All @@ -16,6 +17,8 @@ type EnsureDependenciesOpts struct {

// 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()
Expand Down Expand Up @@ -99,3 +102,35 @@ func (f FastlaneRunner) InstallDependencies(opts EnsureDependenciesOpts) error {

return nil
}

func (f FastlaneRunner) reportRubyVersion(useBundler bool, bundlerVersion string, workDir string) {
var versionCmd command.Command
options := &command.Opts{
Stdout: os.Stdout,
Stderr: os.Stderr,
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)
}
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.17
require (
github.com/bitrise-io/bitrise-init v0.0.0-20220504131857-f00a24c7c8ba
github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3
github.com/bitrise-io/go-steputils v1.0.2
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.14
github.com/bitrise-io/go-utils v1.0.2
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.15
github.com/bitrise-io/go-steputils v1.0.5
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.17
github.com/bitrise-io/go-utils v1.0.5
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16
github.com/bitrise-io/go-xcode v1.0.9
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/stretchr/testify v1.8.1
Expand All @@ -20,13 +20,14 @@ require (
github.com/bitrise-io/envman v0.0.0-20220512153504-166d59151b78 // indirect
github.com/bitrise-io/stepman v0.0.0-20220718172049-e5ae0a09c2f2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
19 changes: 11 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3 h1:tCKogs4CmxEuiR2k330SFkiqQ9
github.com/bitrise-io/go-android/v2 v2.0.0-alpha.3/go.mod h1:pkrTuGB9KAgVTWsMJ8UjqKjSInaNcdp8En9Fxqg2krc=
github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10/go.mod h1:pARutiL3kEuRLV3JvswidvfCj+9Y3qMZtji2BDqLFsA=
github.com/bitrise-io/go-steputils v1.0.1/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils v1.0.2 h1:BEFG87r7uA/Yabk4SmuxP2yOgjjO+YGsDOYXtUH8IJ0=
github.com/bitrise-io/go-steputils v1.0.2/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.14 h1:UzXSvZYsidm9vW/OwbFVKMHyqGfkJmaiDhg20wAP2zc=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.14/go.mod h1:ub3KVohX1vc1f2alPeVg7EoXAifm7p+SD326c2OUKdo=
github.com/bitrise-io/go-steputils v1.0.5 h1:OBH7CPXeqIWFWJw6BOUMQnUb8guspwKr2RhYBhM9tfc=
github.com/bitrise-io/go-steputils v1.0.5/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.17 h1:npcWC9jimYaJYlYBrPXxschwRAh6elJX01/1lEJ7mD8=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.17/go.mod h1:/ueNOKnsjcUrlt8Ck75WRNspL7E6nAAylvl9oGJtYio=
github.com/bitrise-io/go-utils v0.0.0-20200224122728-e212188d99b4/go.mod h1:tTEsKvbz1LbzuN/KpVFHXnLtcAPdEgIdM41s0lL407s=
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 v1.0.1/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
github.com/bitrise-io/go-utils v1.0.2 h1:w4Mz2IvrgDzrFJECuHdvsK1LHO30cdtuy9bBa7Lw2c0=
github.com/bitrise-io/go-utils v1.0.2/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
github.com/bitrise-io/go-utils v1.0.5 h1:RgLAvyK5m+CGAXeoogGUnz9apShWwbN4B2lBkJkU89c=
github.com/bitrise-io/go-utils v1.0.5/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.6/go.mod h1:mysJdafur1ytXda0TeRsV+GxYCJFDU0QcCmYBgQf2Fc=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.7/go.mod h1:6i0Gt0JRIbXpsrFDJT1YWghFfdN8qF26/fnpc/6d/88=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.12/go.mod h1:gZWtM7PLn1VOroa4gN1La/24aRVc0jg5R701jTsPaO8=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.15 h1:ERQb+OOa+eKMWb+HByyPd5ugz6TeaJPnQ3xHgyaR7hA=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.15/go.mod h1:Laih4ji980SQkRgdnMCH0g4u2GZI/5nnbqmYT9UfKFQ=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.13/go.mod h1:gZWtM7PLn1VOroa4gN1La/24aRVc0jg5R701jTsPaO8=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16 h1:y+Yo0d8pYIjZiKhQuPM/Z5FY9/mu+wrWkyQlch8f9Po=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16/go.mod h1:Laih4ji980SQkRgdnMCH0g4u2GZI/5nnbqmYT9UfKFQ=
github.com/bitrise-io/go-xcode v1.0.6/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY=
github.com/bitrise-io/go-xcode v1.0.9 h1:+sbqOYidQ+aiFfCTDpf2LdGSQEM5RfbtDsiG27zJG+s=
github.com/bitrise-io/go-xcode v1.0.9/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY=
Expand All @@ -54,6 +56,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
Expand Down Expand Up @@ -83,6 +86,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -145,7 +149,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
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.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func run() ExitCode {
return Failure
}

buildStep.tracker.wait()

return Success
}

Expand All @@ -64,8 +66,9 @@ func createStep(logger log.Logger) FastlaneRunner {
}

pathModifier := pathutil.NewPathModifier()
tracker := newStepTracker(envRepository, logger)

return NewFastlaneRunner(inputParser, logger, cmdLocator, cmdFactory, rbyFactory, pathModifier)
return NewFastlaneRunner(inputParser, logger, cmdLocator, cmdFactory, rbyFactory, pathModifier, tracker)
}

// FastlaneRunner ...
Expand All @@ -76,6 +79,7 @@ type FastlaneRunner struct {
cmdLocator env.CommandLocator
rbyFactory ruby.CommandFactory
pathModifier pathutil.PathModifier
tracker stepTracker
}

// NewFastlaneRunner ...
Expand All @@ -86,6 +90,7 @@ func NewFastlaneRunner(
cmdFactory command.Factory,
rbyFactory ruby.CommandFactory,
pathModifier pathutil.PathModifier,
tracker stepTracker,
) FastlaneRunner {
return FastlaneRunner{
inputParser: stepInputParser,
Expand All @@ -94,6 +99,7 @@ func NewFastlaneRunner(
cmdFactory: cmdFactory,
rbyFactory: rbyFactory,
pathModifier: pathModifier,
tracker: tracker,
}
}

Expand Down
35 changes: 35 additions & 0 deletions tracker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/bitrise-io/go-utils/v2/analytics"
"github.com/bitrise-io/go-utils/v2/env"
"github.com/bitrise-io/go-utils/v2/log"
)

type stepTracker struct {
tracker analytics.Tracker
logger log.Logger
}

func newStepTracker(envRepo env.Repository, logger log.Logger) stepTracker {
p := analytics.Properties{
"build_slug": envRepo.Get("BITRISE_BUILD_SLUG"),
"step_execution_id": envRepo.Get("BITRISE_STEP_EXECUTION_ID"),
"step_id": "fastlane",
}
return stepTracker{
tracker: analytics.NewDefaultTracker(logger, p),
logger: logger,
}
}

func (t *stepTracker) logEffectiveRubyVersion(versionString string) {
properties := analytics.Properties{
"effective_ruby_version": versionString,
}
t.tracker.Enqueue("step_ruby_version_selected", properties)
}

func (t *stepTracker) wait() {
t.tracker.Wait()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/bitrise-io/go-steputils/step/steperror.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aec09a6

Please sign in to comment.