From 354e6f866c1e25bece64068ad54ee2fa0ccf2d90 Mon Sep 17 00:00:00 2001 From: Timo Webler Date: Fri, 4 Oct 2024 15:50:05 +0200 Subject: [PATCH] refactor(manager/gitlabci): remove method "replaceReferenceTags" (#31787) --- lib/modules/manager/gitlabci-include/extract.ts | 3 +-- lib/modules/manager/gitlabci/common.spec.ts | 15 +++++++++++---- lib/modules/manager/gitlabci/utils.spec.ts | 11 +---------- lib/modules/manager/gitlabci/utils.ts | 13 ------------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/lib/modules/manager/gitlabci-include/extract.ts b/lib/modules/manager/gitlabci-include/extract.ts index 026f51e80760a9..60eb93772a183a 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( @@ -76,7 +75,7 @@ export function extractPackageFile( : null; try { // TODO: use schema (#9610) - const docs = parseYaml(replaceReferenceTags(content), { + const docs = parseYaml(content, { uniqueKeys: false, }); for (const doc of docs) { diff --git a/lib/modules/manager/gitlabci/common.spec.ts b/lib/modules/manager/gitlabci/common.spec.ts index 9c491ef848f968..5f55bcdb4b83ec 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 3c563ce93cbb93..0b89036dd8f5df 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 e69552b2a61f69..1a861897df735d 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\\}?/)(?.+)`, );