diff options
author | Sébastien CROCQUESEL <[email protected]> | 2021-10-25 07:25:35 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-25 05:25:35 +0000 |
commit | b3676ac8ec29ad157029e55f72e837669903a39e (patch) | |
tree | 34253bc06f328685d2f8382a9e4ad022a6766e19 | |
parent | e3e55d89461c877007f73e1c2f23b282647aaa41 (diff) | |
download | renovate-28.9.0.tar.gz renovate-28.9.0.zip |
feat(regex): depType can be captured and templated (#12287)28.9.0
-rw-r--r-- | docs/usage/configuration-options.md | 5 | ||||
-rw-r--r-- | lib/config/options/index.ts | 9 | ||||
-rw-r--r-- | lib/config/validation.spec.ts | 2 | ||||
-rw-r--r-- | lib/config/validation.ts | 1 | ||||
-rw-r--r-- | lib/manager/regex/__snapshots__/index.spec.ts.snap | 9 | ||||
-rw-r--r-- | lib/manager/regex/index.spec.ts | 2 | ||||
-rw-r--r-- | lib/manager/regex/index.ts | 1 | ||||
-rw-r--r-- | lib/manager/regex/readme.md | 1 | ||||
-rw-r--r-- | lib/manager/types.ts | 1 |
9 files changed, 31 insertions, 0 deletions
diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 4cf12065359..4b83c5809c2 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -2154,6 +2154,11 @@ It will be compiled using Handlebars and the regex `groups` result. If the `datasource` for a dependency is not captured with a named group then it can be defined in config using this field. It will be compiled using Handlebars and the regex `groups` result. +### depTypeTemplate + +If `depType` cannot be captured with a named capture group in `matchString` then it can be defined manually using this field. +It will be compiled using Handlebars and the regex `groups` result. + ### versioningTemplate If the `versioning` for a dependency is not captured with a named group then it can be defined in config using this field. diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index e12d34a3add..d043910c68a 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -1968,6 +1968,15 @@ const options: RenovateOptions[] = [ env: false, }, { + name: 'depTypeTemplate', + description: + 'Optional depType for extracted dependencies. Valid only within a `regexManagers` object.', + type: 'string', + parent: 'regexManagers', + cli: false, + env: false, + }, + { name: 'currentValueTemplate', description: 'Optional currentValue for extracted dependencies. Valid only within a `regexManagers` object.', diff --git a/lib/config/validation.spec.ts b/lib/config/validation.spec.ts index 7699913c184..711db997199 100644 --- a/lib/config/validation.spec.ts +++ b/lib/config/validation.spec.ts @@ -352,6 +352,7 @@ describe('config/validation', () => { datasourceTemplate: 'bar', registryUrlTemplate: 'foobar', extractVersionTemplate: '^(?<version>v\\d+\\.\\d+)', + depTypeTemplate: 'apple', }, ], }; @@ -370,6 +371,7 @@ describe('config/validation', () => { matchStrings: ['ENV (?<currentValue>.*?)\\s'], depNameTemplate: 'foo', datasourceTemplate: 'bar', + depTypeTemplate: 'apple', automerge: true, }, ], diff --git a/lib/config/validation.ts b/lib/config/validation.ts index efe44470473..3faa3dbd77a 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -389,6 +389,7 @@ export async function validateConfig( 'currentValueTemplate', 'extractVersionTemplate', 'autoReplaceStringTemplate', + 'depTypeTemplate', ]; // TODO: fix types for (const regexManager of val as any[]) { diff --git a/lib/manager/regex/__snapshots__/index.spec.ts.snap b/lib/manager/regex/__snapshots__/index.spec.ts.snap index 6071a39e352..bcc3505484b 100644 --- a/lib/manager/regex/__snapshots__/index.spec.ts.snap +++ b/lib/manager/regex/__snapshots__/index.spec.ts.snap @@ -81,11 +81,13 @@ Object { exports[`manager/regex/index extracts multiple dependencies 1`] = ` Object { + "depTypeTemplate": "final", "deps": Array [ Object { "currentValue": "6.2", "datasource": "gradle-version", "depName": "gradle", + "depType": "final", "replaceString": "ENV GRADLE_VERSION=6.2 # gradle-version/gradle&versioning=maven ", "versioning": "maven", @@ -94,6 +96,7 @@ Object { "currentValue": "10.19.0", "datasource": "github-tags", "depName": "nodejs/node", + "depType": "final", "replaceString": "ENV NODE_VERSION=10.19.0 # github-tags/nodejs/node&versioning=node ", "versioning": "node", @@ -102,6 +105,7 @@ Object { "currentValue": "1.9.3", "datasource": "github-releases", "depName": "composer/composer", + "depType": "final", "replaceString": "ENV COMPOSER_VERSION=1.9.3 # github-releases/composer/composer ", "versioning": "semver", @@ -110,6 +114,7 @@ Object { "currentValue": "1.9.0", "datasource": "rubygems", "depName": "cocoapods", + "depType": "final", "replaceString": "ENV COCOAPODS_VERSION=1.9.0 # rubygems/cocoapods&versioning=ruby ", "versioning": "ruby", @@ -118,6 +123,7 @@ Object { "currentValue": "19.03.1", "datasource": "github-releases", "depName": "docker/docker-ce", + "depType": "final", "replaceString": "ENV DOCKER_VERSION=19.03.1 # github-releases/docker/docker-ce&versioning=docker ", "versioning": "docker", @@ -126,6 +132,7 @@ Object { "currentValue": "1.0.0", "datasource": "github-releases", "depName": "python-poetry/poetry", + "depType": "final", "replaceString": "ENV POETRY_VERSION=1.0.0 # github-releases/python-poetry/poetry ", "versioning": "semver", @@ -134,6 +141,7 @@ Object { "currentValue": "6.10.2", "datasource": "npm", "depName": "npm", + "depType": "final", "replaceString": "ENV NPM_VERSION=6.10.2 # npm/npm ", "versioning": "semver", @@ -142,6 +150,7 @@ Object { "currentValue": "1.19.1", "datasource": "npm", "depName": "yarn", + "depType": "final", "replaceString": "ENV YARN_VERSION=1.19.1 # npm/yarn ", "versioning": "semver", diff --git a/lib/manager/regex/index.spec.ts b/lib/manager/regex/index.spec.ts index 7f3d9bdfc68..13258f85f2d 100644 --- a/lib/manager/regex/index.spec.ts +++ b/lib/manager/regex/index.spec.ts @@ -21,6 +21,7 @@ describe('manager/regex/index', () => { ], versioningTemplate: '{{#if versioning}}{{versioning}}{{else}}semver{{/if}}', + depTypeTemplate: 'final', }; const res = await extractPackageFile( dockerfileContent, @@ -35,6 +36,7 @@ describe('manager/regex/index', () => { expect(res.deps.find((dep) => dep.depName === 'gradle').versioning).toEqual( 'maven' ); + expect(res.deps.filter((dep) => dep.depType === 'final')).toHaveLength(8); }); it('returns null if no dependencies found', async () => { const config = { diff --git a/lib/manager/regex/index.ts b/lib/manager/regex/index.ts index 70f9c181ef1..7a866a6f70e 100644 --- a/lib/manager/regex/index.ts +++ b/lib/manager/regex/index.ts @@ -22,6 +22,7 @@ const validMatchFields = [ 'versioning', 'extractVersion', 'registryUrl', + 'depType', ]; const mergeFields = ['registryUrls', ...validMatchFields]; diff --git a/lib/manager/regex/readme.md b/lib/manager/regex/readme.md index c7289ff64a8..71d5337bb07 100644 --- a/lib/manager/regex/readme.md +++ b/lib/manager/regex/readme.md @@ -21,6 +21,7 @@ Configuration-wise, it works like this: - You must have either a `depName` capture group or a `depNameTemplate` config field - You can optionally have a `lookupName` capture group or a `lookupNameTemplate` if it differs from `depName` - You must have either a `datasource` capture group or a `datasourceTemplate` config field +- You can optionally have a `depType` capture group or a `depTypeTemplate` config field - You can optionally have a `versioning` capture group or a `versioningTemplate` config field. If neither are present, `semver` will be used as the default - You can optionally have an `extractVersion` capture group or an `extractVersionTemplate` config field - You can optionally have a `currentDigest` capture group. diff --git a/lib/manager/types.ts b/lib/manager/types.ts index 64f6e496af0..311ad5e4928 100644 --- a/lib/manager/types.ts +++ b/lib/manager/types.ts @@ -35,6 +35,7 @@ export interface CustomExtractConfig extends ExtractConfig { lookupNameTemplate?: string; datasourceTemplate?: string; versioningTemplate?: string; + depTypeTemplate?: string; } export interface UpdateArtifactsConfig { |