Skip to content

Commit 37ba6ab

Browse files
authored
Fix misleading error for malformed local workflow paths (#221)
1 parent 216fcbb commit 37ba6ab

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

languageservice/src/validate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ function validateWorkflowUsesFormat(diagnostics: Diagnostic[], token: StringToke
354354
return;
355355
}
356356

357+
// Malformed local workflow reference (starts with ./ but not in .github/workflows)
358+
if (uses.startsWith("./")) {
359+
addWorkflowUsesFormatError(diagnostics, token, "local workflow references must be rooted in '.github/workflows'");
360+
return;
361+
}
362+
357363
// Remote workflow reference: must have @ for version
358364
const atSegments = uses.split("@");
359365
if (atSegments.length === 1) {

languageservice/src/validate.uses-format.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,27 @@ jobs:
469469
]);
470470
});
471471

472+
it("malformed local path not in .github/workflows", async () => {
473+
const input = `on: push
474+
jobs:
475+
test:
476+
uses: ./foo/bar.yml
477+
`;
478+
const result = await validate(createDocument("wf.yaml", input));
479+
expect(result).toEqual([
480+
{
481+
message:
482+
"Invalid workflow reference './foo/bar.yml': local workflow references must be rooted in '.github/workflows'",
483+
severity: DiagnosticSeverity.Error,
484+
range: {
485+
start: {line: 3, character: 10},
486+
end: {line: 3, character: 23}
487+
},
488+
code: "invalid-workflow-uses-format"
489+
}
490+
]);
491+
});
492+
472493
it("missing .github/workflows path", async () => {
473494
const input = `on: push
474495
jobs:
@@ -562,7 +583,8 @@ jobs:
562583
const result = await validate(createDocument("wf.yaml", input));
563584
expect(result).toEqual([
564585
{
565-
message: "Invalid workflow reference './workflows/test.yml': no version specified",
586+
message:
587+
"Invalid workflow reference './workflows/test.yml': local workflow references must be rooted in '.github/workflows'",
566588
severity: DiagnosticSeverity.Error,
567589
range: {
568590
start: {line: 3, character: 10},

0 commit comments

Comments
 (0)