Skip to content

Commit 12fd324

Browse files
Thomascountzeregon
authored andcommitted
Use BUNDLE_LOCKFILE when detecting the lockfile
Honor `BUNDLE_LOCKFILE` (added in Bundler 4) when selecting the lockfile used for Bundler version detection, deployment mode, and bundler-cache keys. Without this, workflows using an alternate lockfile can read the wrong `BUNDLED WITH` version and generate cache keys from the wrong lockfile.
1 parent a99ac84 commit 12fd324

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ should be able to fix them by setting `rubygems: 3.0.0` or higher.
168168

169169
By default, Bundler is installed as follows:
170170

171-
* If there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
171+
* If there is a `Gemfile.lock` file (or `$BUNDLE_LOCKFILE`, `$BUNDLE_GEMFILE.lock`, or `gems.locked`) with a `BUNDLED WITH` section,
172172
that version of Bundler will be installed and used.
173173
* If the Ruby ships with Bundler 2.2+ (as a default gem), that version is used.
174174
* Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.3, Bundler 1 on Ruby < 2.3).
@@ -188,7 +188,7 @@ Note that any step doing `bundle install` (for the root `Gemfile`) or `gem insta
188188

189189
This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org.
190190
It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory).
191-
If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bundle config --local deployment true` is used.
191+
If there is a `Gemfile.lock` (or `$BUNDLE_LOCKFILE`, `$BUNDLE_GEMFILE.lock`, or `gems.locked`), `bundle config --local deployment true` is used.
192192

193193
To use a `Gemfile` which is not at the root or has a different name, set `BUNDLE_GEMFILE` in the `env` at the job level
194194
as shown in the [example](#matrix-of-gemfiles).

bundler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ function isValidBundlerVersion(bundlerVersion) {
1515
// The returned gemfile is guaranteed to exist, the lockfile might not exist
1616
export function detectGemfiles() {
1717
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
18+
const lockfilePath = process.env['BUNDLE_LOCKFILE']
19+
1820
if (fs.existsSync(gemfilePath)) {
19-
return [gemfilePath, `${gemfilePath}.lock`]
21+
return [gemfilePath, lockfilePath || `${gemfilePath}.lock`]
2022
} else if (process.env['BUNDLE_GEMFILE']) {
2123
throw new Error(`$BUNDLE_GEMFILE is set to ${gemfilePath} but does not exist`)
2224
}
2325

2426
if (fs.existsSync("gems.rb")) {
25-
return ["gems.rb", "gems.locked"]
27+
return ["gems.rb", lockfilePath || "gems.locked"]
2628
}
2729

2830
return [null, null]

dist/index.js

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

0 commit comments

Comments
 (0)