Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call "add-platform" before "bundle install" when using cache #702

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ inputs:
bundler-cache:
description: 'Run "bundle install", and cache the result automatically. Either true or false.'
default: 'false'
add-platform:
description: 'Run "bundle lock --add-platform" before "bundle install" when using "bundler-cache"'
default: 'false'
working-directory:
description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions, mise.toml and Gemfile.lock.'
cache-version:
Expand Down
8 changes: 8 additions & 0 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
return true
}

export async function addPlatform(lockFile) {
if (fs.existsSync(lockFile)) {
const output = (await exec.getExecOutput('ruby', ['-e', 'p Gem::Platform.local.to_s'])).stdout
const platform = output.slice(1, output.length - 2)
await exec.getExecOutput('bundle', ['lock', '--add-platform', platform, `--lockfile=${lockFile}`])
}
}

async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) {
const cwd = process.cwd()
const bundleWith = process.env['BUNDLE_WITH'] || ''
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js

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

5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const inputDefaults = {
'rubygems': 'default',
'bundler': 'Gemfile.lock',
'bundler-cache': 'false',
'add-platform': 'false',
'working-directory': '.',
'cache-version': bundler.DEFAULT_CACHE_VERSION,
'self-hosted': 'false',
Expand Down Expand Up @@ -104,6 +105,10 @@ export async function setupRuby(options = {}) {
}

if (inputs['bundler-cache'] === 'true') {
if (inputs['add-platform'] === 'true') {
await bundler.addPlatform(lockFile)
}

await common.time('bundle install', async () =>
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version']))
}
Expand Down