Skip to content

Chapter 6 of 7

Artifacts, Caching, and Service Containers

Workflows often need to share files between jobs or expose build outputs for download. Artifacts serve this role: actions/upload-artifact@v4 stores files under a name: and path:, and a later job retrieves them with actions/download-artifact@v4. Repository artifacts are retained for 90 days by default, after which they are deleted. Each individual artifact is capped at 10 GB and the total upload per workflow run is also limited to 10 GB across all artifacts, so larger outputs need to be handled through GitHub Packages or external storage.

Caching speeds up builds by reusing dependencies between runs. The actions/cache@v4 action stores files keyed by a combination of path and key, with hashFiles() used to generate keys that invalidate automatically when dependency manifests change. For example, a key like \({{ runner.os }}-npm-\){{ hashFiles('**/package-lock.json') }} will produce a fresh cache whenever package-lock.json changes. The key is an exact match for upload and download, while restore-keys: provides comma-separated prefix matches as a fallback when the exact key is missing. Many setup actions, including actions/setup-node@v4 with cache: 'npm' and actions/setup-go@v5 with cache: true, integrate this caching automatically based on lockfile hashes.

Jobs that need databases or other backing services can declare them under services:, which spins up additional containers alongside the job. A PostgreSQL service, for instance, can be started with services: postgres: image: postgres:16 env: POSTGRES_PASSWORD: postgres ports: ['5432:5432'], and health checks added through options: like --health-cmd="pg_isready" ensure the service is ready before the job proceeds. The job and its services share a custom network where services are reachable by their service name as host.

All chapters
  1. 1GitHub Actions Foundations
  2. 2Triggering Workflows
  3. 3Jobs, Matrices, Concurrency, and Conditions
  4. 4Environment Variables, Outputs, and Context References
  5. 5Permissions, Tokens, and Security
  6. 6Artifacts, Caching, and Service Containers
  7. 7Reusable Workflows, Environments, and Deployments

Drill it

Reading is not remembering. These come from the Github Actions Ci Cd Recipes deck:

Q

What is GitHub Actions?

A CI/CD and workflow automation platform built into GitHub that runs jobs in response to repository events using YAML-defined workflows stored in .github/workfl...

Q

What file extension do GitHub Actions workflow files use?

.yaml or .yml, stored under .github/workflows/ in the repository.

Q

What is a workflow in GitHub Actions?

An automated, configurable process defined by a YAML file that runs one or more jobs and is triggered by events.

Q

What is a job in GitHub Actions?

A set of steps in a workflow that execute on the same runner; jobs run in parallel by default unless dependencies are declared with needs:.