Skip to content

Commit

Permalink
Add an exported setupRuby() function which can be called from other a…
Browse files Browse the repository at this point in the history
…ctions

* Inputs are passed as simple object properties.
* It is recommended to expose the same inputs for other actions.
* See #58 and #33.
  • Loading branch information
eregon committed Jun 6, 2020
1 parent b04e5b8 commit 81be093
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
29 changes: 21 additions & 8 deletions dist/index.js

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

28 changes: 20 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@ const core = require('@actions/core')
const exec = require('@actions/exec')
const common = require('./common')

const inputDefaults = {
'ruby-version': 'default',
'bundler': 'default',
'working-directory': '.',
}

export async function run() {
try {
await main()
const options = {}
for (const key in inputDefaults) {
options[key] = core.getInput(key)
}
await setupRuby(options)
} catch (error) {
core.setFailed(error.message)
}
}

async function main() {
process.chdir(core.getInput('working-directory'))
export async function setupRuby(options) {
const inputs = { ...inputDefaults, ...options }

process.chdir(inputs['working-directory'])

const platform = common.getVirtualEnvironmentName()
const [engine, parsedVersion] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version'])

let installer
if (platform === 'windows-latest' && engine !== 'jruby') {
Expand All @@ -35,9 +47,9 @@ async function main() {

setupPath(newPathEntries)

if (core.getInput('bundler') !== 'none') {
if (inputs['bundler'] !== 'none') {
await common.measure('Installing Bundler', async () =>
installBundler(platform, rubyPrefix, engine, version))
installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
}

core.setOutput('ruby-prefix', rubyPrefix)
Expand Down Expand Up @@ -142,8 +154,8 @@ function readBundledWithFromGemfileLock() {
return null
}

async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler')
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = bundlerVersionInput

if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock()
Expand Down

0 comments on commit 81be093

Please sign in to comment.