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":
|
case "inputs":
|
||||||
return getInputsContext(workflowContext);
|
return getInputsContext(workflowContext);
|
||||||
|
|
||||||
|
case "reusableWorkflowJob":
|
||||||
case "job":
|
case "job":
|
||||||
return getJobContext(workflowContext);
|
return getJobContext(workflowContext);
|
||||||
|
|
||||||
@@ -114,5 +115,5 @@ function filterContextNames(contextNames: string[], workflowContext: WorkflowCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hasStrategy(workflowContext: WorkflowContext): boolean {
|
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 {
|
export function getMatrixContext(workflowContext: WorkflowContext, mode: Mode): ContextValue {
|
||||||
// https://docs.github.com/en/actions/learn-github-actions/contexts#matrix-context
|
// 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)) {
|
if (!strategy || !isMapping(strategy)) {
|
||||||
return new DescriptionDictionary();
|
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
|
// https://docs.github.com/en/actions/learn-github-actions/contexts#strategy-context
|
||||||
const keys = ["fail-fast", "job-index", "job-total", "max-parallel"];
|
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)) {
|
if (!strategy || !isMapping(strategy)) {
|
||||||
return new DescriptionDictionary(
|
return new DescriptionDictionary(
|
||||||
...keys.map(key => {
|
...keys.map(key => {
|
||||||
|
|||||||
@@ -505,6 +505,45 @@ jobs:
|
|||||||
expect(result).toEqual([]);
|
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 () => {
|
it("reference outside of a matrix job", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
on: push
|
on: push
|
||||||
|
|||||||
Reference in New Issue
Block a user