Skip to content

Chapter 8 of 9

Advanced Workflows

Scale automation with matrices, caches, artifacts, and reusable workflows.

42 minutes 10 quick checksBy Subha Prasad
Lesson 8 of 9Course navigation

Lesson content

Read, practise, then check your understanding

Advanced Workflows: Matrices, Caching, and Reuse

Advanced workflows remove duplication and shorten feedback without hiding behavior. A matrix expands one job into multiple combinations. Caches reuse expensive dependency data, artifacts transfer or retain outputs, and reusable workflows centralize an entire audited process.

Core ideas

  • strategy.matrix creates one job per combination and supports include and exclude adjustments.
  • fail-fast controls whether one matrix failure cancels other in-progress combinations.
  • Caches are keyed snapshots intended for reusable dependencies; artifacts are outputs from a particular run.
  • A reusable workflow declares workflow_call inputs, secrets, and outputs and is invoked at job level.

How it works

Build cache keys from the operating system, tool version, and lockfile hash. Restore keys can accept older compatible entries, but an incorrect cache must never change correctness. Use artifacts for compiled packages, test reports, or diagnostics that downstream jobs or people need.

Configuration example

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        node: [20, 22]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm test

Read the example from top to bottom: the trigger creates a run, the job requests a runner, and each step receives only the context configured for it. Adapt names, versions, permissions, and commands to the repository rather than copying production credentials or policies blindly.

Production guidance

  • Keep the matrix to supported combinations; exhaustive combinations can multiply cost quickly.
  • Do not cache secrets, build outputs that should be rebuilt, or mutable global state.
  • Version reusable workflow contracts and test changes with representative callers.

The chapter quiz follows this lesson and checks both the vocabulary and the operational decisions behind the configuration.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement correctly describes matrix strategy?
Which term matches this explanation: Expanding one job definition across combinations such as OS and runtime version.
Which statement correctly describes fail-fast?
Which term matches this explanation: Matrix behavior that cancels unfinished siblings after a failure.
Which statement correctly describes dependency cache?
Which term matches this explanation: Stored reusable dependency data that speeds later workflow runs.
Which statement correctly describes artifact?
Which term matches this explanation: A file or bundle retained from a run for download or use by another job.
Which statement correctly describes reusable workflow?
Which term matches this explanation: A complete workflow invoked by another workflow through workflow_call.

0 of 10 checks passed

Your progress is saved on this device.