diff --git a/lib/modules/manager/gitlabci/common.ts b/lib/modules/manager/gitlabci/common.ts index 38452d1b50..9daf9f207b 100644 --- a/lib/modules/manager/gitlabci/common.ts +++ b/lib/modules/manager/gitlabci/common.ts @@ -37,5 +37,5 @@ export function isGitlabIncludeLocal( export function isGitlabIncludeComponent( include: GitlabInclude, ): include is GitlabIncludeComponent { - return !is.undefined((include as GitlabIncludeComponent).component); + return is.string((include as GitlabIncludeComponent).component); } diff --git a/lib/modules/manager/gitlabci/extract.spec.ts b/lib/modules/manager/gitlabci/extract.spec.ts index 84ab81e28c..750273089e 100644 --- a/lib/modules/manager/gitlabci/extract.spec.ts +++ b/lib/modules/manager/gitlabci/extract.spec.ts @@ -231,6 +231,7 @@ describe('modules/manager/gitlabci/extract', () => { it('extract images via registry aliases', () => { const registryAliases = { $CI_REGISTRY: 'registry.com', + $BUILD_IMAGES: 'registry.com/build-images', foo: 'foo.registry.com', }; const res = extractPackageFile( @@ -242,6 +243,7 @@ describe('modules/manager/gitlabci/extract', () => { - foo/mariadb:10.4.11 - name: $CI_REGISTRY/other/image1:1.0.0 alias: imagealias1 + - $BUILD_IMAGES/image2:1.0.0 `, '', { @@ -279,6 +281,16 @@ describe('modules/manager/gitlabci/extract', () => { depType: 'service-image', replaceString: '$CI_REGISTRY/other/image1:1.0.0', }, + { + autoReplaceStringTemplate: + '$BUILD_IMAGES/image2:{{#if newValue}}{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}', + currentDigest: undefined, + currentValue: '1.0.0', + datasource: 'docker', + depName: 'registry.com/build-images/image2', + depType: 'service-image', + replaceString: '$BUILD_IMAGES/image2:1.0.0', + }, ]); }); @@ -357,6 +369,7 @@ describe('modules/manager/gitlabci/extract', () => { it('extracts component references via registry aliases', () => { const registryAliases = { $CI_SERVER_HOST: 'gitlab.example.com', + $COMPONENT_REGISTRY: 'gitlab.example.com/a-group', }; const content = codeBlock` include: @@ -373,6 +386,7 @@ describe('modules/manager/gitlabci/extract', () => { malformed: true - component: $CI_SERVER_HOST/an-org/a-component@1.0 - component: other-gitlab.example.com/an-org/a-project/a-component@1.0 + - component: $COMPONENT_REGISTRY/a-project/a-component@1.0 `; const res = extractPackageFile(content, '', { registryAliases, @@ -414,6 +428,13 @@ describe('modules/manager/gitlabci/extract', () => { depType: 'repository', registryUrls: ['https://other-gitlab.example.com'], }, + { + currentValue: '1.0', + datasource: 'gitlab-tags', + depName: 'a-group/a-project', + depType: 'repository', + registryUrls: ['https://gitlab.example.com'], + }, ]); }); diff --git a/lib/modules/manager/gitlabci/extract.ts b/lib/modules/manager/gitlabci/extract.ts index d00ca9c868..09e4ba195e 100644 --- a/lib/modules/manager/gitlabci/extract.ts +++ b/lib/modules/manager/gitlabci/extract.ts @@ -122,12 +122,16 @@ function extractDepFromIncludeComponent( includeComponent: GitlabIncludeComponent, registryAliases?: Record, ): PackageDependency | null { - const componentReference = componentReferenceRegex.exec( - includeComponent.component, - )?.groups; + let componentUrl = includeComponent.component; + if (registryAliases) { + for (const key in registryAliases) { + componentUrl = componentUrl.replace(key, registryAliases[key]); + } + } + const componentReference = componentReferenceRegex.exec(componentUrl)?.groups; if (!componentReference) { logger.debug( - { componentReference: includeComponent.component }, + { componentReference: componentUrl }, 'Ignoring malformed component reference', ); return null; @@ -135,15 +139,11 @@ function extractDepFromIncludeComponent( const projectPathParts = componentReference.projectPath.split('/'); if (projectPathParts.length < 2) { logger.debug( - { componentReference: includeComponent.component }, + { componentReference: componentUrl }, 'Ignoring component reference with incomplete project path', ); return null; } - const aliasValue = registryAliases?.[componentReference.fqdn]; - if (aliasValue) { - componentReference.fqdn = aliasValue; - } const dep: PackageDependency = { datasource: GitlabTagsDatasource.id,