Skip to content

Commit

Permalink
feat: allow install command's version parameter to be evaluated (#102)
Browse files Browse the repository at this point in the history
* feat: allow evaluation of `version` param

This will allow support of users passing in env vars, like `'${MY_RUBY_VERSION}'` or things like `'$(cat foo/bar/.ruby-version)'`.

* chore: modify integration-test CI job to use Ruby 2.7.5 as per demo rails project

* docs: update description for commands.install.parameters.version.description

* test: add additional test for installing Ruby version specified in env var
  • Loading branch information
kelvintaywl authored May 18, 2022
1 parent 20485a7 commit 365d475
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
23 changes: 21 additions & 2 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ executors:
jobs:
integration-tests:
docker:
- image: cimg/ruby:2.7-node
# NOTE: the specific Ruby version required is based on https://github.com/CircleCI-Public/circleci-demo-ruby-rails
# See https://github.com/CircleCI-Public/circleci-demo-ruby-rails/blob/2033c5f8da3010941127e0f9133925bd8efc7a79/Gemfile#L10
# When the project's Ruby version requirement is updated, we will need to update here as well.
- image: cimg/ruby:2.7.5-node
- image: cimg/postgres:14.2
environment:
POSTGRES_USER: circleci-demo-ruby
Expand Down Expand Up @@ -70,7 +73,7 @@ jobs:
install-on-machine:
parameters:
image:
description: Enter the version that should be user for the machine executor.
description: Enter the version that should be used for the machine executor.
type: string
executor:
name: ubuntu
Expand All @@ -90,6 +93,19 @@ jobs:
- run:
name: "Test Install"
command: ruby --version | grep "2.6"
install-from-env-var:
docker:
- image: cimg/node:current
steps:
- run:
name: Set RUBY_VERSION env var
command: |
echo "export RUBY_VERSION='2.7.0'" >> $BASH_ENV
- ruby/install:
version: "${RUBY_VERSION}"
- run:
name: "Test Install"
command: ruby --version | grep "2.7.0"

workflows:
test-deploy:
Expand All @@ -104,6 +120,8 @@ workflows:
filters: *filters
- install-on-node:
filters: *filters
- install-from-env-var:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/publish:
Expand All @@ -115,6 +133,7 @@ workflows:
- integration-tests
- install-on-machine
- install-on-node
- install-from-env-var
context: orb-publishing
filters:
branches:
Expand Down
6 changes: 5 additions & 1 deletion src/commands/install.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
description: "Install Ruby within a build. To be used in a Linux distro with Apt available."
parameters:
version:
description: "Ruby version."
description: >
Ruby version.
This can be a literal value (e.g, `2.7.5`).
You can also pass in a string to be evaluated.
For example, `${MY_RUBY_VERSION}` or `$(cat foo/bar/.ruby-version)`.
type: string
steps:
- run:
Expand Down
10 changes: 6 additions & 4 deletions src/scripts/install-ruby.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash

rvm install "$PARAM_VERSION"
rvm use "$PARAM_VERSION"
PARAM_RUBY_VERSION=$(eval echo "${PARAM_VERSION}")

readonly ruby_path="$(rvm $PARAM_VERSION 1> /dev/null 2> /dev/null && rvm env --path)"
printf '%s\n' "source $ruby_path" >> $BASH_ENV
rvm install "$PARAM_RUBY_VERSION"
rvm use "$PARAM_RUBY_VERSION"

readonly ruby_path="$(rvm $PARAM_RUBY_VERSION 1> /dev/null 2> /dev/null && rvm env --path)"
printf '%s\n' "source $ruby_path" >> $BASH_ENV

0 comments on commit 365d475

Please sign in to comment.