Skip to content

Commit e32d37c

Browse files
committed
feat: parse indirect matrix
1 parent bee15d5 commit e32d37c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lib/github-actions/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ internals.parseActionsSetupNode = function * (workflow, file) {
3232

3333
const envMatch = nodeVersion.match(/^\${{\s+env.(?<envVarName>.*)\s+}}$/);
3434
if (envMatch) {
35-
const envValue = workflow.env[envMatch.groups.envVarName];
35+
const env = {
36+
...workflow.env,
37+
...step.env
38+
};
39+
const envValue = env[envMatch.groups.envVarName];
40+
41+
if (!envValue) {
42+
yield 'not-set';
43+
continue;
44+
}
3645

3746
yield envValue;
3847
continue;
@@ -68,15 +77,26 @@ internals.parseLjharbActions = function * (workflow, file) {
6877
const matrixMatch = nodeVersion.match(/^\${{\s+matrix.(?<matrixVarName>.*)\s+}}$/);
6978
if (matrixMatch) {
7079

80+
let needs = job.strategy.matrix;
7181
if (typeof job.strategy.matrix !== 'string') {
7282

7383
const matrix = job.strategy.matrix[matrixMatch.groups.matrixVarName];
7484

75-
yield * matrix;
76-
continue;
85+
if (!matrix) {
86+
throw new Error(`Unable to find matrix variable '${matrixMatch.groups.matrixVarName}' in the matrix in ${file}`);
87+
}
88+
89+
if (typeof matrix !== 'string') {
90+
// @todo find an example
91+
yield * matrix;
92+
continue;
93+
}
94+
95+
// example: eslint-plugin-react
96+
needs = matrix;
7797
}
7898

79-
const fromJsonMatch = job.strategy.matrix.match(/^\${{\s+fromJson\(needs\.(?<needJobName>.*)\.outputs\.(?<needOutputName>.*)\)\s+}}$/);
99+
const fromJsonMatch = needs.match(/^\${{\s+fromJson\(needs\.(?<needJobName>.*)\.outputs\.(?<needOutputName>.*)\)\s+}}$/);
80100
if (fromJsonMatch) {
81101
const { needJobName, needOutputName } = fromJsonMatch.groups;
82102
const needJob = workflow.jobs[needJobName];

0 commit comments

Comments
 (0)