GitHub Actions Artifacts, Caches and Matrix Builds
Choose the correct storage
An artifact is a workflow output, such as a test report or build archive, retained for later inspection or distribution under configured retention. A cache is reusable data, commonly downloaded dependencies, intended to reduce repeated work. Neither is a substitute for a source repository or independent backup. Cache hits are not proof of correctness; verify restored inputs using the normal integrity and dependency checks.
Design a small matrix
A matrix expands a job into combinations of selected values. Two OS labels and two formats produce four jobs in this simple Cartesian product. matrix.os selects a runner and matrix.format selects data for the step. fail-fast: false allows other variants to continue after a failed variant; it does not mark failures successful. More combinations increase runner usage. This workflow does not require checkout.
name: Garden variantson: [workflow_dispatch]permissions: {}jobs: verify: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] format: [short, long] steps: - name: Check format selection env: FORMAT: ${{ matrix.format }} shell: bash run: | case "$FORMAT" in short|long) printf '%s\n' 'Known format' ;; *) exit 1 ;; esacName artifacts and cache keys deliberately
If each matrix variant produces a report, use distinguishable names such as report-ubuntu-latest-short. Upload only the intended report, not an entire working directory or credential file. The upload and download actions must be reviewed and pinned before activation. For dependency caches, a key might combine OS, toolchain version and a lockfile digest, for example deps-linux-py3.12-<lock-digest>. This is a conceptual key, not an action invocation. Avoid secrets in both caches and artifacts; untrusted contributions may have access to data under applicable cache rules.
Estimate before expanding
For simple independent axes, multiply their lengths. For example two OS values times two formats equals four job variants. include and exclude alter that product and have specific merge rules; this lab intentionally excludes those features. Use max-parallel where appropriate to limit simultaneous jobs, not to reduce the number of variants. Verify each variant’s result before interpreting a matrix as fully successful.
Practice and check
Write down the four pairs and the distinct report names before running the offline lab. The lab expands the two axes, checks naming uniqueness and executes the fixed format check under local Bash for both formats. It also models exact cache-key equality versus changed keys. There is no actual artifact upload, cache service, Windows runner or hosted job scheduling.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
GitHub Actions Artifacts, Caches and Matrix Builds — knowledge check
Reason about GitHub Actions workflow behavior and safety.
Two OS values and two formats with no include/exclude produce how many jobs?
Which mechanism fits a report retained after the run?
Which mechanism commonly reduces repeated dependency downloads?
What does fail-fast: false do?
Why use distinct artifact names per variant?