How can you create a dynamic matrix where the list of values is determined by a previous job?
Select an answer to reveal the explanation.
Short Explanation
fromJSON() converts a JSON string output from a prior job into an actual array that the matrix strategy can iterate over.
Full Explanation
Dynamic matrices are achieved by: (1) Having a 'setup' job output a JSON array string via $GITHUB_OUTPUT (e.g., 'matrix=["node16","node18","node20"]'); (2) The downstream job with 'needs: setup' uses fromJSON() in its matrix: 'matrix: node: ${{ fromJSON(needs.setup.outputs.matrix) }}'. This enables matrices computed from external sources (API calls, file contents, git tags). Artifact-based approaches don't integrate with the matrix syntax. GitHub API calls can't be made inside YAML matrix blocks. Dynamic matrices are fully supported.
Prefer to study offline? Printable PDF study book + test engine ($7.50, unofficial). These questions stay free here.