Skip to content

Commit

Permalink
fix(manager/gitlabci): support alias with a path in component URL (#2…
Browse files Browse the repository at this point in the history
…9707)

Co-authored-by: marco <marco@mybit.nl>
  • Loading branch information
marcovmun and marco-mybit committed Aug 16, 2024
1 parent 2a7f88e commit 59cd325
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/modules/manager/gitlabci/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
21 changes: 21 additions & 0 deletions lib/modules/manager/gitlabci/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
`,
'',
{
Expand Down Expand Up @@ -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',
},
]);
});

Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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'],
},
]);
});

Expand Down
18 changes: 9 additions & 9 deletions lib/modules/manager/gitlabci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,28 @@ function extractDepFromIncludeComponent(
includeComponent: GitlabIncludeComponent,
registryAliases?: Record<string, string>,
): 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;
}
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,
Expand Down

0 comments on commit 59cd325

Please sign in to comment.