Skip to content

Commit

Permalink
feat(bundler): use ruby and bundler versions to update lock files
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jan 21, 2019
1 parent d4cff79 commit 1ee546b
Showing 1 changed file with 57 additions and 4 deletions.
61 changes: 57 additions & 4 deletions lib/manager/bundler/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1ee546b

Please sign in to comment.