Skip to content

Commit a92bf9e

Browse files
committed
Add validation for empty container image
1 parent fb5c6e4 commit a92bf9e

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

workflow-parser/src/model/converter/container.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export function convertToJobContainer(context: TemplateContext, container: Templ
2121
if (isString(container)) {
2222
// Workflow uses shorthand syntax `container: image-name`
2323
image = container.assertString("container item");
24+
if (!image || image.value.length === 0) {
25+
context.error(container, "Container image cannot be empty");
26+
return;
27+
}
2428
return {image: image};
2529
}
2630

@@ -63,7 +67,7 @@ export function convertToJobContainer(context: TemplateContext, container: Templ
6367
}
6468
}
6569

66-
if (!image) {
70+
if (!image || image.value.length === 0) {
6771
context.error(container, "Container image cannot be empty");
6872
} else {
6973
return {image, env, ports, volumes, options};

workflow-parser/src/model/converter/job.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function convertJob(context: TemplateContext, jobKey: StringToken, token:
5050
break;
5151

5252
case "container":
53-
convertToJobContainer(context, item.value);
53+
handleTemplateTokenErrors(item.value, context, undefined, () => convertToJobContainer(context, item.value));
5454
container = item.value;
5555
break;
5656

@@ -103,7 +103,7 @@ export function convertJob(context: TemplateContext, jobKey: StringToken, token:
103103
break;
104104

105105
case "services":
106-
convertToJobServices(context, item.value);
106+
handleTemplateTokenErrors(item.value, context, undefined, () => convertToJobServices(context, item.value));
107107
services = item.value;
108108
break;
109109

workflow-parser/src/workflow-v1.0.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@
23452345
"mapping": {
23462346
"properties": {
23472347
"image": {
2348-
"type": "non-empty-string",
2348+
"type": "string",
23492349
"description": "Use `jobs.<job_id>.container.image` to define the Docker image to use as the container to run the action. The value can be the Docker Hub image or a registry name."
23502350
},
23512351
"options": {
@@ -2390,7 +2390,7 @@
23902390
"matrix"
23912391
],
23922392
"one-of": [
2393-
"non-empty-string",
2393+
"string",
23942394
"container-mapping"
23952395
]
23962396
},
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
include-source: false # Drop file/line/col from output
2+
---
3+
on: push
4+
jobs:
5+
build1:
6+
runs-on: linux
7+
container: ""
8+
steps:
9+
- run: echo hi
10+
build2:
11+
runs-on: linux
12+
container:
13+
image: ""
14+
steps:
15+
- run: echo hi
16+
build3:
17+
runs-on: linux
18+
services:
19+
svc: ""
20+
steps:
21+
- run: echo hi
22+
build4:
23+
runs-on: linux
24+
services:
25+
svc:
26+
image: ""
27+
steps:
28+
- run: echo hi
29+
build5:
30+
runs-on: linux
31+
container:
32+
steps:
33+
- run: echo hi
34+
build6:
35+
runs-on: linux
36+
services:
37+
svc:
38+
steps:
39+
- run: echo hi
40+
---
41+
{
42+
"errors": [
43+
{
44+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 5, Col: 16): Container image cannot be empty"
45+
},
46+
{
47+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 11, Col: 7): Container image cannot be empty"
48+
},
49+
{
50+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 17, Col: 12): Container image cannot be empty"
51+
},
52+
{
53+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 24, Col: 9): Container image cannot be empty"
54+
},
55+
{
56+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 29, Col: 15): Container image cannot be empty"
57+
},
58+
{
59+
"Message": ".github/workflows/job-container-empty-image.yml (Line: 35, Col: 11): Container image cannot be empty"
60+
}
61+
]
62+
}

workflow-parser/testdata/reader/job-container-invalid.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ jobs:
3636
{
3737
"Message": ".github/workflows/job-container-invalid.yml (Line: 8, Col: 9): Unexpected value 'badkey'"
3838
},
39-
{
40-
"Message": ".github/workflows/job-container-invalid.yml (Line: 14, Col: 13): Unexpected value ''"
41-
},
4239
{
4340
"Message": ".github/workflows/job-container-invalid.yml (Line: 21, Col: 9): Unexpected value 'badkey'"
44-
},
45-
{
46-
"Message": ".github/workflows/job-container-invalid.yml (Line: 28, Col: 15): Unexpected value ''"
4741
}
4842
]
4943
}

0 commit comments

Comments
 (0)