diff --git a/lib/manager/regex/__fixtures__/gitlab-ci.yml b/lib/manager/regex/__fixtures__/gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..55f074e222f467dbcec9356d9776c1464d004d04 --- /dev/null +++ b/lib/manager/regex/__fixtures__/gitlab-ci.yml @@ -0,0 +1,6 @@ +include: + - template: Auto-DevOps.gitlab-ci.yml +variables: + CHART_REPOSITORY_URL: "https://kubernetes-sigs.github.io/descheduler/" + CHART_NAME: "descheduler" + CHART_VERSION: 0.19.2 diff --git a/lib/manager/regex/__snapshots__/index.spec.ts.snap b/lib/manager/regex/__snapshots__/index.spec.ts.snap index cc1d94995c3fe925da86e0dc9c75b07d0b42e5e5..9335afa0bd3892eba27c0fb812764277ceed28db 100644 --- a/lib/manager/regex/__snapshots__/index.spec.ts.snap +++ b/lib/manager/regex/__snapshots__/index.spec.ts.snap @@ -229,6 +229,31 @@ Object { } `; +exports[`manager/regex/index extracts with combination strategy and registry url 1`] = ` +Object { + "datasourceTemplate": "helm", + "deps": Array [ + Object { + "currentValue": "0.19.2", + "datasource": "helm", + "depName": "descheduler", + "registryUrls": Array [ + "https://kubernetes-sigs.github.io/descheduler/", + ], + "replaceString": "CHART_VERSION: 0.19.2 +", + }, + ], + "matchStrings": Array [ + "CHART_VERSION: (?<currentValue>.*?) +", + "CHART_REPOSITORY_URL: \\"(?<registryUrl>.*?)\\"", + "CHART_NAME: \\"(?<depName>.*?)\\"", + ], + "matchStringsStrategy": "combination", +} +`; + exports[`manager/regex/index extracts with recursive strategy and fail because of not sufficient regexes 1`] = `null`; exports[`manager/regex/index extracts with recursive strategy and fail because there is no match 1`] = `null`; diff --git a/lib/manager/regex/index.spec.ts b/lib/manager/regex/index.spec.ts index 30a45786ebcc1e628d247d36a03520433ed7f56c..ed2bd5cc79082caaae70b448145fa3856bfa6572 100644 --- a/lib/manager/regex/index.spec.ts +++ b/lib/manager/regex/index.spec.ts @@ -6,6 +6,7 @@ import { defaultConfig, extractPackageFile } from '.'; const dockerfileContent = loadFixture(`Dockerfile`); const ansibleYamlContent = loadFixture(`ansible.yml`); const exampleJsonContent = loadFixture(`example.json`); +const exampleGitlabCiYml = loadFixture(`gitlab-ci.yml`); describe(getName(), () => { it('has default config', () => { @@ -199,6 +200,24 @@ describe(getName(), () => { expect(res).toMatchSnapshot(); expect(res.deps).toHaveLength(1); }); + it('extracts with combination strategy and registry url', async () => { + const config: CustomExtractConfig = { + matchStringsStrategy: 'combination', + matchStrings: [ + 'CHART_VERSION: (?<currentValue>.*?)\n', + 'CHART_REPOSITORY_URL: "(?<registryUrl>.*?)"', + 'CHART_NAME: "(?<depName>.*?)"', + ], + datasourceTemplate: 'helm', + }; + const res = await extractPackageFile( + exampleGitlabCiYml, + '.gitlab-ci.yml', + config + ); + expect(res).toMatchSnapshot(); + expect(res.deps).toHaveLength(1); + }); it('extracts with recursive strategy and single match', async () => { const config: CustomExtractConfig = { matchStrings: [ diff --git a/lib/manager/regex/index.ts b/lib/manager/regex/index.ts index 840870bfc4b78285dade6f1b127e71c121c20773..250c735b18b5db778d7d23490ff3529c3effc8a1 100644 --- a/lib/manager/regex/index.ts +++ b/lib/manager/regex/index.ts @@ -24,6 +24,8 @@ const validMatchFields = [ 'registryUrl', ]; +const mergeFields = ['registryUrls', ...validMatchFields]; + function regexMatchAll(regex: RegExp, content: string): RegExpMatchArray[] { const matches: RegExpMatchArray[] = []; let matchResult; @@ -85,7 +87,7 @@ function createDependency( function mergeDependency(deps: PackageDependency[]): PackageDependency { const result: PackageDependency = {}; deps.forEach((dep) => { - validMatchFields.forEach((field) => { + mergeFields.forEach((field) => { if (dep[field]) { result[field] = dep[field]; // save the line replaceString of the section which contains the current Value for a speed up lookup during the replace phase