Skip to content

Commit

Permalink
fix: reduce code issues (#8639)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Korn <charleskorn@users.noreply.github.com>
  • Loading branch information
viceice and charleskorn committed Feb 11, 2021
1 parent 1a9e543 commit 6cc2e50
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@ FROM\
COPY --from=image6 /path/1 /path/2

COPY \
# comment1
--from=image7:1.0.0@sha256:abcdef \
/path/1 \
/path/2

# COPY --from=image8

COPY --from=image9

COPY\
--chown=root \
# comment1
#
#comment2
--from=image10
# comment2
path1 path2

COPY --chown=root --from=image11 / ./

COPY \
Expand Down
18 changes: 0 additions & 18 deletions lib/manager/dockerfile/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ Array [
"depType": "stage",
"replaceString": "image7:1.0.0@sha256:abcdef",
},
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
"currentValue": undefined,
"datasource": "docker",
"depName": "image9",
"depType": "stage",
"replaceString": "image9",
},
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
"currentValue": undefined,
"datasource": "docker",
"depName": "image10",
"depType": "stage",
"replaceString": "image10",
},
Object {
"autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}",
"currentDigest": undefined,
Expand Down
6 changes: 3 additions & 3 deletions lib/manager/dockerfile/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { readFileSync } from 'fs';
import { extractPackageFile, getDep } from './extract';

const d1 = readFileSync(
'lib/manager/dockerfile/__fixtures__/Dockerfile1',
'lib/manager/dockerfile/__fixtures__/1.Dockerfile',
'utf8'
);

const d2 = readFileSync(
'lib/manager/dockerfile/__fixtures__/Dockerfile2',
'lib/manager/dockerfile/__fixtures__/2.Dockerfile',
'utf8'
);

Expand Down Expand Up @@ -150,7 +150,7 @@ describe('lib/manager/dockerfile/extract', () => {
it('extracts images from all sorts of (maybe multiline) FROM and COPY --from statements', () => {
const res = extractPackageFile(d2).deps;
expect(res).toMatchSnapshot();
expect(res).toHaveLength(11);
expect(res).toHaveLength(9);
});
it('handles calico/node', () => {
const res = extractPackageFile('FROM calico/node\n').deps;
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/dockerfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function extractPackageFile(content: string): PackageFile | null {
const stageNames: string[] = [];

const fromMatches = content.matchAll(
/^[ \t]*FROM(?:\\\r?\n| |\t|#.*\r?\n|-\S+)+(?<image>\S+)(?:(?:\\\r?\n| |\t|#.*\r?\n)+as[ \t]+(?<name>\S+))?/gim
/^[ \t]*FROM(?:\\\r?\n| |\t|#.*?\r?\n|[ \t]--[a-z]+=\w+?)*[ \t](?<image>\S+)(?:(?:\\\r?\n| |\t|#.*\r?\n)+as[ \t]+(?<name>\S+))?/gim
);

for (const fromMatch of fromMatches) {
Expand All @@ -94,7 +94,7 @@ export function extractPackageFile(content: string): PackageFile | null {
}

const copyFromMatches = content.matchAll(
/^[ \t]*COPY(?:\\\r?\n| |\t|#.*\r?\n|-\S+)+--from=(?<image>\S+)/gim
/^[ \t]*COPY(?:\\\r?\n| |\t|#.*\r?\n|[ \t]--[a-z]+=\w+?)*[ \t]--from=(?<image>\S+)/gim
);

for (const copyFromMatch of copyFromMatches) {
Expand Down
1 change: 1 addition & 0 deletions lib/manager/gradle-lite/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('manager/gradle-lite/utils', () => {
expect(isDependencyString("foo:bar:1.2.3'")).toBe(false);
expect(isDependencyString('foo:bar:1.2.3"')).toBe(false);
expect(isDependencyString('-Xep:ParameterName:OFF')).toBe(false);
expect(isDependencyString('foo$bar:baz:1.2.+')).toBe(false);
});

it('parseDependencyString', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/gradle-lite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './common';

const artifactRegex = regEx(
'^[a-zA-Z][-_a-zA-Z0-9]*(?:.[a-zA-Z0-9][-_a-zA-Z0-9]*)*$'
'^[a-zA-Z][-_a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-_a-zA-Z0-9]*?)*$'
);

const versionLikeRegex = regEx('^(?<version>[-.\\[\\](),a-zA-Z0-9+]+)');
Expand Down

0 comments on commit 6cc2e50

Please sign in to comment.