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

Commit

Permalink
feat: report error when 'needs' refers to a non-existing action (#46)
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
OmarTawfik committed Mar 12, 2019
1 parent 7b3720b commit cc446d6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
14 changes: 9 additions & 5 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ gulp.task(
gulp.series(
BuildTasks.clean,
BuildTasks.compile,
LinterTasks.copyFiles,
LinterTasks.generatePackageJson,
VSCodeTasks.copyFiles,
VSCodeTasks.generatePackageJson,
gulp.parallel([
LinterTasks.copyFiles,
LinterTasks.generatePackageJson,
VSCodeTasks.copyFiles,
VSCodeTasks.generatePackageJson,
]),
),
gulp.parallel([BuildTasks.prettier, BuildTasks.tslint, BuildTasks.jestCI]),
BuildTasks.prettier,
BuildTasks.tslint,
BuildTasks.jestCI,
]),
);

Expand Down
10 changes: 9 additions & 1 deletion src/analysis/properties-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

Expand Down Expand Up @@ -33,6 +33,14 @@ class PropertiesAnalyzer extends BoundNodeVisitor {
}
}

protected visitNeeds(node: BoundNeeds): void {
for (const action of node.actions) {
if (!this.actions.has(action.value)) {
this.bag.actionDoesNotExist(action.value, action.syntax.range);
}
}
}

protected visitSecrets(node: BoundSecrets): void {
const localSecrets = new Set<string>();
for (const secret of node.secrets) {
Expand Down
10 changes: 6 additions & 4 deletions src/util/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ export enum DiagnosticCode {
PropertyMustBeDefined,
InvalidProperty,
DuplicateKey,
ReservedEnvironmentVariable,

// Analysis:
TooManySecrets,
DuplicateSecrets,
// Block Analysis
TooManyActions,
DuplicateBlock,

// Property Analysis
TooManySecrets,
DuplicateSecrets,
ActionDoesNotExist,
UnrecognizedEvent,
ReservedEnvironmentVariable,
}

export interface Diagnostic {
Expand Down
29 changes: 29 additions & 0 deletions test/properties-analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ ERROR: The action 'not_found' does not exist in the same workflow file.
`);
});

it("reports error on needing a non-existing action", () => {
expectDiagnostics(`
action "a" {
uses = "./ci"
}
action "b" {
uses = "./ci"
}
action "c" {
uses = "./ci"
needs = [
"a",
"b",
"not_found"
]
}
`).toMatchInlineSnapshot(`
"
ERROR: The action 'not_found' does not exist in the same workflow file.
11 | \\"a\\",
12 | \\"b\\",
13 | \\"not_found\\"
| ^^^^^^^^^^^
14 | ]
15 | }
"
`);
});

it("reports errors on unknown events", () => {
expectDiagnostics(`
workflow "x" {
Expand Down

0 comments on commit cc446d6

Please sign in to comment.