Skip to content

Commit 1a68550

Browse files
Fryguyeregon
authored andcommitted
Fix bundler: with a minor version installing the wrong version
If passed `bundler: 2.2`, setup-ruby would install bundler 2.3, because it would generate a constraint that looks like `~> 2.2`. This unexpectedly installs the latest of the 2.x series, but the expectation is that it would install the latest of the 2.2.x series. Fixes #304
1 parent bd94d6a commit 1a68550

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ jobs:
145145
rubygems: 3.2.3
146146
- run: gem --version | grep -F "3.3.3"
147147

148+
testMajorBundlerVersion:
149+
name: "Test with a major Bundler version"
150+
runs-on: ubuntu-latest
151+
steps:
152+
- uses: actions/checkout@v2
153+
- uses: ./
154+
with:
155+
ruby-version: 2.6
156+
bundler: 2
157+
- run: bundle --version | grep -P "Bundler version 2\.\d+\.\d+"
158+
159+
testMinorBundlerVersion:
160+
name: "Test with a minor Bundler version"
161+
runs-on: ubuntu-latest
162+
steps:
163+
- uses: actions/checkout@v2
164+
- uses: ./
165+
with:
166+
ruby-version: 2.6
167+
bundler: 2.2
168+
- run: bundle --version | grep -P "Bundler version 2\.2\.\d+"
169+
148170
testExactBundlerVersion:
149171
name: "Test with an exact Bundler version"
150172
runs-on: ubuntu-latest

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
Defaults to 'default'.
1919
bundler:
2020
description: |
21-
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1.4).
21+
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1, 2.1.4).
2222
For 'Gemfile.lock', the version is determined based on the BUNDLED WITH section from the file Gemfile.lock, $BUNDLE_GEMFILE.lock or gems.locked.
2323
Defaults to 'Gemfile.lock' if the file exists and 'latest' otherwise.
2424
required: false

bundler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export async function installBundler(bundlerVersionInput, lockFile, platform, ru
6565
bundlerVersion = '2'
6666
}
6767

68-
if (/^\d+/.test(bundlerVersion)) {
69-
// OK
68+
if (/^\d+(?:\.\d+){0,2}$/.test(bundlerVersion)) {
69+
// OK - input is a 1, 2, or 3 part version number
7070
} else {
7171
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
7272
}
@@ -95,9 +95,12 @@ export async function installBundler(bundlerVersionInput, lockFile, platform, ru
9595
console.log(`Using Bundler 1 shipped with ${engine}-${rubyVersion}`)
9696
} else {
9797
const gem = path.join(rubyPrefix, 'bin', 'gem')
98-
const bundlerVersionConstraint = /^\d+\.\d+\.\d+/.test(bundlerVersion) ? bundlerVersion : `~> ${bundlerVersion}`
9998
// Workaround for https://github.com/rubygems/rubygems/issues/5245
10099
const force = (platform.startsWith('windows-') && engine === 'ruby' && floatVersion >= 3.1) ? ['--force'] : []
100+
101+
const versionParts = [...bundlerVersion.matchAll(/\d+/g)].length
102+
const bundlerVersionConstraint = versionParts === 3 ? bundlerVersion : `~> ${bundlerVersion}.0`
103+
101104
await exec.exec(gem, ['install', 'bundler', ...force, '-v', bundlerVersionConstraint])
102105
}
103106

dist/index.js

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

0 commit comments

Comments
 (0)