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

fix(gitlabci): Update local include files #8810

Merged
merged 3 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/manager/gitlabci-include/__fixtures__/gitlab-ci.2.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions lib/manager/gitlabci-include/__fixtures__/gitlab-ci.3.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions lib/manager/gitlabci-include/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib/manager/gitlabci-include/extract extractPackageFile() extracts local include block 1`] = `
Array [
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
"currentValue": "3.11",
"datasource": "docker",
"depName": "alpine",
"depType": "image",
"replaceString": "alpine:3.11",
},
]
`;

exports[`lib/manager/gitlabci-include/extract extractPackageFile() extracts multiple include blocks 1`] = `
Array [
Object {
Expand All @@ -36,27 +22,3 @@ Array [
},
]
`;

exports[`lib/manager/gitlabci-include/extract extractPackageFile() extracts multiple local include blocks 1`] = `
Array [
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
"currentValue": "3.11",
"datasource": "docker",
"depName": "alpine",
"depType": "image",
"replaceString": "alpine:3.11",
},
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"commitMessageTopic": "Node.js",
"currentDigest": undefined,
"currentValue": "12",
"datasource": "docker",
"depName": "node",
"depType": "image",
"replaceString": "node:12",
},
]
`;
35 changes: 6 additions & 29 deletions lib/manager/gitlabci-include/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,27 @@ const yamlFile = fs.readFileSync(
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.1.yaml',
'utf8'
);
const yamlLocal = fs.readFileSync(
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.2.yaml',
'utf8'
);

const yamlLocalBlock = fs.readFileSync(
'lib/manager/gitlabci-include/__fixtures__/gitlab-ci.3.yaml',
'utf8'
);

describe('lib/manager/gitlabci-include/extract', () => {
describe('extractPackageFile()', () => {
it('returns null for empty', async () => {
it('returns null for empty', () => {
expect(
await extractPackageFile('nothing here', '.gitlab-ci.yml', {})
extractPackageFile('nothing here', '.gitlab-ci.yml', {})
).toBeNull();
});
it('extracts multiple include blocks', async () => {
const res = await extractPackageFile(yamlFile, '.gitlab-ci.yml', {});
it('extracts multiple include blocks', () => {
const res = extractPackageFile(yamlFile, '.gitlab-ci.yml', {});
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(3);
});
it('extracts local include block', async () => {
const res = await extractPackageFile(yamlLocal, '.gitlab-ci.yml', {});
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(1);
});
it('extracts multiple local include blocks', async () => {
const res = await extractPackageFile(
yamlLocalBlock,
'.gitlab-ci.yml',
{}
);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(2);
});
it('normalizes configured endpoints', async () => {
it('normalizes configured endpoints', () => {
const endpoints = [
'http://gitlab.test/api/v4',
'http://gitlab.test/api/v4/',
];

for (const endpoint of endpoints) {
const res = await extractPackageFile(yamlFile, '.gitlab-ci.yml', {
const res = extractPackageFile(yamlFile, '.gitlab-ci.yml', {
endpoint,
});
expect(res.deps[0].registryUrls[0]).toEqual('http://gitlab.test');
Expand Down
21 changes: 2 additions & 19 deletions lib/manager/gitlabci-include/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import yaml from 'js-yaml';
import * as datasourceGitlabTags from '../../datasource/gitlab-tags';
import { logger } from '../../logger';
import { SkipReason } from '../../types';
import { readLocalFile } from '../../util/fs';
import * as gitlabci from '../gitlabci/extract';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';

function extractDepFromIncludeFile(includeObj: {
Expand All @@ -25,19 +23,11 @@ function extractDepFromIncludeFile(includeObj: {
return dep;
}

async function extractDepsFromIncludeLocal(includeObj: {
local: string;
}): Promise<PackageDependency[] | null> {
const content = await readLocalFile(includeObj.local, 'utf8');
const deps = gitlabci.extractPackageFile(content)?.deps;
return deps;
}

export async function extractPackageFile(
export function extractPackageFile(
content: string,
_packageFile: string,
config: ExtractConfig
): Promise<PackageFile | null> {
): PackageFile | null {
const deps: PackageDependency[] = [];
try {
// TODO: fix me
Expand All @@ -50,13 +40,6 @@ export async function extractPackageFile(
dep.registryUrls = [config.endpoint.replace(/\/api\/v4\/?/, '')];
}
deps.push(dep);
} else if (includeObj.local) {
const includedDeps = await extractDepsFromIncludeLocal(includeObj);
if (includedDeps) {
for (const includedDep of includedDeps) {
deps.push(includedDep);
}
}
}
}
}
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions lib/manager/gitlabci/__fixtures__/gitlab-ci.3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
image:
# comment
name: renovate/renovate:19.70.8-slim

services:
# comment
- mariadb:10.4.11
# another comment
- other/image:1.0.0

include:
- local: 'lib/manager/gitlabci/__fixtures__/include.yml'
- local: 'lib/manager/gitlabci/__fixtures__/include.1.yml'
5 changes: 5 additions & 0 deletions lib/manager/gitlabci/__fixtures__/include.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
stage: test
image: node:12
script:
- echo test
5 changes: 5 additions & 0 deletions lib/manager/gitlabci/__fixtures__/include.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
stage: test
image: alpine:3.11
script:
- echo test