From 1ee546b0ea99aeac98fd60d2ad1cbf0db0f103d7 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Mon, 21 Jan 2019 14:50:30 +0100 Subject: [PATCH] feat(bundler): use ruby and bundler versions to update lock files --- lib/manager/bundler/artifacts.js | 61 +++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/manager/bundler/artifacts.js b/lib/manager/bundler/artifacts.js index 2c7fc31286..8994a36363 100644 --- a/lib/manager/bundler/artifacts.js +++ b/lib/manager/bundler/artifacts.js @@ -4,6 +4,14 @@ const { exec } = require('child-process-promise'); const fs = require('fs-extra'); const upath = require('upath'); +const { getPkgReleases } = require('../../datasource/docker'); +const { + isValid, + isVersion, + matches, + sortVersions, +} = require('../../versioning/ruby'); + module.exports = { getArtifacts, }; @@ -48,20 +56,65 @@ async function getArtifacts( let cmd; if (config.binarySource === 'docker') { logger.info('Running bundler via docker'); + let tag = 'latest'; + let rubyConstraint; + const rubyVersionFile = upath.join( + upath.dirname(packageFileName), + '.ruby-version' + ); + logger.debug('Checking ' + rubyVersionFile); + const rubyVersionFileContent = await platform.getFile(rubyVersionFile); + if (rubyVersionFileContent) { + logger.debug('Using ruby version specified in .ruby-version'); + rubyConstraint = rubyVersionFileContent.replace(/\n/g, '').trim(); + } else { + rubyConstraint = + config && config.compatibility && config.compatibility.ruby + ? config.compatibility.ruby + : undefined; + } + if (rubyConstraint && isValid(rubyConstraint)) { + logger.debug('Found ruby compatibility'); + const rubyReleases = await getPkgReleases({ + fullname: 'renovate/ruby', + qualifiers: {}, + }); + if (rubyReleases && rubyReleases.releases) { + let versions = rubyReleases.releases.map(release => release.version); + versions = versions.filter(version => isVersion(version)); + versions = versions.filter(version => + matches(version, rubyConstraint) + ); + versions = versions.sort(sortVersions); + if (versions.length) { + tag = versions.pop(); + } + } + } + const bundlerConstraint = + config && config.compatibility && config.compatibility.bundler + ? config.compatibility.bundler + : undefined; + let bundlerVersion = ''; + if (bundlerConstraint && isVersion(bundlerConstraint)) { + bundlerVersion = ' -v ' + bundlerConstraint; + } cmd = `docker run --rm `; const volumes = [config.localDir]; cmd += volumes.map(v => `-v ${v}:${v} `).join(''); const envVars = []; cmd += envVars.map(e => `-e ${e} `); cmd += `-w ${cwd} `; - cmd += `renovate/bundler bundler`; + cmd += `renovate/ruby:${tag} bash -l -c "ruby --version && `; + cmd += 'gem install bundler' + bundlerVersion; + cmd += ' && bundle'; } else { logger.info('Running bundler via global bundler'); cmd = 'bundler'; } - const args = 'lock'; - logger.debug({ cmd, args }, 'bundler command'); - ({ stdout, stderr } = await exec(`${cmd} ${args}`, { + cmd += ' lock"'; + logger.debug({ cmd }, 'bundler command'); + ({ stdout, stderr } = await exec(cmd, { cwd, shell: true, env, -- GitLab