From 7e5c8d20aee393fbbe3e1d651dd2ecfded8da0e7 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Thu, 8 Dec 2022 13:55:19 -0500 Subject: [PATCH] Skip context validation when matrices have expressions --- actions-languageservice/src/context-providers/default.ts | 8 ++++++-- .../src/context-providers/matrix.test.ts | 8 ++++---- actions-languageservice/src/context-providers/matrix.ts | 7 ++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/actions-languageservice/src/context-providers/default.ts b/actions-languageservice/src/context-providers/default.ts index 4b35267..3782223 100644 --- a/actions-languageservice/src/context-providers/default.ts +++ b/actions-languageservice/src/context-providers/default.ts @@ -7,6 +7,10 @@ import {getNeedsContext} from "./needs"; import {getStepsContext} from "./steps"; import {getStrategyContext} from "./strategy"; +// ContextValue is the type of the value returned by a context provider +// Null indicates that the context provider doesn't have any value to provide +export type ContextValue = data.Dictionary | data.Null; + export async function getContext( names: string[], config: ContextProviderConfig | undefined, @@ -16,7 +20,7 @@ export async function getContext( const filteredNames = filterContextNames(names, workflowContext); for (const contextName of filteredNames) { - let value: data.Dictionary | undefined; + let value: ContextValue | undefined; value = await getDefaultContext(contextName, workflowContext); @@ -34,7 +38,7 @@ export async function getContext( return context; } -async function getDefaultContext(name: string, workflowContext: WorkflowContext): Promise { +async function getDefaultContext(name: string, workflowContext: WorkflowContext): Promise { switch (name) { case "runner": return objectToDictionary({ diff --git a/actions-languageservice/src/context-providers/matrix.test.ts b/actions-languageservice/src/context-providers/matrix.test.ts index b1a0d48..a1e473c 100644 --- a/actions-languageservice/src/context-providers/matrix.test.ts +++ b/actions-languageservice/src/context-providers/matrix.test.ts @@ -88,7 +88,7 @@ describe("matrix context", () => { const workflowContext = contextFromStrategy(strategy); const context = getMatrixContext(workflowContext); - expect(context).toEqual(new data.Dictionary()); + expect(context).toEqual(new data.Null()); }); it("matrix is not a mapping token", () => { @@ -97,7 +97,7 @@ describe("matrix context", () => { const workflowContext = contextFromStrategy(strategy); const context = getMatrixContext(workflowContext); - expect(context).toEqual(new data.Dictionary()); + expect(context).toEqual(new data.Null()); }); it("empty matrix", () => { @@ -118,7 +118,7 @@ describe("matrix context", () => { const workflowContext = contextFromStrategy(strategy); const context = getMatrixContext(workflowContext); - expect(context).toEqual(new data.Dictionary()); + expect(context).toEqual(new data.Null()); }); it("matrix with include expression", () => { @@ -138,7 +138,7 @@ describe("matrix context", () => { const workflowContext = contextFromStrategy(strategy); const context = getMatrixContext(workflowContext); - expect(context).toEqual(new data.Dictionary()); + expect(context).toEqual(new data.Null()); }); it("matrix with expression within property", () => { diff --git a/actions-languageservice/src/context-providers/matrix.ts b/actions-languageservice/src/context-providers/matrix.ts index c13f6ac..f3d8b4c 100644 --- a/actions-languageservice/src/context-providers/matrix.ts +++ b/actions-languageservice/src/context-providers/matrix.ts @@ -4,8 +4,9 @@ import {KeyValuePair} from "@github/actions-workflow-parser/templates/tokens/key import {MappingToken} from "@github/actions-workflow-parser/templates/tokens/mapping-token"; import {SequenceToken} from "@github/actions-workflow-parser/templates/tokens/sequence-token"; import {WorkflowContext} from "../context/workflow-context"; +import {ContextValue} from "./default"; -export function getMatrixContext(workflowContext: WorkflowContext): data.Dictionary { +export function getMatrixContext(workflowContext: WorkflowContext): ContextValue { // https://docs.github.com/en/actions/learn-github-actions/contexts#matrix-context const strategy = workflowContext.job?.strategy; if (!strategy || !isMapping(strategy)) { @@ -15,13 +16,13 @@ export function getMatrixContext(workflowContext: WorkflowContext): data.Diction const matrix = strategy.find("matrix"); if (!matrix || !isMapping(matrix)) { // Matrix could be an expression, so there's no context we can provide - return new data.Dictionary(); + return new data.Null(); } const properties = matrixProperties(matrix); if (!properties) { // Matrix included an expression, so there's no context we can provide - return new data.Dictionary(); + return new data.Null(); } const d = new data.Dictionary();