Skip to content

Commit

Permalink
feat(presets/custom-managers): Add Makefile custom manager preset (re…
Browse files Browse the repository at this point in the history
  • Loading branch information
phil9909 committed Jun 18, 2024
1 parent 70badaa commit 3b56439
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
73 changes: 73 additions & 0 deletions lib/config/presets/internal/custom-managers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,79 @@ describe('config/presets/internal/custom-managers', () => {
});
});

describe('Update `_VERSION` variables in Makefiles', () => {
const customManager = presets['makefileVersions'].customManagers?.[0];

it(`find dependencies in file`, async () => {
const fileContent = codeBlock`
# renovate: datasource=node depName=node versioning=node
NODE_VERSION=18.13.0
# renovate: datasource=npm depName=pnpm
PNPM_VERSION = "7.25.1"
# renovate: datasource=npm depName=yarn
YARN_VERSION := '3.3.1'
# renovate: datasource=custom.hashicorp depName=consul
CONSUL_VERSION ?= 1.3.1
lint:
\tnpm install -g pnpm@$(PNPM_VERSION)
`;

const res = await extractPackageFile(
fileContent,
'gitlab-ci.yml',
customManager!,
);

expect(res?.deps).toMatchObject([
{
currentValue: '18.13.0',
datasource: 'node-version',
depName: 'node',
replaceString:
'# renovate: datasource=node depName=node versioning=node\nNODE_VERSION=18.13.0\n',
versioning: 'node',
},
{
currentValue: '7.25.1',
datasource: 'npm',
depName: 'pnpm',
replaceString:
'# renovate: datasource=npm depName=pnpm\nPNPM_VERSION = "7.25.1"\n',
},
{
currentValue: '3.3.1',
datasource: 'npm',
depName: 'yarn',
replaceString:
"# renovate: datasource=npm depName=yarn\nYARN_VERSION := '3.3.1'\n",
},
{
currentValue: '1.3.1',
datasource: 'custom.hashicorp',
depName: 'consul',
replaceString:
'# renovate: datasource=custom.hashicorp depName=consul\nCONSUL_VERSION ?= 1.3.1\n',
},
]);
});

describe('matches regexes patterns', () => {
it.each`
path | expected
${'Makefile'} | ${true}
${'makefile'} | ${true}
${'GNUMakefile'} | ${true}
${'sub/dir/Makefile'} | ${true}
${'versions.mk'} | ${true}
${'Dockerfile'} | ${false}
${'MakefileGenerator.ts'} | ${false}
`('$path', ({ path, expected }) => {
expect(regexMatches(path, customManager!.fileMatch)).toBe(expected);
});
});
});

describe('finds dependencies in pom.xml properties', () => {
const customManager = presets['mavenPropertyVersions'].customManagers?.[0];

Expand Down
17 changes: 17 additions & 0 deletions lib/config/presets/internal/custom-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ export const presets: Record<string, Preset> = {
],
description: 'Update `appVersion` value in Helm chart `Chart.yaml`.',
},
makefileVersions: {
customManagers: [
{
customType: 'regex',
fileMatch: [
'(^|/)Makefile$',
'(^|/)makefile$',
'(^|/)GNUMakefile$',
'\\.mk$',
],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-.]+?) depName=(?<depName>[^\\s]+?)(?: (?:packageName)=(?<packageName>[^\\s]+?))?(?: versioning=(?<versioning>[^\\s]+?))?(?: extractVersion=(?<extractVersion>[^\\s]+?))?(?: registryUrl=(?<registryUrl>[^\\s]+?))?\\s+[A-Za-z0-9_]+?_VERSION\\s*:*\\??=\\s*["\']?(?<currentValue>.+?)["\']?\\s',
],
},
],
description: 'Update `_VERSION` variables in Makefiles.',
},
mavenPropertyVersions: {
customManagers: [
{
Expand Down

0 comments on commit 3b56439

Please sign in to comment.