Skip to content

Commit

Permalink
fix(manager/gitlabci): Update local include files
Browse files Browse the repository at this point in the history
If local files are imported from the GitLab CI YAML file, the
dependencies will be recognized but not updated by renovate.
Renovate needs to respect the 'include:local' imports and update the
depedependencies in those files.

`extractPackageFile` is replaced by `extractAllPackageFiles` since the
functionality of those two functions are the same.

Related to renovatebot#6745
Fixes renovatebot#6713
  • Loading branch information
l0nax committed Feb 22, 2021
1 parent 9171e71 commit 2136973
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 208 deletions.
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
@@ -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
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
Expand Up @@ -3,9 +3,7 @@ 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 { ExtractConfig, PackageDependency, PackageFile } from '../common';
import * as gitlabci from '../gitlabci/extract';

function extractDepFromIncludeFile(includeObj: {
file: any;
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
@@ -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
@@ -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
@@ -0,0 +1,5 @@
test:
stage: test
image: alpine:3.11
script:
- echo test

0 comments on commit 2136973

Please sign in to comment.