Skip to content

Commit 4509387

Browse files
committed
PR cleanup
1 parent e2d3b28 commit 4509387

8 files changed

Lines changed: 58 additions & 32 deletions

File tree

languageservice/src/context-providers/env.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {data, DescriptionDictionary} from "@actions/expressions";
22
import {isScalar, isString} from "@actions/workflow-parser";
3-
import {isExecutableStep} from "@actions/workflow-parser/model/type-guards";
43
import {MappingToken} from "@actions/workflow-parser/templates/tokens/mapping-token";
54
import {WorkflowContext} from "../context/workflow-context.js";
65

76
export function getEnvContext(workflowContext: WorkflowContext): DescriptionDictionary {
87
const d = new DescriptionDictionary();
98

109
//step env
11-
if (workflowContext.step && isExecutableStep(workflowContext.step) && workflowContext.step.env) {
10+
if (workflowContext.step && "env" in workflowContext.step && workflowContext.step.env) {
1211
envContext(workflowContext.step.env, d);
1312
}
1413

languageservice/src/validate.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
run: npm start
3030
background: true
3131
- wait: server
32+
continue-on-error: true
3233
- wait-all:
34+
continue-on-error: false
3335
- cancel: server`
3436
)
3537
);

workflow-parser/src/model/convert.test.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import {nullTrace} from "../test-utils/null-trace.js";
33
import {parseWorkflow} from "../workflows/workflow-parser.js";
44
import {convertWorkflowTemplate, ErrorPolicy} from "./convert.js";
5-
import {isExecutableStep} from "./type-guards.js";
65

76
function serializeTemplate(template: unknown): unknown {
87
return JSON.parse(JSON.stringify(template));
@@ -494,13 +493,14 @@ jobs:
494493
const job = template.jobs[0];
495494
expect(job.type).toBe("job");
496495
if (job.type === "job") {
497-
expect(isExecutableStep(job.steps[0])).toBe(true);
498-
expect(isExecutableStep(job.steps[1])).toBe(true);
499-
expect(isExecutableStep(job.steps[2])).toBe(true);
500-
if (isExecutableStep(job.steps[0]) && isExecutableStep(job.steps[1]) && isExecutableStep(job.steps[2])) {
501-
expect(job.steps[0].if?.expression).toBe("Success()");
502-
expect(job.steps[1].if?.expression).toBe("FAILURE()");
503-
expect(job.steps[2].if?.expression).toBe("Cancelled() || Always()");
496+
const [firstStep, secondStep, thirdStep] = job.steps;
497+
expect("if" in firstStep).toBe(true);
498+
expect("if" in secondStep).toBe(true);
499+
expect("if" in thirdStep).toBe(true);
500+
if ("if" in firstStep && "if" in secondStep && "if" in thirdStep) {
501+
expect(firstStep.if?.expression).toBe("Success()");
502+
expect(secondStep.if?.expression).toBe("FAILURE()");
503+
expect(thirdStep.if?.expression).toBe("Cancelled() || Always()");
504504
}
505505
}
506506
});
@@ -543,11 +543,12 @@ jobs:
543543
expect(job2.if?.expression).toBe("success()");
544544

545545
if (job2.type === "job") {
546-
expect(isExecutableStep(job2.steps[0])).toBe(true);
547-
expect(isExecutableStep(job2.steps[1])).toBe(true);
548-
if (isExecutableStep(job2.steps[0]) && isExecutableStep(job2.steps[1])) {
549-
expect(job2.steps[0].if?.expression).toBe("success()");
550-
expect(job2.steps[1].if?.expression).toBe("success()");
546+
const [firstStep, secondStep] = job2.steps;
547+
expect("if" in firstStep).toBe(true);
548+
expect("if" in secondStep).toBe(true);
549+
if ("if" in firstStep && "if" in secondStep) {
550+
expect(firstStep.if?.expression).toBe("success()");
551+
expect(secondStep.if?.expression).toBe("success()");
551552
}
552553
}
553554
});
@@ -582,13 +583,14 @@ jobs:
582583
const job = template.jobs[0];
583584
expect(job.type).toBe("job");
584585
if (job.type === "job") {
585-
expect(isExecutableStep(job.steps[0])).toBe(true);
586-
expect(isExecutableStep(job.steps[1])).toBe(true);
587-
expect(isExecutableStep(job.steps[2])).toBe(true);
588-
if (isExecutableStep(job.steps[0]) && isExecutableStep(job.steps[1]) && isExecutableStep(job.steps[2])) {
589-
expect(job.steps[0].if?.expression).toBe("success().outputs.result");
590-
expect(job.steps[1].if?.expression).toBe("failure().outputs.value");
591-
expect(job.steps[2].if?.expression).toBe("always() && steps.test.outcome");
586+
const [firstStep, secondStep, thirdStep] = job.steps;
587+
expect("if" in firstStep).toBe(true);
588+
expect("if" in secondStep).toBe(true);
589+
expect("if" in thirdStep).toBe(true);
590+
if ("if" in firstStep && "if" in secondStep && "if" in thirdStep) {
591+
expect(firstStep.if?.expression).toBe("success().outputs.result");
592+
expect(secondStep.if?.expression).toBe("failure().outputs.value");
593+
expect(thirdStep.if?.expression).toBe("always() && steps.test.outcome");
592594
}
593595
}
594596
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function convertStep(context: TemplateContext, idBuilder: IdBuilder, step: Templ
148148
return {
149149
id: id?.value || "",
150150
name: name || createSyntheticStepName("Wait"),
151+
"continue-on-error": continueOnError,
151152
wait
152153
};
153154
}
@@ -156,6 +157,7 @@ function convertStep(context: TemplateContext, idBuilder: IdBuilder, step: Templ
156157
return {
157158
id: id?.value || "",
158159
name: name || createSyntheticStepName("Wait for all"),
160+
"continue-on-error": continueOnError,
159161
"wait-all": waitAll
160162
};
161163
}

workflow-parser/src/model/type-guards.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ export function isActionStep(step: Step): step is ActionStep {
88
return (step as ActionStep).uses !== undefined;
99
}
1010

11-
export function isExecutableStep(step: Step): step is RunStep | ActionStep {
12-
return isRunStep(step) || isActionStep(step);
13-
}
14-
1511
export function isJob(job: WorkflowJob): job is Job {
1612
return job.type === "job";
1713
}

workflow-parser/src/model/workflow-template.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ export type ActionStep = ExecutableStep & {
107107
background?: boolean;
108108
};
109109

110-
export type WaitStep = BaseStep & {
110+
type ContinueOnErrorStep = BaseStep & {
111+
"continue-on-error"?: boolean | ScalarToken;
112+
};
113+
114+
export type WaitStep = ContinueOnErrorStep & {
111115
wait: StringToken[];
112116
};
113117

114-
export type WaitAllStep = BaseStep & {
118+
export type WaitAllStep = ContinueOnErrorStep & {
115119
"wait-all": boolean;
116120
};
117121

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,7 @@
21892189
"properties": {
21902190
"name": "step-name",
21912191
"id": "step-id",
2192+
"continue-on-error": "step-continue-on-error",
21922193
"wait": {
21932194
"type": "step-wait-target",
21942195
"required": true
@@ -2201,6 +2202,7 @@
22012202
"properties": {
22022203
"name": "step-name",
22032204
"id": "step-id",
2205+
"continue-on-error": "step-continue-on-error",
22042206
"wait-all": {
22052207
"type": "step-wait-all-value",
22062208
"required": true

workflow-parser/testdata/reader/step-continue-on-error.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ jobs:
55
build:
66
runs-on: ubuntu-latest
77
steps:
8-
- run: exit 2
8+
- id: build
9+
run: exit 2
910
continue-on-error: true
1011
- run: exit 1
1112
continue-on-error: false
13+
- wait: build
14+
continue-on-error: true
15+
- wait-all:
16+
continue-on-error: false
1217
- run: exit 1
1318
---
1419
{
@@ -24,7 +29,7 @@ jobs:
2429
"runs-on": "ubuntu-latest",
2530
"steps": [
2631
{
27-
"id": "__run",
32+
"id": "build",
2833
"if": {
2934
"type": 3,
3035
"expr": "success()"
@@ -33,7 +38,7 @@ jobs:
3338
"run": "exit 2"
3439
},
3540
{
36-
"id": "__run_2",
41+
"id": "__run",
3742
"if": {
3843
"type": 3,
3944
"expr": "success()"
@@ -42,7 +47,21 @@ jobs:
4247
"run": "exit 1"
4348
},
4449
{
45-
"id": "__run_3",
50+
"id": "__wait",
51+
"name": "Wait",
52+
"continue-on-error": true,
53+
"wait": [
54+
"build"
55+
]
56+
},
57+
{
58+
"id": "__wait-all",
59+
"name": "Wait for all",
60+
"continue-on-error": false,
61+
"wait-all": true
62+
},
63+
{
64+
"id": "__run_2",
4665
"if": {
4766
"type": 3,
4867
"expr": "success()"

0 commit comments

Comments
 (0)