Skip to content

Commit 81be093

Browse files
committed
Add an exported setupRuby() function which can be called from other actions
* Inputs are passed as simple object properties. * It is recommended to expose the same inputs for other actions. * See #58 and #33.
1 parent b04e5b8 commit 81be093

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

dist/index.js

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@ const core = require('@actions/core')
55
const exec = require('@actions/exec')
66
const common = require('./common')
77

8+
const inputDefaults = {
9+
'ruby-version': 'default',
10+
'bundler': 'default',
11+
'working-directory': '.',
12+
}
13+
814
export async function run() {
915
try {
10-
await main()
16+
const options = {}
17+
for (const key in inputDefaults) {
18+
options[key] = core.getInput(key)
19+
}
20+
await setupRuby(options)
1121
} catch (error) {
1222
core.setFailed(error.message)
1323
}
1424
}
1525

16-
async function main() {
17-
process.chdir(core.getInput('working-directory'))
26+
export async function setupRuby(options) {
27+
const inputs = { ...inputDefaults, ...options }
28+
29+
process.chdir(inputs['working-directory'])
1830

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

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

3648
setupPath(newPathEntries)
3749

38-
if (core.getInput('bundler') !== 'none') {
50+
if (inputs['bundler'] !== 'none') {
3951
await common.measure('Installing Bundler', async () =>
40-
installBundler(platform, rubyPrefix, engine, version))
52+
installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
4153
}
4254

4355
core.setOutput('ruby-prefix', rubyPrefix)
@@ -142,8 +154,8 @@ function readBundledWithFromGemfileLock() {
142154
return null
143155
}
144156

145-
async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
146-
var bundlerVersion = core.getInput('bundler')
157+
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
158+
var bundlerVersion = bundlerVersionInput
147159

148160
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
149161
bundlerVersion = readBundledWithFromGemfileLock()

0 commit comments

Comments
 (0)