Design a job graph with service containers and matrices
Predict runner usage, wire a database into tests and choose which values are available while a workflow is planned or running.
How many runners will test the release?
A library supports Linux and Windows on three runtime versions. One Windows combination is excluded. No new combinations are included. How do you collect every result with at most two matrix jobs running at once?
Work through the decision
The matrix expands to five variants. Set max-parallel to two and fail-fast to false. Give each artifact a name containing its OS and runtime. Make the packaging job depend on successful tests. When diagnosing an image change, record the image version from the job log.
Put work at the correct level
A job gets a runner. Its steps share the job workspace and execute in order. Separate jobs can run concurrently unless connected. Put an if expression on the job to skip allocating its runner when possible, or on one step if the rest of the job should still run.
Order the job graph
List upstream job IDs in needs. A dependent job normally waits for success. When gathering diagnostics after failures, apply a deliberate status condition and inspect needs results. Starting simultaneously is unsafe when packaging depends on a completed build.
Move values between shell steps
Each run step launches its own shell. A shell export disappears with that process. Append a simple NAME=value line to GITHUB_ENV for subsequent steps of the same job. Use named outputs when a downstream job needs a value.
Connect a service container
A service container runs for the job. A containerized job can address it by service label on the shared network. A job running directly on the runner reaches a published port on localhost. A health check distinguishes a listening service from a process still starting.
For a container job, a service named db listening on 5432 is reachable at db:5432. For a host job publishing 5433:5432, use localhost:5433. Set a service health command such as pg_isready for Postgres, with a retry interval and a retry limit. A mapped port by itself only establishes routing.
Budget a matrix
A matrix expands combinations of axes. Exclude unsupported pairs and add exceptional combinations deliberately. max-parallel limits simultaneous jobs, while fail-fast controls cancellation after failures. A moving hosted image label can change tools. Inspect image announcements and test a named image version before switching.
Use matrix.include to add a supported combination or metadata and exclude to remove an invalid one. Inspect the expanded list after both operations. Hosted image migrations such as the removal of Ubuntu 20.04 illustrate why a friendly label is insufficient evidence of the toolchain. Check the image recorded for the specific job.
GitHub-hosted runner image inventory and migration announcements
Reuse YAML without changing its meaning
An anchor names a node in a YAML document and an alias repeats it. GitHub documents reuse of an entire mapping or job this way. The exam outline mentions the YAML merge key. GitHub's Actions parser guidance supports anchors and aliases, so use explicit fields or a reusable component when an override requires merging.
Within one file, this mapping shares both environment values exactly. In a generic YAML merge example, << would combine mapping entries and a local key could override one inherited value. For Actions, use an alias for the exact node or write explicit fields if a value differs.
env: &test_env
APP_MODE: test
LOG_LEVEL: info
# In another job in this workflow:
# env: *test_env
Read the context available at that point
The github context describes the event and ref, runner describes the host, matrix the active combination and needs the direct dependencies. Other contexts expose steps, job, strategy, inputs, secrets, vars and env at supported keys. A full reviewed commit SHA identifies an exact action revision across runs.
Use github.event_name for the event type and github.ref for its reference. runner.os describes the executing runner, job.status its job, and steps.check.outcome an identified step. strategy.job-index identifies a matrix position. vars.REGION is configured data while secrets.REGISTRY_KEY is sensitive. Reference only contexts supported at the current key. An immutable action dependency fixes the content fetched for a particular version. A reviewed full SHA gives a concrete update boundary.
Context availability by workflow key
Evaluate at the right boundary
Actions evaluates expressions at supported workflow keys. A runner shell expands its environment when the step executes. Keep untrusted event content out of generated shell source, pass ordinary data as an environment value, and avoid logging secrets or entire contexts.
Validate the definition before running it
An Actions-aware editor uses the workflow schema to check permitted keys and can suggest action inputs from metadata. Static validation can catch an unsupported key or typo. Runner availability, service readiness and many permissions still require observing an actual run.
Two jobs share an environment block
A workflow uses an anchor for an environment mapping. A developer wants to add one job-specific field through a YAML merge. Their local generic YAML parser accepts it. What is the portable Actions approach?
Check your reasoning
An alias can reuse the complete mapping. For an override, spell out the supported fields or extract a reusable component. Validate with Actions-aware tooling before scheduling a runner. A generic YAML parse alone does not establish support for all constructs in a workflow.
Enumerate a CI matrix locally
Run this Python 3 model. It uses no hosted minutes. Predict how many jobs are eligible and how many batches two runner slots need if all jobs take the same time.
from itertools import product
from math import ceil
jobs = [(os, version) for os, version in product(
["linux", "windows"], [20, 22, 24])
if (os, version) != ("windows", 20)]
print(jobs)
print("batches", ceil(len(jobs) / 2))
Expected output and interpretation
[('linux', 20), ('linux', 22), ('linux', 24), ('windows', 22), ('windows', 24)]
batches 3Changing max-parallel changes the schedule. Excluding a pair changes the work itself.
GitHub documentation · GH-200 skills outline
Documented YAML anchor and alias syntax · GitHub maintainer clarification on merge keys
Continue in GitHub Foundations. Choose automation, AI assistance or a development runtime.
Design a job graph with service containers and matrices quiz
Answer 9 questions. Check each answer for an explanation.