Skip to content

Commit 38c3566

Browse files
committed
Call "add-platform" before "bundle install" when using cache
1 parent 8711a86 commit 38c3566

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ inputs:
2525
bundler-cache:
2626
description: 'Run "bundle install", and cache the result automatically. Either true or false.'
2727
default: 'false'
28+
add-platform:
29+
description: 'Run "bundle lock --add-platform" before "bundle install" when using "bundler-cache"'
30+
default: 'false'
2831
working-directory:
2932
description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions, mise.toml and Gemfile.lock.'
3033
cache-version:

bundler.js

+8
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
232232
return true
233233
}
234234

235+
export async function addPlatform(lockFile) {
236+
if (fs.existsSync(lockFile)) {
237+
const output = (await exec.getExecOutput('ruby', ['-e', 'p Gem::Platform.local.to_s'])).stdout
238+
const platform = output.slice(1, output.length - 2)
239+
await exec.getExecOutput('bundle', ['lock', '--add-platform', platform, `--lockfile=${lockFile}`])
240+
}
241+
}
242+
235243
async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) {
236244
const cwd = process.cwd()
237245
const bundleWith = process.env['BUNDLE_WITH'] || ''

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const inputDefaults = {
1414
'rubygems': 'default',
1515
'bundler': 'Gemfile.lock',
1616
'bundler-cache': 'false',
17+
'add-platform': 'false',
1718
'working-directory': '.',
1819
'cache-version': bundler.DEFAULT_CACHE_VERSION,
1920
'self-hosted': 'false',
@@ -104,6 +105,10 @@ export async function setupRuby(options = {}) {
104105
}
105106

106107
if (inputs['bundler-cache'] === 'true') {
108+
if (inputs['add-platform'] === 'true') {
109+
await bundler.addPlatform(lockFile)
110+
}
111+
107112
await common.time('bundle install', async () =>
108113
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version']))
109114
}

0 commit comments

Comments
 (0)