Adding reusable workflow jobs to matrix and strategy contexts (#158)
This commit is contained in:
@@ -57,6 +57,7 @@ function getDefaultContext(name: string, workflowContext: WorkflowContext, mode:
|
||||
case "inputs":
|
||||
return getInputsContext(workflowContext);
|
||||
|
||||
case "reusableWorkflowJob":
|
||||
case "job":
|
||||
return getJobContext(workflowContext);
|
||||
|
||||
@@ -114,5 +115,5 @@ function filterContextNames(contextNames: string[], workflowContext: WorkflowCon
|
||||
}
|
||||
|
||||
function hasStrategy(workflowContext: WorkflowContext): boolean {
|
||||
return workflowContext.job?.strategy !== undefined;
|
||||
return workflowContext.job?.strategy !== undefined || workflowContext.reusableWorkflowJob?.strategy !== undefined;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {ContextValue, Mode} from "./default";
|
||||
|
||||
export function getMatrixContext(workflowContext: WorkflowContext, mode: Mode): ContextValue {
|
||||
// https://docs.github.com/en/actions/learn-github-actions/contexts#matrix-context
|
||||
const strategy = workflowContext.job?.strategy;
|
||||
const strategy = workflowContext.job?.strategy ?? workflowContext.reusableWorkflowJob?.strategy;
|
||||
if (!strategy || !isMapping(strategy)) {
|
||||
return new DescriptionDictionary();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export function getStrategyContext(workflowContext: WorkflowContext): Descriptio
|
||||
// https://docs.github.com/en/actions/learn-github-actions/contexts#strategy-context
|
||||
const keys = ["fail-fast", "job-index", "job-total", "max-parallel"];
|
||||
|
||||
const strategy = workflowContext.job?.strategy;
|
||||
const strategy = workflowContext.job?.strategy ?? workflowContext.reusableWorkflowJob?.strategy;
|
||||
if (!strategy || !isMapping(strategy)) {
|
||||
return new DescriptionDictionary(
|
||||
...keys.map(key => {
|
||||
|
||||
@@ -505,6 +505,45 @@ jobs:
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("reference strategy in reusable workflow", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
node: [14, 16]
|
||||
uses: ./reusable-workflow-with-inputs.yaml
|
||||
with:
|
||||
username: User-\${{ strategy.fail-fast }}
|
||||
`;
|
||||
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("reference matrix in reusable workflow", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
node: [14, 16]
|
||||
uses: ./reusable-workflow-with-inputs.yaml
|
||||
with:
|
||||
username: \${{ matrix.node }}
|
||||
`;
|
||||
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("reference outside of a matrix job", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
|
||||
Reference in New Issue
Block a user