feat(bazel): support "container_pull" dependency-type (#3514)

This commit is contained in:
Dmitry 2019-04-12 14:27:49 +03:00 committed by Rhys Arkins
parent 3c75d63b56
commit 4607276464
7 changed files with 131 additions and 1 deletions

View file

@ -63,7 +63,12 @@ function findBalancedParenIndex(longString) {
} }
function parseContent(content) { function parseContent(content) {
return ['http_archive', 'go_repository', 'git_repository'].reduce( return [
'container_pull',
'http_archive',
'go_repository',
'git_repository',
].reduce(
(acc, prefix) => [ (acc, prefix) => [
...acc, ...acc,
...content ...content
@ -99,10 +104,25 @@ function extractPackageFile(content) {
let commit; let commit;
let url; let url;
let sha256; let sha256;
let digest;
let repository;
let registry;
let match = def.match(/name\s*=\s*"([^"]+)"/); let match = def.match(/name\s*=\s*"([^"]+)"/);
if (match) { if (match) {
[, depName] = match; [, depName] = match;
} }
match = def.match(/digest\s*=\s*"([^"]+)"/);
if (match) {
[, digest] = match;
}
match = def.match(/registry\s*=\s*"([^"]+)"/);
if (match) {
[, registry] = match;
}
match = def.match(/repository\s*=\s*"([^"]+)"/);
if (match) {
[, repository] = match;
}
match = def.match(/remote\s*=\s*"([^"]+)"/); match = def.match(/remote\s*=\s*"([^"]+)"/);
if (match) { if (match) {
[, remote] = match; [, remote] = match;
@ -196,6 +216,19 @@ function extractPackageFile(content) {
dep.lookupName = dep.repo; dep.lookupName = dep.repo;
dep.lookupType = 'releases'; dep.lookupType = 'releases';
deps.push(dep); deps.push(dep);
} else if (
depType === 'container_pull' &&
currentValue &&
digest &&
repository &&
registry
) {
dep.currentDigest = digest;
dep.currentValue = currentValue;
dep.depName = depName;
dep.datasource = 'docker';
dep.lookupName = repository;
deps.push(dep);
} else { } else {
logger.info( logger.info(
{ def }, { def },

View file

@ -9,6 +9,11 @@ async function updateDependency(fileContent, upgrade) {
try { try {
logger.debug(`bazel.updateDependency(): ${upgrade.newValue}`); logger.debug(`bazel.updateDependency(): ${upgrade.newValue}`);
let newDef; let newDef;
if (upgrade.depType === 'container_pull') {
newDef = upgrade.def
.replace(/(tag\s*=\s*)"[^"]+"/, `$1"${upgrade.newValue}"`)
.replace(/(digest\s*=\s*)"[^"]+"/, `$1"${upgrade.newDigest}"`);
}
if ( if (
upgrade.depType === 'git_repository' || upgrade.depType === 'git_repository' ||
upgrade.depType === 'go_repository' upgrade.depType === 'go_repository'

View file

@ -1,5 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`lib/manager/bazel/extract extractPackageFile() extracts dependencies for container_pull deptype 1`] = `
Array [
Object {
"currentDigest": "sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
"currentValue": "v1.0.0-alpha31.cli-migrations",
"datasource": "docker",
"def": "container_pull(
name=\\"hasura\\",
registry=\\"index.docker.io\\",
repository=\\"hasura/graphql-engine\\",
# v1.0.0-alpha31.cli-migrations 11/28
digest=\\"sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548\\",
tag=\\"v1.0.0-alpha31.cli-migrations\\"
)",
"depName": "hasura",
"depType": "container_pull",
"lookupName": "hasura/graphql-engine",
},
]
`;
exports[`lib/manager/bazel/extract extractPackageFile() extracts dependencies from *.bzl files 1`] = ` exports[`lib/manager/bazel/extract extractPackageFile() extracts dependencies from *.bzl files 1`] = `
Array [ Array [
Object { Object {

View file

@ -115,3 +115,15 @@ go_rules_dependencies()
go_register_toolchains() go_register_toolchains()
" "
`; `;
exports[`manager/bazel/update updateDependency updates container_pull deptype and prserves comment 1`] = `
"container_pull(
name=\\"hasura\\",
registry=\\"index.docker.io\\",
repository=\\"hasura/graphql-engine\\",
# v1.0.0-alpha31.cli-migrations 11/28
digest=\\"sha256:2c29ba015faef92a3f55b37632fc373a7fbc2c9fddd31e317bf07113391c640b\\",
tag=\\"v1.0.0-alpha42.cli-migrations\\"
)
"
`;

View file

@ -0,0 +1,8 @@
container_pull(
name="hasura",
registry="index.docker.io",
repository="hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)

View file

@ -33,6 +33,23 @@ describe('lib/manager/bazel/extract', () => {
const res = extractPackageFile(fileWithBzlExtension, config); const res = extractPackageFile(fileWithBzlExtension, config);
expect(res.deps).toMatchSnapshot(); expect(res.deps).toMatchSnapshot();
}); });
it('extracts dependencies for container_pull deptype', () => {
const res = extractPackageFile(
`
container_pull(
name="hasura",
registry="index.docker.io",
repository="hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)`,
config
);
expect(res.deps).toMatchSnapshot();
});
it('check remote option in go_repository', () => { it('check remote option in go_repository', () => {
const successStory = extractPackageFile( const successStory = extractPackageFile(
` `

View file

@ -10,6 +10,11 @@ const content = fs.readFileSync(
'utf8' 'utf8'
); );
const contentContainerPull = fs.readFileSync(
path.resolve('test/manager/bazel/_fixtures/container_pull'),
'utf8'
);
const fileWithBzlExtension = fs.readFileSync( const fileWithBzlExtension = fs.readFileSync(
'test/manager/bazel/_fixtures/repositories.bzl', 'test/manager/bazel/_fixtures/repositories.bzl',
'utf8' 'utf8'
@ -36,6 +41,35 @@ describe('manager/bazel/update', () => {
const res = await bazelfile.updateDependency(content, upgrade); const res = await bazelfile.updateDependency(content, upgrade);
expect(res).not.toEqual(content); expect(res).not.toEqual(content);
}); });
it('updates container_pull deptype and prserves comment', async () => {
const upgrade = {
depName: 'hasura',
depType: 'container_pull',
def: `container_pull(
name="hasura",
registry="index.docker.io",
repository="hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)`,
currentValue: 'v1.0.0-alpha31.cli-migrations',
currentDigest:
'sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548',
newDigest:
'sha256:2c29ba015faef92a3f55b37632fc373a7fbc2c9fddd31e317bf07113391c640b',
newValue: 'v1.0.0-alpha42.cli-migrations',
};
const res = await bazelfile.updateDependency(
contentContainerPull,
upgrade
);
expect(res).toMatchSnapshot();
expect(res).not.toEqual(contentContainerPull);
expect(res.includes('# v1.0.0-alpha31.cli-migrations 11/28')).toBe(true);
});
it('updates commit to tag', async () => { it('updates commit to tag', async () => {
const upgrade = { const upgrade = {
depName: 'com_github_google_uuid', depName: 'com_github_google_uuid',