Validate that an action exists
This commit is contained in:
@@ -25,6 +25,11 @@ export async function validateAction(
|
|||||||
|
|
||||||
const actionInputs = await config.getActionInputs(action);
|
const actionInputs = await config.getActionInputs(action);
|
||||||
if (actionInputs === undefined) {
|
if (actionInputs === undefined) {
|
||||||
|
diagnostics.push({
|
||||||
|
severity: DiagnosticSeverity.Error,
|
||||||
|
range: mapRange(step.uses.range),
|
||||||
|
message: `Unable to resolve action \`${step.uses.value}\`, repository or version not found`
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ registerLogger(new TestLogger());
|
|||||||
|
|
||||||
const validationConfig: ValidationConfig = {
|
const validationConfig: ValidationConfig = {
|
||||||
getActionInputs: async (ref: ActionReference) => {
|
getActionInputs: async (ref: ActionReference) => {
|
||||||
let inputs: Record<string, ActionInput> = {};
|
let inputs: Record<string, ActionInput> | undefined = undefined;
|
||||||
switch (ref.owner + "/" + ref.name + "@" + ref.ref) {
|
switch (ref.owner + "/" + ref.name + "@" + ref.ref) {
|
||||||
case "actions/checkout@v3":
|
case "actions/checkout@v3":
|
||||||
inputs = {
|
inputs = {
|
||||||
@@ -58,6 +58,7 @@ const validationConfig: ValidationConfig = {
|
|||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("validate action steps", () => {
|
describe("validate action steps", () => {
|
||||||
it("valid action reference", async () => {
|
it("valid action reference", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
@@ -73,6 +74,35 @@ jobs:
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("action does not exist", async () => {
|
||||||
|
const input = `
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/does-not-exist@v3
|
||||||
|
`;
|
||||||
|
const result = await validate(createDocument("wf.yaml", input), validationConfig);
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
message: "Unable to resolve action `actions/does-not-exist@v3`, repository or version not found",
|
||||||
|
range: {
|
||||||
|
end: {
|
||||||
|
character: 41,
|
||||||
|
line: 6
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
character: 16,
|
||||||
|
line: 6
|
||||||
|
}
|
||||||
|
},
|
||||||
|
severity: DiagnosticSeverity.Error
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("invalid input", async () => {
|
it("invalid input", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
on: push
|
on: push
|
||||||
|
|||||||
Reference in New Issue
Block a user