Skip to content

Commit

Permalink
Ruby detection (#94)
Browse files Browse the repository at this point in the history
* Ruby detection

---------

Co-authored-by: Olivér Falvai <ofalvai@gmail.com>
  • Loading branch information
lpusok and ofalvai authored Sep 11, 2023
1 parent b29272c commit b2a6b7f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ go/bin/
go/pkg/
.gows.user.yml
.idea
.DS_Store
.ruby-version
steps-cocoapods-install
55 changes: 37 additions & 18 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ app:
# Shared test configs
- PODFILE_PTH: ""
- VERBOSE: "false"
- PIN_RUBY: "false"
- PIN_RBENV_RUBY: ""
- PIN_ASDF_RUBY: ""

workflows:
test_no_gemfile:
Expand Down Expand Up @@ -49,25 +50,23 @@ workflows:
- _run
- _check_cache_include_paths

test_with_specific_ruby:
before_run:
- _expose_xcode_version
steps:
- script:
# TODO: Ruby compilation fails on Xcode 15 Beta, revisit this later
run_if: "{{getenv \"XCODE_MAJOR_VERSION\" | ne \"15\"}}"
inputs:
- content: |-
#!/bin/env bash
set -x # Do not set -e as bitrise command is expected to fail
bitrise run --config=./e2e/bitrise.yml utility_test_with_specific_ruby
test_with_specific_missing_ruby_asdf:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-iOS-Cocoapods-Sample.git
- TEST_APP_BRANCH: main
- COMMAND: install
- PIN_ASDF_RUBY: 3.2.0
after_run:
- _run
- _check_cache_include_paths

utility_test_with_specific_ruby:
# previous test isntalled required ruby version
test_with_specific_installed_ruby_rbenv:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-iOS-Cocoapods-Sample.git
- TEST_APP_BRANCH: main
- COMMAND: install
- PIN_RUBY: "true"
- PIN_RBENV_RUBY: 3.2.0
after_run:
- _run
- _check_cache_include_paths
Expand Down Expand Up @@ -110,14 +109,34 @@ workflows:
- clone_into_dir: ./_tmp
- script:
run_if: |-
{{ enveq "PIN_RUBY" "true" }}
title: Pin Ruby version
{{ getenv "PIN_RBENV_RUBY" | ne "" }}
title: Pin .ruby-version Ruby version
inputs:
- content: |-
#!/bin/bash
set -ex
echo "$PIN_RBENV_RUBY" >> ./_tmp/.ruby-version
- script:
run_if: |-
{{ getenv "PIN_ASDF_RUBY" | ne "" }}
title: Pin .tool-versions Ruby version
inputs:
- content: |-
#!/bin/bash
set -ex
echo "ruby $PIN_ASDF_RUBY" >> ./_tmp/.tool-versions
- script:
inputs:
- content: |-
#!/bin/bash
set -ex
echo "3.1.4" >> .ruby-version
which ruby
cd ./_tmp
asdf current
cd -
- path::./:
inputs:
- source_root_path: $BITRISE_SOURCE_DIR/_tmp
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module bitrise-steplib/steps-cocoapods-install
go 1.20

require (
github.com/bitrise-io/go-steputils v1.0.5
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.16
github.com/bitrise-io/go-steputils v1.0.6
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.20
github.com/bitrise-io/go-utils v1.0.9
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.15
github.com/bitrise-io/go-xcode v1.0.16
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10 h1:/2OyBFI7GjYKexBPcfTPvKFz8Ks7qYzkkz2SQ8aiJgc=
github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10/go.mod h1:pARutiL3kEuRLV3JvswidvfCj+9Y3qMZtji2BDqLFsA=
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.16 h1:WA0QxrFG6ZeBTFsjBsqnCYwlfW0WRDuxGX74a2ffWRw=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.16/go.mod h1:M09BbxYoh6B7KJnXk/yvtuU5nZPh7RQBJGKc1dp+0hQ=
github.com/bitrise-io/go-steputils v1.0.6 h1:eBRL70DWwEd7DWYGd5Ds7OSIY5HElzhoDOI6UuITKQg=
github.com/bitrise-io/go-steputils v1.0.6/go.mod h1:YIUaQnIAyK4pCvQG0hYHVkSzKNT9uL2FWmkFNW4mfNI=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.20 h1:ac+HUrl4H+2qM/0FmP6mOJQvoxSPpO68er3tKNJoM6E=
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.20/go.mod h1:YeLAqkNuns7tiZNAlGJ8kOWvSEZy3SOKAQCv2CeWk5A=
github.com/bitrise-io/go-utils v1.0.1/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
github.com/bitrise-io/go-utils v1.0.9 h1:wy7FewUpseNSTZr41BbGH0csfFqzptFt4zy2pOAEOg0=
github.com/bitrise-io/go-utils v1.0.9/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
Expand Down
36 changes: 34 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,39 @@ func main() {
log.Donef("Using system installed CocoaPods version")
}

if rubycommand.RubyInstallType() == rubycommand.RbenvRuby {
if rubycommand.RubyInstallType() == rubycommand.ASDFRuby {
isRubyVersionInstalled, rubyVersion, err := rubycommand.IsSpecifiedASDFRubyInstalled(configs.SourceRootPath)
if err != nil {
failf("Failed to check if selected ruby is installed: %s", err)
}

fmt.Println()
log.Infof("Checking selected Ruby version")
asdfCurrentCmd := command.New("asdf", "current", "ruby").
SetStdout(os.Stdout).
SetStderr(os.Stderr).
SetDir(configs.SourceRootPath)
log.Donef("$ %s", asdfCurrentCmd.PrintableCommandArgs())
if err := asdfCurrentCmd.Run(); err != nil {
log.Warnf("Failed to print selected Ruby version: %s", err)
}

fmt.Println()
if !isRubyVersionInstalled {
log.Errorf("The selected Ruby version (%s) is not installed.", rubyVersion)
} else {
log.Donef("The selected Ruby version (%s) is installed.", rubyVersion)
}

if !isRubyVersionInstalled && os.Getenv("CI") == "true" {
log.Infof("Installing missing Ruby version")
cmd := command.New("asdf", "install", "ruby", rubyVersion).SetStdout(os.Stdout).SetStderr(os.Stderr)
log.Donef("$ %s", cmd.PrintableCommandArgs())
if err := cmd.Run(); err != nil {
log.Errorf("Failed to install Ruby version %s, error: %s", rubyVersion, err)
}
}
} else if rubycommand.RubyInstallType() == rubycommand.RbenvRuby {
rubySelectStart := time.Now()
rubyInstalled, rversion, err := rubycommand.IsSpecifiedRbenvRubyInstalled(configs.SourceRootPath)
if err != nil {
Expand All @@ -376,7 +408,7 @@ func main() {
// Run this logic only in CI environment when the ruby was installed via rbenv for the virtual machine
if os.Getenv("CI") == "true" {
fmt.Println()
log.Infof("Check selected Ruby is installed")
log.Infof("Checking selected Ruby version using rbenv")

if !rubyInstalled {
log.Errorf("Ruby %s is not installed", rversion)
Expand Down

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.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# github.com/bitrise-io/go-plist v0.0.0-20210301100253-4b1a112ccd10
## explicit; go 1.15
github.com/bitrise-io/go-plist
# github.com/bitrise-io/go-steputils v1.0.5
# github.com/bitrise-io/go-steputils v1.0.6
## explicit; go 1.15
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/stepconf
github.com/bitrise-io/go-steputils/tools
# github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.16
# github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.20
## explicit; go 1.17
github.com/bitrise-io/go-steputils/v2/ruby
# github.com/bitrise-io/go-utils v1.0.9
Expand Down

0 comments on commit b2a6b7f

Please sign in to comment.