Fix misleading error for malformed local workflow paths (#221)
This commit is contained in:
@@ -354,6 +354,12 @@ function validateWorkflowUsesFormat(diagnostics: Diagnostic[], token: StringToke
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Malformed local workflow reference (starts with ./ but not in .github/workflows)
|
||||||
|
if (uses.startsWith("./")) {
|
||||||
|
addWorkflowUsesFormatError(diagnostics, token, "local workflow references must be rooted in '.github/workflows'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remote workflow reference: must have @ for version
|
// Remote workflow reference: must have @ for version
|
||||||
const atSegments = uses.split("@");
|
const atSegments = uses.split("@");
|
||||||
if (atSegments.length === 1) {
|
if (atSegments.length === 1) {
|
||||||
|
|||||||
@@ -469,6 +469,27 @@ jobs:
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("malformed local path not in .github/workflows", async () => {
|
||||||
|
const input = `on: push
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
uses: ./foo/bar.yml
|
||||||
|
`;
|
||||||
|
const result = await validate(createDocument("wf.yaml", input));
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
"Invalid workflow reference './foo/bar.yml': local workflow references must be rooted in '.github/workflows'",
|
||||||
|
severity: DiagnosticSeverity.Error,
|
||||||
|
range: {
|
||||||
|
start: {line: 3, character: 10},
|
||||||
|
end: {line: 3, character: 23}
|
||||||
|
},
|
||||||
|
code: "invalid-workflow-uses-format"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("missing .github/workflows path", async () => {
|
it("missing .github/workflows path", async () => {
|
||||||
const input = `on: push
|
const input = `on: push
|
||||||
jobs:
|
jobs:
|
||||||
@@ -562,7 +583,8 @@ jobs:
|
|||||||
const result = await validate(createDocument("wf.yaml", input));
|
const result = await validate(createDocument("wf.yaml", input));
|
||||||
expect(result).toEqual([
|
expect(result).toEqual([
|
||||||
{
|
{
|
||||||
message: "Invalid workflow reference './workflows/test.yml': no version specified",
|
message:
|
||||||
|
"Invalid workflow reference './workflows/test.yml': local workflow references must be rooted in '.github/workflows'",
|
||||||
severity: DiagnosticSeverity.Error,
|
severity: DiagnosticSeverity.Error,
|
||||||
range: {
|
range: {
|
||||||
start: {line: 3, character: 10},
|
start: {line: 3, character: 10},
|
||||||
|
|||||||
Reference in New Issue
Block a user