Typorithm · medium

Secrets, Caching & Matrix

cicd-practicesdevopssecretsmatrixcache
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Secrets, Caching & Matrix

0%

CI/CD

A build matrix runs a job across several versions in parallel (here Node 20 and 22). Secrets are injected from the encrypted store via the secrets context and never hardcoded. Caching dependencies speeds builds, and the ${{ ... }} expression syntax reads matrix values and secrets.

A build matrix multiplies one job across an axis of values. matrix.node: [20, 22] runs the job twice in parallel — once on Node 20 and once on Node 22 — catching version-specific breakage.

The ${{ ... }} expression syntax reads context values: ${{ matrix.node }} pulls the current matrix value, and ${{ secrets.TOKEN }} pulls a value from the encrypted secrets store. Secrets are never hardcoded in the YAML.

Caching dependencies (often built into actions like setup-node) avoids re-downloading them every run, which speeds builds. For deploys, reusable workflows and OIDC handle secure cloud authentication without long-lived secrets.

01

matrix runs a job across versions in parallel.

02

${{ secrets.TOKEN }} injects an encrypted secret.

03

Caching dependencies avoids re-downloading them each run.

strategy:
  matrix:
    node: [20, 22]
steps:
  - uses: actions/setup-node@v4
    with:
      node-version: ${{ matrix.node }}
  - env:
      TOKEN: ${{ secrets.TOKEN }}

Read the implementation

Connect each part of the code to the concept before you type.

1. Build matrix

strategy.matrix expands the job across each value in parallel.

strategy:
  matrix:

2. Matrix axis

node lists the versions to test — the job runs once per value.

node: [20, 22]

3. Setup action

setup-node installs the chosen Node version and can cache dependencies.

- uses: actions/setup-node@v4

4. Matrix value

${{ matrix.node }} reads the current matrix value for this job run.

node-version: ${{ matrix.node }}

5. Secret

${{ secrets.TOKEN }} injects an encrypted secret instead of hardcoding it.

TOKEN: ${{ secrets.TOKEN }}

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Secrets, Caching & Matrix: Lesson & Practice · Typorithm | ApplyDjinn