Skip context validation when matrices have expressions
This commit is contained in:
@@ -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<data.Dictionary | undefined> {
|
||||
async function getDefaultContext(name: string, workflowContext: WorkflowContext): Promise<ContextValue | undefined> {
|
||||
switch (name) {
|
||||
case "runner":
|
||||
return objectToDictionary({
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user