Skip to content

Commit

Permalink
feat(manager/gitlabci): support registry aliases (#28607)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
candrews and secustor authored Apr 24, 2024
1 parent 0ebd47a commit eb87cbb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
63 changes: 63 additions & 0 deletions lib/modules/manager/gitlabci/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,69 @@ describe('modules/manager/gitlabci/extract', () => {
expect(extractFromJob({ image: 'image:test' })).toEqual(expectedRes);
});

it('extracts component references via registry aliases', () => {
const registryAliases = {
$CI_SERVER_HOST: 'gitlab.example.com',
};
const content = codeBlock`
include:
- component: $CI_SERVER_HOST/an-org/a-project/[email protected]
inputs:
stage: build
- component: $CI_SERVER_HOST/an-org/a-subgroup/a-project/a-component@e3262fdd0914fa823210cdb79a8c421e2cef79d8
- component: $CI_SERVER_HOST/an-org/a-subgroup/another-project/a-component@main
- component: $CI_SERVER_HOST/another-org/a-project/a-component@~latest
inputs:
stage: test
- component: $CI_SERVER_HOST/malformed-component-reference
- component:
malformed: true
- component: $CI_SERVER_HOST/an-org/[email protected]
- component: other-gitlab.example.com/an-org/a-project/[email protected]
`;
const res = extractPackageFile(content, '', {
registryAliases,
});
expect(res?.deps).toMatchObject([
{
currentValue: '1.0',
datasource: 'gitlab-tags',
depName: 'an-org/a-project',
depType: 'repository',
registryUrls: ['https://gitlab.example.com'],
},
{
currentValue: 'e3262fdd0914fa823210cdb79a8c421e2cef79d8',
datasource: 'gitlab-tags',
depName: 'an-org/a-subgroup/a-project',
depType: 'repository',
registryUrls: ['https://gitlab.example.com'],
},
{
currentValue: 'main',
datasource: 'gitlab-tags',
depName: 'an-org/a-subgroup/another-project',
depType: 'repository',
registryUrls: ['https://gitlab.example.com'],
},
{
currentValue: '~latest',
datasource: 'gitlab-tags',
depName: 'another-org/a-project',
depType: 'repository',
registryUrls: ['https://gitlab.example.com'],
skipReason: 'unsupported-version',
},
{
currentValue: '1.0',
datasource: 'gitlab-tags',
depName: 'an-org/a-project',
depType: 'repository',
registryUrls: ['https://other-gitlab.example.com'],
},
]);
});

it('extracts component references', () => {
const content = codeBlock`
include:
Expand Down
10 changes: 9 additions & 1 deletion lib/modules/manager/gitlabci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function getAllIncludeComponents(

function extractDepFromIncludeComponent(
includeComponent: GitlabIncludeComponent,
registryAliases?: Record<string, string>,
): PackageDependency | null {
const componentReference = componentReferenceRegex.exec(
includeComponent.component,
Expand All @@ -139,6 +140,10 @@ function extractDepFromIncludeComponent(
);
return null;
}
const aliasValue = registryAliases?.[componentReference.fqdn];
if (aliasValue) {
componentReference.fqdn = aliasValue;
}

const dep: PackageDependency = {
datasource: GitlabTagsDatasource.id,
Expand Down Expand Up @@ -209,7 +214,10 @@ export function extractPackageFile(

const includedComponents = getAllIncludeComponents(doc);
for (const includedComponent of includedComponents) {
const dep = extractDepFromIncludeComponent(includedComponent);
const dep = extractDepFromIncludeComponent(
includedComponent,
config.registryAliases,
);
if (dep) {
deps.push(dep);
}
Expand Down

0 comments on commit eb87cbb

Please sign in to comment.