Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit cc446d6

Browse files
committed
feat: report error when 'needs' refers to a non-existing action (#46)
Fixes #7
1 parent 7b3720b commit cc446d6

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

gulpfile.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ gulp.task(
1515
gulp.series(
1616
BuildTasks.clean,
1717
BuildTasks.compile,
18-
LinterTasks.copyFiles,
19-
LinterTasks.generatePackageJson,
20-
VSCodeTasks.copyFiles,
21-
VSCodeTasks.generatePackageJson,
18+
gulp.parallel([
19+
LinterTasks.copyFiles,
20+
LinterTasks.generatePackageJson,
21+
VSCodeTasks.copyFiles,
22+
VSCodeTasks.generatePackageJson,
23+
]),
2224
),
23-
gulp.parallel([BuildTasks.prettier, BuildTasks.tslint, BuildTasks.jestCI]),
25+
BuildTasks.prettier,
26+
BuildTasks.tslint,
27+
BuildTasks.jestCI,
2428
]),
2529
);
2630

src/analysis/properties-analyzer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { BoundNodeVisitor } from "../binding/bound-node-visitor";
66
import { DiagnosticBag } from "../util/diagnostics";
7-
import { BoundDocument, BoundResolves, BoundSecrets, BoundOn, BoundEnv } from "../binding/bound-nodes";
7+
import { BoundDocument, BoundResolves, BoundSecrets, BoundOn, BoundEnv, BoundNeeds } from "../binding/bound-nodes";
88
import { MAXIMUM_SUPPORTED_SECRETS } from "../util/constants";
99
import * as webhooks from "@octokit/webhooks-definitions";
1010

@@ -33,6 +33,14 @@ class PropertiesAnalyzer extends BoundNodeVisitor {
3333
}
3434
}
3535

36+
protected visitNeeds(node: BoundNeeds): void {
37+
for (const action of node.actions) {
38+
if (!this.actions.has(action.value)) {
39+
this.bag.actionDoesNotExist(action.value, action.syntax.range);
40+
}
41+
}
42+
}
43+
3644
protected visitSecrets(node: BoundSecrets): void {
3745
const localSecrets = new Set<string>();
3846
for (const secret of node.secrets) {

src/util/diagnostics.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ export enum DiagnosticCode {
2626
PropertyMustBeDefined,
2727
InvalidProperty,
2828
DuplicateKey,
29-
ReservedEnvironmentVariable,
3029

31-
// Analysis:
32-
TooManySecrets,
33-
DuplicateSecrets,
30+
// Block Analysis
3431
TooManyActions,
3532
DuplicateBlock,
33+
34+
// Property Analysis
35+
TooManySecrets,
36+
DuplicateSecrets,
3637
ActionDoesNotExist,
3738
UnrecognizedEvent,
39+
ReservedEnvironmentVariable,
3840
}
3941

4042
export interface Diagnostic {

test/properties-analysis.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ ERROR: The action 'not_found' does not exist in the same workflow file.
109109
`);
110110
});
111111

112+
it("reports error on needing a non-existing action", () => {
113+
expectDiagnostics(`
114+
action "a" {
115+
uses = "./ci"
116+
}
117+
action "b" {
118+
uses = "./ci"
119+
}
120+
action "c" {
121+
uses = "./ci"
122+
needs = [
123+
"a",
124+
"b",
125+
"not_found"
126+
]
127+
}
128+
`).toMatchInlineSnapshot(`
129+
"
130+
ERROR: The action 'not_found' does not exist in the same workflow file.
131+
11 | \\"a\\",
132+
12 | \\"b\\",
133+
13 | \\"not_found\\"
134+
| ^^^^^^^^^^^
135+
14 | ]
136+
15 | }
137+
"
138+
`);
139+
});
140+
112141
it("reports errors on unknown events", () => {
113142
expectDiagnostics(`
114143
workflow "x" {

0 commit comments

Comments
 (0)