Skip to content

Commit

Permalink
Export BUNDLER_VERSION after installing Bundler
Browse files Browse the repository at this point in the history
* Fixes #440
  • Loading branch information
eregon committed Jan 6, 2023
1 parent eb7f94f commit 3190662
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
const targetRubyVersion = common.targetRubyVersion(engine, rubyVersion)
// Use Bundler 2.3 when we use Ruby 2.3.2 - 2.5
// Use Bundler 2.4 when we use Ruby 2.6-2.7
if (bundlerVersion == '2') {
if (bundlerVersion === '2') {
if (targetRubyVersion <= 2.5) { // < 2.3.2 already handled above
console.log('Ruby 2.3.2 - 2.5 only works with Bundler 2.3')
bundlerVersion = '2.3'
Expand All @@ -146,6 +146,14 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock

await exec.exec(gem, ['install', 'bundler', ...force, '-v', bundlerVersionConstraint])

if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
// we need to specify which Bundler version to use explicitly until the lockfile exists.
// We actually set it globally for the case of bundler-cache: false with manual bundler install later.
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} to ensure Bundler 1 is used`)
core.exportVariable('BUNDLER_VERSION', bundlerVersion)
}

return bundlerVersion
}

Expand All @@ -155,27 +163,19 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
return false
}

let envOptions = {}
if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
// we need to specify which Bundler version to use explicitly until the lockfile exists.
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler 1 is used`)
envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
}

// config
const cachePath = 'vendor/bundle'
// An absolute path, so it is reliably under $PWD/vendor/bundle, and not relative to the gemfile's directory
const bundleCachePath = path.join(process.cwd(), cachePath)

await exec.exec('bundle', ['config', '--local', 'path', bundleCachePath], envOptions)
await exec.exec('bundle', ['config', '--local', 'path', bundleCachePath])

if (fs.existsSync(lockFile)) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], envOptions)
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
} else {
// Generate the lockfile so we can use it to compute the cache key.
// This will also automatically pick up the latest gem versions compatible with the Gemfile.
await exec.exec('bundle', ['lock'], envOptions)
await exec.exec('bundle', ['lock'])
}

await afterLockFile(lockFile, platform, engine, rubyVersion)
Expand Down
24 changes: 12 additions & 12 deletions dist/index.js

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

3 comments on commit 3190662

@dblock
Copy link

@dblock dblock commented on 3190662 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a test :)

@eregon
Copy link
Member Author

@eregon eregon commented on 3190662 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already one:

testDependencyOnBundler1:
name: "Test gemfile depending on Bundler 1"
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/bundler1.gemfile
steps:
- uses: actions/checkout@v3
- uses: ./
with:
ruby-version: '2.7'
bundler: 1
bundler-cache: true
- run: bundle --version | grep -F "Bundler version 1."

@dblock
Copy link

@dblock dblock commented on 3190662 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eregon If I may, there's functionality change in this code, and no tests have changed, so there's no test for this change of behavior. Thanks for your great work though and the fix!

Please sign in to comment.