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(droneci): support for multiline string image dependency #15578

Merged
merged 2 commits into from
May 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/modules/manager/droneci/__fixtures__/.drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ services:
image: redis:alpine
ports:
- 6379

- name: node
image: "amd64/node:10.0.0\
@sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201"
commands:
- npm install
- npm test

- name: node
image: 'amd64/node\
:10.0.0\
@sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201'
commands:
- npm install
- npm test
23 changes: 23 additions & 0 deletions lib/modules/manager/droneci/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,28 @@ Array [
"depType": "docker",
"replaceString": "redis:alpine",
},
Object {
"autoReplaceStringTemplate": "{{packageName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": "sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201",
"currentValue": "10.0.0",
"datasource": "docker",
"depName": "node",
"depType": "docker",
"packageName": "amd64/node",
"replaceString": "\\\"amd64/node:10.0.0\\\\
@sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201\\\"",
},
Object {
"autoReplaceStringTemplate": "{{packageName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": "sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201",
"currentValue": "10.0.0",
"datasource": "docker",
"depName": "node",
"depType": "docker",
"packageName": "amd64/node",
"replaceString": "'amd64/node\\\\
:10.0.0\\\\
@sha256:36adc17e9cceab32179d3314da9cb9c737ffb11f0de4e688f407ad6d9ca32201'",
},
]
`;
2 changes: 1 addition & 1 deletion lib/modules/manager/droneci/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('modules/manager/droneci/extract', () => {
it('extracts multiple image lines', () => {
const res = extractPackageFile(Fixtures.get('.drone.yml'));
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(4);
expect(res.deps).toHaveLength(6);
});
});
});
52 changes: 38 additions & 14 deletions lib/modules/manager/droneci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,44 @@ export function extractPackageFile(content: string): PackageFile | null {
const lines = content.split(newlineRegex);
for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
const line = lines[lineNumber];
const match = regEx(/^\s* image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line);
if (match) {
const currentFrom = match[1];
const dep = getDep(currentFrom);
logger.debug(
{
depName: dep.depName,
currentValue: dep.currentValue,
currentDigest: dep.currentDigest,
},
'DroneCI docker image'
);
dep.depType = 'docker';
deps.push(dep);

const first_line_match = regEx(/^\s* image:\s*(['"]([^\s'"]+)\\)$/).exec(
line
);
if (first_line_match) {
let currentFrom = first_line_match[2];
let replaceString = first_line_match[1];

for (let i = lineNumber + 1; i < lines.length; i += 1) {
const internal_line = lines[i];
const middle_line_match =
regEx(/^(\s*([^\s'"]+)\\)$/).exec(internal_line);
if (middle_line_match) {
currentFrom += middle_line_match[2];
replaceString += '\n' + middle_line_match[1];
} else {
const final_line_match = regEx(/^(\s*([^\s'"]+)['"])$/).exec(
internal_line
);
if (final_line_match) {
currentFrom += final_line_match[2];
replaceString += '\n' + final_line_match[1];

const dep = getDep(currentFrom);
dep.depType = 'docker';
dep.replaceString = replaceString;
deps.push(dep);
}
break;
}
}
} else {
const match = regEx(/^\s* image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line);
if (match) {
const dep = getDep(match[1]);
dep.depType = 'docker';
deps.push(dep);
}
}
}
} catch (err) /* istanbul ignore next */ {
Expand Down