Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/gitlab-include): support multi-document package files #31686

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/modules/manager/gitlabci-include/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import { extractPackageFile } from '.';
Expand Down Expand Up @@ -68,5 +69,38 @@ describe('modules/manager/gitlabci-include/extract', () => {
expect(res?.deps[0].registryUrls).toEqual(['http://gitlab.test']);
}
});

it('supports multi-document files', () => {
const multiDocFile = codeBlock`
other:
content: to be ignored
---
include:
- project: mikebryant/include-source-example
ref: 1.0.0
---
include:
- project: mikebryant/include-source-example2
ref: 2.0.0
---
more:
content: to be ignored
viceice marked this conversation as resolved.
Show resolved Hide resolved
`;
const res = extractPackageFile(multiDocFile);
expect(res).toMatchObject({
deps: [
{
currentValue: '1.0.0',
datasource: 'gitlab-tags',
depName: 'mikebryant/include-source-example',
},
{
currentValue: '2.0.0',
datasource: 'gitlab-tags',
depName: 'mikebryant/include-source-example2',
},
],
});
});
});
});
26 changes: 18 additions & 8 deletions lib/modules/manager/gitlabci-include/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger';
import { regEx } from '../../../util/regex';
import { parseSingleYaml } from '../../../util/yaml';
import { parseYaml } from '../../../util/yaml';
import { GitlabTagsDatasource } from '../../datasource/gitlab-tags';
import {
filterIncludeFromGitlabPipeline,
Expand Down Expand Up @@ -70,16 +70,26 @@ export function extractPackageFile(
const deps: PackageDependency[] = [];
const platform = GlobalConfig.get('platform');
const endpoint = GlobalConfig.get('endpoint');
const registryUrls =
platform === 'gitlab' && endpoint
? [endpoint.replace(regEx(/\/api\/v4\/?/), '')]
: null;
try {
// TODO: use schema (#9610)
const doc = parseSingleYaml<GitlabPipeline>(replaceReferenceTags(content));
const includes = getAllIncludeProjects(doc);
for (const includeObj of includes) {
const dep = extractDepFromIncludeFile(includeObj);
if (platform === 'gitlab' && endpoint) {
dep.registryUrls = [endpoint.replace(regEx(/\/api\/v4\/?/), '')];
const docs = parseYaml<GitlabPipeline>(replaceReferenceTags(content), {
uniqueKeys: false,
});
for (const doc of docs) {
if (is.object(doc)) {
const includes = getAllIncludeProjects(doc);
for (const includeObj of includes) {
const dep = extractDepFromIncludeFile(includeObj);
if (registryUrls) {
dep.registryUrls = registryUrls;
}
deps.push(dep);
}
}
deps.push(dep);
}
} catch (err) /* istanbul ignore next */ {
if (err.stack?.startsWith('YAMLException:')) {
Expand Down