Skip to content

Commit

Permalink
feat: matchFiles + lockFiles (#8783)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 20, 2021
1 parent d2a7147 commit 7118404
Show file tree
Hide file tree
Showing 24 changed files with 298 additions and 137 deletions.
2 changes: 1 addition & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ Use the syntax `!/ /` like the following:

### matchFiles

Renovate will compare `matchFiles` for an exact match against the dependency's package file.
Renovate will compare `matchFiles` for an exact match against the dependency's package file or lock file.

For example the following would match `package.json` but not `package/frontend/package.json`:

Expand Down
21 changes: 21 additions & 0 deletions lib/manager/bundler/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Object {
"skipReason": "no-version",
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [
"https://rubygems.org",
],
Expand Down Expand Up @@ -1379,6 +1382,9 @@ Object {
"skipReason": "no-version",
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [
"https://rubygems.org",
],
Expand Down Expand Up @@ -1440,6 +1446,9 @@ Object {
"skipReason": "no-version",
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [
"https://rubygems.org",
],
Expand Down Expand Up @@ -2138,6 +2147,9 @@ Object {
},
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [
"https://rubygems.org",
],
Expand Down Expand Up @@ -4684,6 +4696,9 @@ Object {
},
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [
"https://rubygems.org",
],
Expand Down Expand Up @@ -4716,6 +4731,9 @@ Object {
],
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [],
}
`;
Expand Down Expand Up @@ -4749,6 +4767,9 @@ Object {
"skipReason": "no-version",
},
],
"lockFiles": Array [
"Gemfile.lock",
],
"registryUrls": Array [],
}
`;
1 change: 1 addition & 0 deletions lib/manager/bundler/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export async function extractPackageFile(
const lockContent = await readLocalFile(gemfileLock, 'utf8');
if (lockContent) {
logger.debug({ packageFile: fileName }, 'Found Gemfile.lock file');
res.lockFiles = [gemfileLock];
const lockedEntries = extractLockFileEntries(lockContent);
for (const dep of res.deps) {
const lockedDepValue = lockedEntries.get(dep.depName);
Expand Down
10 changes: 8 additions & 2 deletions lib/manager/cargo/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { parse } from '@iarna/toml';
import * as datasourceCrate from '../../datasource/crate';
import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { readLocalFile } from '../../util/fs';
import { findLocalSiblingOrParent, readLocalFile } from '../../util/fs';
import { ExtractConfig, PackageDependency, PackageFile } from '../common';
import {
CargoConfig,
Expand Down Expand Up @@ -186,5 +186,11 @@ export async function extractPackageFile(
if (!deps.length) {
return null;
}
return { deps };
const lockFileName = await findLocalSiblingOrParent(fileName, 'Cargo.lock');
const res: PackageFile = { deps };
// istanbul ignore if
if (lockFileName) {
res.lockFiles = [lockFileName];
}
return res;
}
9 changes: 6 additions & 3 deletions lib/manager/cocoapods/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const complexPodfile = fs.readFileSync(

describe('lib/manager/cocoapods/extract', () => {
describe('extractPackageFile()', () => {
it('extracts all dependencies', () => {
const simpleResult = extractPackageFile(simplePodfile).deps;
it('extracts all dependencies', async () => {
const simpleResult = (await extractPackageFile(simplePodfile, 'Podfile'))
.deps;
expect(simpleResult).toMatchSnapshot();

const complexResult = extractPackageFile(complexPodfile).deps;
const complexResult = (
await extractPackageFile(complexPodfile, 'Podfile')
).deps;
expect(complexResult).toMatchSnapshot();
});
});
Expand Down
15 changes: 12 additions & 3 deletions lib/manager/cocoapods/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as datasourceGithubTags from '../../datasource/github-tags';
import * as datasourcePod from '../../datasource/pod';
import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { getSiblingFileName, localPathExists } from '../../util/fs';
import { PackageDependency, PackageFile } from '../common';

const regexMappings = [
Expand Down Expand Up @@ -75,7 +76,10 @@ export function gitDep(parsedLine: ParsedLine): PackageDependency | null {
return null;
}

export function extractPackageFile(content: string): PackageFile | null {
export async function extractPackageFile(
content: string,
fileName: string
): Promise<PackageFile | null> {
logger.trace('cocoapods.extractPackageFile()');
const deps: PackageDependency[] = [];
const lines: string[] = content.split('\n');
Expand Down Expand Up @@ -137,6 +141,11 @@ export function extractPackageFile(content: string): PackageFile | null {
deps.push(dep);
}
}

return deps.length ? { deps } : null;
const res: PackageFile = { deps };
const lockFile = getSiblingFileName(fileName, 'Podfile.lock');
// istanbul ignore if
if (await localPathExists(lockFile)) {
res.lockFiles = [lockFile];
}
return res;
}
1 change: 1 addition & 0 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface NpmLockFiles {
pnpmShrinkwrap?: string;
npmLock?: string;
lernaDir?: string;
lockFiles?: string[];
}

export interface PackageFile<T = Record<string, any>>
Expand Down
6 changes: 6 additions & 0 deletions lib/manager/composer/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ Object {
"depType": "require-dev",
},
],
"lockFiles": Array [
"composer.lock",
],
}
`;

Expand Down Expand Up @@ -557,6 +560,9 @@ Object {
"lookupName": "git@my-git.example:my-git-repo",
},
],
"lockFiles": Array [
"composer.lock",
],
"registryUrls": Array [
"https://wpackagist.org",
"https://packagist.org",
Expand Down
1 change: 1 addition & 0 deletions lib/manager/composer/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function extractPackageFile(
let lockParsed: ComposerLock;
if (lockContents) {
logger.debug({ packageFile: fileName }, 'Found composer lock file');
res.lockFiles = [lockfilePath];
try {
lockParsed = JSON.parse(lockContents) as ComposerLock;
} catch (err) /* istanbul ignore next */ {
Expand Down
44 changes: 22 additions & 22 deletions lib/manager/helmv3/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('lib/manager/helm-requirements/extract', () => {
jest.resetAllMocks();
fs.readLocalFile = jest.fn();
});
it('skips invalid registry urls', () => {
it('skips invalid registry urls', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -27,7 +27,7 @@ describe('lib/manager/helm-requirements/extract', () => {
version: 0.8.1
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand All @@ -36,7 +36,7 @@ describe('lib/manager/helm-requirements/extract', () => {
expect(result).toMatchSnapshot();
expect(result.deps.every((dep) => dep.skipReason)).toEqual(true);
});
it('parses simple Chart.yaml correctly', () => {
it('parses simple Chart.yaml correctly', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -54,15 +54,15 @@ describe('lib/manager/helm-requirements/extract', () => {
condition: postgresql.enabled
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
});
it('resolves aliased registry urls', () => {
it('resolves aliased registry urls', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -75,7 +75,7 @@ describe('lib/manager/helm-requirements/extract', () => {
repository: '@placeholder'
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
placeholder: 'https://my-registry.gcr.io/',
},
Expand All @@ -84,21 +84,21 @@ describe('lib/manager/helm-requirements/extract', () => {
expect(result).toMatchSnapshot();
expect(result.deps.every((dep) => dep.skipReason)).toEqual(false);
});
it("doesn't fail if Chart.yaml is invalid", () => {
it("doesn't fail if Chart.yaml is invalid", async () => {
const content = `
Invalid Chart.yaml content.
arr:
[
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('skips local dependencies', () => {
it('skips local dependencies', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -114,15 +114,15 @@ describe('lib/manager/helm-requirements/extract', () => {
repository: file:///some/local/path/
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
});
it('returns null if no dependencies key', () => {
it('returns null if no dependencies key', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
`);
const content = `
Expand All @@ -134,14 +134,14 @@ describe('lib/manager/helm-requirements/extract', () => {
hello: world
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('returns null if dependencies are an empty list', () => {
it('returns null if dependencies are an empty list', async () => {
fs.readLocalFile.mockResolvedValueOnce(`
`);
const content = `
Expand All @@ -153,14 +153,14 @@ describe('lib/manager/helm-requirements/extract', () => {
dependencies: []
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('returns null if dependencies key is invalid', () => {
it('returns null if dependencies key is invalid', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -172,24 +172,24 @@ describe('lib/manager/helm-requirements/extract', () => {
[
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('returns null if Chart.yaml is empty', () => {
it('returns null if Chart.yaml is empty', async () => {
const content = '';
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('returns null if Chart.yaml uses an unsupported apiVersion', () => {
it('returns null if Chart.yaml uses an unsupported apiVersion', async () => {
const content = `
apiVersion: v1
appVersion: "1.0"
Expand All @@ -198,14 +198,14 @@ describe('lib/manager/helm-requirements/extract', () => {
version: 0.1.0
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});
it('returns null if name and version are missing for all dependencies', () => {
it('returns null if name and version are missing for all dependencies', async () => {
const content = `
apiVersion: v2
appVersion: "1.0"
Expand All @@ -218,7 +218,7 @@ describe('lib/manager/helm-requirements/extract', () => {
alias: "test"
`;
const fileName = 'Chart.yaml';
const result = extractPackageFile(content, fileName, {
const result = await extractPackageFile(content, fileName, {
aliases: {
stable: 'https://charts.helm.sh/stable',
},
Expand Down

0 comments on commit 7118404

Please sign in to comment.