diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 02f3d42056f266..63742895d4251f 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -849,7 +849,8 @@ It will be compiled using Handlebars and the regex `groups` result. It specifies the syntax of the package file that's managed by the custom `jsonata` manager. This setting helps the system correctly parse and interpret the configuration file's contents. -Only the `json` format is supported. +Only the `json` and `yaml` format is supported. +`yaml` files are parsed as multi document YAML files. ```json title="Parsing a JSON file with a custom manager" { @@ -866,6 +867,21 @@ Only the `json` format is supported. } ``` +```json title="Parsing a YAML file with a custom manager" +{ + "customManagers": [ + { + "customType": "jsonata", + "fileFormat": "yaml", + "fileMatch": ["file.yml"], + "matchStrings": [ + "packages.{ \"depName\": package, \"currentValue\": version }" + ] + } + ] +} +``` + ### matchStrings Each `matchStrings` must be one of the following: diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 9aabdf41b45501..c5ad124c28110c 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2745,7 +2745,7 @@ const options: RenovateOptions[] = [ description: 'It specifies the syntax of the package file being managed by the custom JSONata manager.', type: 'string', - allowedValues: ['json'], + allowedValues: ['json', 'yaml'], parents: ['customManagers'], cli: false, env: false, diff --git a/lib/modules/manager/custom/jsonata/index.spec.ts b/lib/modules/manager/custom/jsonata/index.spec.ts index 9237ba21b62dbf..76f964a5c5f108 100644 --- a/lib/modules/manager/custom/jsonata/index.spec.ts +++ b/lib/modules/manager/custom/jsonata/index.spec.ts @@ -83,6 +83,58 @@ describe('modules/manager/custom/jsonata/index', () => { }); }); + it('extracts yaml', async () => { + const json = codeBlock` + --- + packages: + - + "dep_name": "foo" + "package_name": "fii" + "current_value": "1.2.3" + "current_digest": "1234" + "data_source": "nuget" + "versioning": "maven" + "extract_version": "custom-extract-version" + "registry_url": "https://registry.npmjs.org" + "dep_type": "dev" + --- + some: true + `; + const config = { + fileFormat: 'yaml', + matchStrings: [ + `packages.{ + "depName": dep_name, + "packageName": package_name, + "currentValue": current_value, + "currentDigest": current_digest, + "datasource": data_source, + "versioning": versioning, + "extractVersion": extract_version, + "registryUrl": registry_url, + "depType": dep_type + }`, + ], + }; + const res = await extractPackageFile(json, 'unused', config); + + expect(res).toMatchObject({ + deps: [ + { + depName: 'foo', + packageName: 'fii', + currentValue: '1.2.3', + currentDigest: '1234', + datasource: 'nuget', + versioning: 'maven', + extractVersion: 'custom-extract-version', + registryUrls: ['https://registry.npmjs.org/'], + depType: 'dev', + }, + ], + }); + }); + it('applies templates', async () => { const json = codeBlock` { diff --git a/lib/modules/manager/custom/jsonata/index.ts b/lib/modules/manager/custom/jsonata/index.ts index cd63c0c0081534..8324c0efc7c6bb 100644 --- a/lib/modules/manager/custom/jsonata/index.ts +++ b/lib/modules/manager/custom/jsonata/index.ts @@ -2,6 +2,7 @@ import is from '@sindresorhus/is'; import type { Category } from '../../../../constants'; import { logger } from '../../../../logger'; import { parseJson } from '../../../../util/common'; +import { parseYaml } from '../../../../util/yaml'; import type { PackageFileContent } from '../../types'; import type { JsonataExtractConfig } from './types'; import { handleMatching } from './utils'; @@ -25,6 +26,9 @@ export async function extractPackageFile( case 'json': json = parseJson(content, packageFile); break; + case 'yaml': + json = parseYaml(content); + break; } } catch (err) { logger.debug( diff --git a/lib/modules/manager/custom/jsonata/readme.md b/lib/modules/manager/custom/jsonata/readme.md index e388f2936fe6f9..257b173b8edb58 100644 --- a/lib/modules/manager/custom/jsonata/readme.md +++ b/lib/modules/manager/custom/jsonata/readme.md @@ -1,6 +1,6 @@ -With `customManagers` using `JSONata` queries you can configure Renovate so it finds dependencies in JSON files, that are not detected by its other built-in package managers. +With `customManagers` using `JSONata` queries you can configure Renovate so it finds dependencies in JSON or YAML files, that are not detected by its other built-in package managers. -Renovate uses the `jsonata` package to process the `json` file content using the queries. +Renovate uses the `jsonata` package to process the `json` or `yaml` file content using the queries. For more on the jsonata query language, read the [jsonata query language site](https://docs.jsonata.org/overview.html). @@ -87,6 +87,8 @@ We recommend you follow these steps: Alternatively you can "try and error" to a working config, by adjusting our examples. +YAML files are parsed as multi document files. + #### Example queries Below are some example queries for the generic JSON manager. @@ -201,3 +203,31 @@ $map($map(packages, function ($v) { $split($v, "@") }), function ($v) { { "depNa "datasourceTemplate": "npm" } ``` + +```yaml title="Dependencies in a single node, and we want to extract all of them" +packages: + - version: 1.2.3 + package: foo +``` + +Query: + +``` +packages.{ "depName": package, "currentValue": version } +``` + +```yaml title="Dependencies in a single node in a multi document yaml, and we want to extract all of them" +packages: + - version: 1.2.3 + package: foo +--- +packages: + - version: 1.2.5 + package: bar +``` + +Query: + +``` +packages.{ "depName": package, "currentValue": version } +```