A cache is an optimization: a job should still pass on a cold runner. A build artifact is a product of a particular run: a package, a log bundle, or the site that will be deployed. The distinction becomes useful when approval happens after the build.
Make the input reproducible
Install against a lockfile. Include the operating system, toolchain when relevant, and a lockfile hash in the dependency cache key. Keep a cold-run path to verify that a missed cache only costs time. Avoid caching credentials or files that contain them.
Deploy the tested output
Upload the built directory or package from the build job. A later job can download that artifact from the same run and deploy it after approval. Rebuilding during deployment can pick up a different compiler, dependency source, or timestamp and makes it harder to prove what was tested.
- Keep test reports separately so failed runs can still explain what happened.
- Record the Git commit and an artifact digest when the deployment system supports it.
- Choose retention based on how long a release might need to be audited or rolled back.
A useful exercise is to delete a dependency cache in a test workflow. The build may take longer, but the artifact should still be produced. Then remove the expected artifact in a test run. The deployment should stop with a clear error.