CI runner environments and matrices
A runner is the process or machine that executes a CI job. Its working directory, shell version, available utilities, locale, permissions and environment may differ from a developer terminal. An environment matrix enumerates supported combinations; each cell is a separate job with its own result. Generating a matrix is not evidence that all target environments have passed.
Make dependencies explicit
Use a known checkout directory supplied by the runner and validate required files before changing directory. Test interpreter capabilities or numeric version requirements and fail clearly if dependencies are missing. Avoid depending on personal startup files or shell aliases. Pin dependencies through reviewed lockfiles, immutable image digests and reviewed full action commit hashes where applicable; even pinned dependencies require trust and updates. Record actual versions, source revision and configuration. Do not silently substitute a newer tool.
GitHub Actions uses a job strategy matrix, while GitLab CI supports parallel matrix jobs. Both have provider-specific YAML and runner semantics; they are external frameworks, not Bash syntax. A local matrix can exercise the same script with controlled parameters, but does not reproduce hosted runners, permissions, caching or isolation. See the optional integration notes. Use a fresh workspace for every combination and give artifacts distinct names. Check workspace setup and child execution before claiming requirements are met. Matrix labels describe planned jobs, not compatibility evidence.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code. Git, GNU tar, gzip and coreutils are external dependencies for the relevant examples. Do not run these in an existing repository or CI workspace.
Resolve a workspace explicitly
mkdir -p 'checkout space' || exit 1printf 'fixture\n' > 'checkout space/project.txt' || exit 1workspace=$PWD/'checkout space'( cd -- "$workspace" && cat project.txt ) || exit 1[[ -f "$workspace/project.txt" ]]Expected stdout:
fixtureThe quoted path works even with spaces, and the parent directory is unchanged.
Plan a matrix
for target in linux macos; do for mode in debug release; do printf '%s-%s\n' "$target" "$mode" donedoneExpected stdout:
linux-debuglinux-releasemacos-debugmacos-releaseThis enumerates jobs, not actual OS executions.
Check the runner contract
if (( BASH_VERSINFO[0] < 5 )); then printf 'Bash 5 required\n' >&2; exit 2ficommand -v sha256sum >/dev/null || exit 2LC_ALL=C /bin/bash --noprofile --norc -c 'printf "locale=%s\n" "$LC_ALL"' || exit 1printf 'requirements met\n' Expected stdout:
locale=Crequirements metA minimum version and one required executable are checked; this is not exact dependency pinning.
Common mistakes
Do not call a planned matrix a tested compatibility matrix; do not assume the runner starts in your preferred directory.
Practice
Add a third mode to the local matrix; predict the number of cases. Define a target version policy and a clear missing-dependency failure.
Next: Safe CI inputs and interpolation