Skip to content

Commit 9c47bd2

Browse files
authored
feat(run): Support continue-on-error (#32)
* fix: Define Expression type * fix: Added the ability to specify an Expression for cancelInProgress * feat(run): Support continue-on-error
1 parent 303912d commit 9c47bd2

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "ghats/../.ghats/action.js";
22
export * from "./package/concurrency";
3+
export * from "./package/expression";
34
export * from "./package/job";
45
export * from "./package/on";
56
export * from "./package/permissions";

lib/package/concurrency.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe("concurrencyJSON", () => {
1212
{ group: "group", cancelInProgress: false },
1313
{ group: "group", "cancel-in-progress": false },
1414
],
15+
[
16+
{ group: "group", cancelInProgress: "${{ foo }}" },
17+
{ group: "group", "cancel-in-progress": "${{ foo }}" },
18+
],
1519
])("concurrencyJSON(%j) returns %j", (input, expected) => {
1620
expect(concurrencyJSON(input)).toEqual(expected);
1721
});

lib/package/concurrency.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import type { Expression } from "./expression";
2+
13
export type Concurrency =
24
| string
35
| {
46
group: string;
5-
cancelInProgress?: boolean;
7+
cancelInProgress?: boolean | Expression;
68
};
79

810
export function concurrencyJSON(

lib/package/expression.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Expression = `\${{${string}}}`;

lib/package/step.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ describe("stepJSON", () => {
3636
{ kind: "run", if: "always()", command: "echo 'Hello, world!'" },
3737
{ if: "always()", run: "echo 'Hello, world!'" },
3838
],
39+
[
40+
{ kind: "run", continueOnError: true, command: "echo 'Hello, world!'" },
41+
{ "continue-on-error": true, run: "echo 'Hello, world!'" },
42+
],
43+
[
44+
{
45+
kind: "run",
46+
continueOnError: "${{ foo }}",
47+
command: "echo 'Hello, world!'",
48+
},
49+
{ "continue-on-error": "${{ foo }}", run: "echo 'Hello, world!'" },
50+
],
3951
])("stepJSON(%j) -> %j", (input, expected) => {
4052
expect(stepJSON(input)).toEqual(expected);
4153
});
@@ -71,6 +83,18 @@ describe("stepJSON", () => {
7183
{ kind: "uses", if: "always()", action: "actions/checkout@v4" },
7284
{ if: "always()", uses: "actions/checkout@v4" },
7385
],
86+
[
87+
{ kind: "uses", continueOnError: true, action: "actions/checkout@v4" },
88+
{ "continue-on-error": true, uses: "actions/checkout@v4" },
89+
],
90+
[
91+
{
92+
kind: "uses",
93+
continueOnError: "${{ foo }}",
94+
action: "actions/checkout@v4",
95+
},
96+
{ "continue-on-error": "${{ foo }}", uses: "actions/checkout@v4" },
97+
],
7498
])("stepJSON(%j) -> %j", (input, expected) => {
7599
expect(stepJSON(input)).toEqual(expected);
76100
});

lib/package/step.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { Expression } from "./expression";
12
import type { Shell } from "./shell";
23

34
export type StepBase = {
45
id?: string;
56
name?: string;
67
env?: Record<string, string>;
78
if?: string | boolean | number;
8-
// TODO: continue-on-error
9+
continueOnError?: boolean | Expression;
910
// TODO: timeout-minutes
1011
};
1112

@@ -30,6 +31,9 @@ export function stepJSON(step: Step): Record<string, unknown> {
3031
...(step.name != null && { name: step.name }),
3132
...(step.env != null && { env: step.env }),
3233
...(step.if != null && { if: step.if }),
34+
...(step.continueOnError != null && {
35+
"continue-on-error": step.continueOnError,
36+
}),
3337
};
3438

3539
switch (step.kind) {

0 commit comments

Comments
 (0)