Skip to content

Commit

Permalink
Consider Bundler pre and rc versions valid, just exclude .dev
Browse files Browse the repository at this point in the history
* Fixes #439
  • Loading branch information
eregon committed Jan 6, 2023
1 parent ad718fa commit eb7f94f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ jobs:
bundler: 2.2.3
- run: bundle --version | grep -F "Bundler version 2.2.3"

testBundlerPre:
name: "Test with a Bundler pre/rc version"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
ruby-version: '2.6'
bundler: 2.2.0.rc.2
- run: bundle --version | grep -F "Bundler version 2.2.0.rc.2"

testBundlerDev:
name: "Test BUNDLED WITH Bundler dev"
runs-on: ubuntu-latest
Expand Down
11 changes: 7 additions & 4 deletions bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const cache = require('@actions/cache')
const common = require('./common')

export const DEFAULT_CACHE_VERSION = '0'
export const BUNDLER_VERSION_REGEXP = /^\d+(?:\.\d+){0,2}$/

function isValidBundlerVersion(bundlerVersion) {
return /^\d+(?:\.\d+){0,2}/.test(bundlerVersion) && !bundlerVersion.endsWith('.dev')
}

// The returned gemfile is guaranteed to exist, the lockfile might not exist
export function detectGemfiles() {
Expand All @@ -33,7 +36,7 @@ function readBundledWithFromGemfileLock(lockFile) {
const nextLine = lines[bundledWithLine+1]
if (nextLine) {
const bundlerVersion = nextLine.trim()
if (BUNDLER_VERSION_REGEXP.test(bundlerVersion)) {
if (isValidBundlerVersion(bundlerVersion)) {
console.log(`Using Bundler ${bundlerVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
return bundlerVersion
} else {
Expand Down Expand Up @@ -100,7 +103,7 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
bundlerVersion = '2'
}

if (BUNDLER_VERSION_REGEXP.test(bundlerVersion)) {
if (isValidBundlerVersion(bundlerVersion)) {
// OK - input is a 1, 2, or 3 part version number
} else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
Expand Down Expand Up @@ -139,7 +142,7 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
const force = ((platform.startsWith('windows-') && engine === 'ruby' && floatVersion >= 3.1) || (engine === 'truffleruby')) ? ['--force'] : []

const versionParts = [...bundlerVersion.matchAll(/\d+/g)].length
const bundlerVersionConstraint = versionParts === 3 ? bundlerVersion : `~> ${bundlerVersion}.0`
const bundlerVersionConstraint = versionParts >= 3 ? bundlerVersion : `~> ${bundlerVersion}.0`

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

Expand Down
12 changes: 7 additions & 5 deletions dist/index.js

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

1 comment on commit eb7f94f

@dblock
Copy link

@dblock dblock commented on eb7f94f Jan 6, 2023

Choose a reason for hiding this comment

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

Have you considered swapping this code for a proper semver parser? e.g. https://www.npmjs.com/package/semver-parser (haven't used that one, just Googling)

Please sign in to comment.