diff --git a/lib/modules/manager/docker-compose/__fixtures__/docker-compose.3-tags.yml b/lib/modules/manager/docker-compose/__fixtures__/docker-compose.3-tags.yml new file mode 100644 index 000000000000000..dcf8cd77ffa3527 --- /dev/null +++ b/lib/modules/manager/docker-compose/__fixtures__/docker-compose.3-tags.yml @@ -0,0 +1,25 @@ +services: + web: + image: node:20.0.0 + build: + context: '.' + dockerfile: 'Dockerfile' + ports: + - "80:8000" + + worker: + extends: + service: web + build: !reset null + ports: !override + - "443:8000" + + db: + image: "postgres:9.4.0" + volumes: + - db-data:/var/lib/postgresql/data + networks: + - backend + deploy: + placement: + constraints: [node.role == manager] diff --git a/lib/modules/manager/docker-compose/extract.spec.ts b/lib/modules/manager/docker-compose/extract.spec.ts index b9436050d88ae17..ca4f45a06339fe6 100644 --- a/lib/modules/manager/docker-compose/extract.spec.ts +++ b/lib/modules/manager/docker-compose/extract.spec.ts @@ -6,6 +6,7 @@ const yamlFile1 = Fixtures.get('docker-compose.1.yml'); const yamlFile3 = Fixtures.get('docker-compose.3.yml'); const yamlFile3NoVersion = Fixtures.get('docker-compose.3-no-version.yml'); const yamlFile3DefaultValue = Fixtures.get('docker-compose.3-default-val.yml'); +const yamlFile3WithTags = Fixtures.get('docker-compose.3-tags.yml'); describe('modules/manager/docker-compose/extract', () => { describe('extractPackageFile()', () => { @@ -56,6 +57,23 @@ describe('modules/manager/docker-compose/extract', () => { expect(res?.deps).toHaveLength(1); }); + it('extracts can parse yaml tags for version 3', () => { + const res = extractPackageFile(yamlFile3WithTags, '', {}); + expect(res?.deps).toMatchInlineSnapshot(` + [ + { + "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", + "currentDigest": undefined, + "currentValue": "9.4.0", + "datasource": "docker", + "depName": "postgres", + "replaceString": "postgres:9.4.0", + }, + ] + `); + expect(res?.deps).toHaveLength(1); + }); + it('extracts image and replaces registry', () => { const compose = codeBlock` version: "3" diff --git a/lib/modules/manager/gitlabci-include/extract.ts b/lib/modules/manager/gitlabci-include/extract.ts index 9de7408d4a4ed52..8e7303a09caaae1 100644 --- a/lib/modules/manager/gitlabci-include/extract.ts +++ b/lib/modules/manager/gitlabci-include/extract.ts @@ -14,7 +14,6 @@ import type { GitlabIncludeProject, GitlabPipeline, } from '../gitlabci/types'; -import { replaceReferenceTags } from '../gitlabci/utils'; import type { PackageDependency, PackageFileContent } from '../types'; function extractDepFromIncludeFile( @@ -72,7 +71,7 @@ export function extractPackageFile( const endpoint = GlobalConfig.get('endpoint'); try { // TODO: use schema (#9610) - const doc = parseSingleYaml(replaceReferenceTags(content)); + const doc = parseSingleYaml(content); const includes = getAllIncludeProjects(doc); for (const includeObj of includes) { const dep = extractDepFromIncludeFile(includeObj); diff --git a/lib/modules/manager/gitlabci/common.spec.ts b/lib/modules/manager/gitlabci/common.spec.ts index 9c491ef848f968a..5f55bcdb4b83ec7 100644 --- a/lib/modules/manager/gitlabci/common.spec.ts +++ b/lib/modules/manager/gitlabci/common.spec.ts @@ -1,7 +1,6 @@ import { codeBlock } from 'common-tags'; import { parseSingleYaml } from '../../../util/yaml'; import type { GitlabPipeline } from '../gitlabci/types'; -import { replaceReferenceTags } from '../gitlabci/utils'; import { filterIncludeFromGitlabPipeline, isGitlabIncludeComponent, @@ -12,7 +11,7 @@ import { // TODO: use schema (#9610) const pipeline = parseSingleYaml( - replaceReferenceTags(codeBlock` + codeBlock` include: - project: mikebryant/include-source-example file: /template.yaml @@ -25,7 +24,7 @@ const pipeline = parseSingleYaml( script: - !reference [.setup, script] - - !reference [arbitrary job name with space and no starting dot, nested1, nested2, nested3]`), + - !reference [arbitrary job name with space and no starting dot, nested1, nested2, nested3]`, ); const includeLocal = { local: 'something' }; const includeProject = { project: 'something' }; @@ -37,7 +36,15 @@ describe('modules/manager/gitlabci/common', () => { const filtered_pipeline = filterIncludeFromGitlabPipeline(pipeline); expect(filtered_pipeline).not.toHaveProperty('include'); expect(filtered_pipeline).toEqual({ - script: [null, null], + script: [ + ['.setup', 'script'], + [ + 'arbitrary job name with space and no starting dot', + 'nested1', + 'nested2', + 'nested3', + ], + ], }); }); }); diff --git a/lib/modules/manager/gitlabci/utils.spec.ts b/lib/modules/manager/gitlabci/utils.spec.ts index 3c563ce93cbb932..0b89036dd8f5df4 100644 --- a/lib/modules/manager/gitlabci/utils.spec.ts +++ b/lib/modules/manager/gitlabci/utils.spec.ts @@ -1,6 +1,5 @@ -import { Fixtures } from '../../../../test/fixtures'; import type { PackageDependency } from '../types'; -import { getGitlabDep, replaceReferenceTags } from './utils'; +import { getGitlabDep } from './utils'; describe('modules/manager/gitlabci/utils', () => { describe('getGitlabDep', () => { @@ -82,12 +81,4 @@ describe('modules/manager/gitlabci/utils', () => { }); }); }); - - describe('replaceReferenceTags', () => { - it('replaces all !reference tags with empty strings', () => { - const yamlFileReferenceConfig = Fixtures.get('gitlab-ci.reference.yaml'); - const replaced = replaceReferenceTags(yamlFileReferenceConfig); - expect(replaced).not.toContain('!reference'); - }); - }); }); diff --git a/lib/modules/manager/gitlabci/utils.ts b/lib/modules/manager/gitlabci/utils.ts index e69552b2a61f69a..1a861897df735d3 100644 --- a/lib/modules/manager/gitlabci/utils.ts +++ b/lib/modules/manager/gitlabci/utils.ts @@ -2,19 +2,6 @@ import { regEx } from '../../../util/regex'; import { getDep } from '../dockerfile/extract'; import type { PackageDependency } from '../types'; -const re = /!reference \[[^\]]+\]/g; - -/** - * Replaces GitLab reference tags before parsing, because our yaml parser cannot process them anyway. - * @param content pipeline yaml - * @returns replaced pipeline content - * https://docs.gitlab.com/ee/ci/yaml/#reference-tags - */ -export function replaceReferenceTags(content: string): string { - const res = content.replace(re, ''); - return res; -} - const depProxyRe = regEx( `(?\\$\\{?CI_DEPENDENCY_PROXY_(?:DIRECT_)?GROUP_IMAGE_PREFIX\\}?/)(?.+)`, ); diff --git a/lib/util/yaml.spec.ts b/lib/util/yaml.spec.ts index de9491f458054a8..74f37c3e89f560e 100644 --- a/lib/util/yaml.spec.ts +++ b/lib/util/yaml.spec.ts @@ -281,5 +281,23 @@ describe('util/yaml', () => { }, }); }); + + it('should parse content with yaml tags', () => { + expect( + parseSingleYaml( + codeBlock` + myObject: + aString: value + aStringWithTag: !reset null + `, + { removeTemplates: true }, + ), + ).toEqual({ + myObject: { + aString: 'value', + aStringWithTag: 'null', + }, + }); + }); }); });