Quick decision: Use a cache for files a future run can regenerate. Use an artifact when a person or a later job needs the output of a specific run.

Two files from the same build

Your iOS job downloads dependencies and generates a test results bundle. Cache the reusable dependency downloads with a key that reflects the inputs that affect compatibility. Upload the test results bundle as an artifact so a teammate can open the results for the commit that failed.

Ask what happens if the file disappears

The job can download or regenerate it: A cache can save time. Keep the job working on a cache miss.

You would lose the exact output of a particular run: Use an artifact and set a retention period that suits your review process.

As a final check, run the workflow once without a cache and confirm the build still works. Keep credentials out of caches and review reports for sensitive content before uploading them.

GitHub’s dependency caching and artifact comparison

What goes where in an iOS workflow?

Downloaded Swift package dependencies: A cache can save repeated downloads. Use a key informed by the resolved dependency versions and include platform or toolchain details if they change whether the cached files are reusable.

A failed run’s test results: Upload the results as an artifact so someone can inspect that exact run after the runner is gone.

A build passed from one job to another: Use an artifact when the downstream job must receive the output of the upstream job. If the handoff fails, surface the failure instead of silently continuing with an older cached copy.

A cache hit is only useful if it saves time

Compare a normal run against one without the cache. Include restore and save time in the comparison. If the directory is large and takes almost as long to restore as it takes to rebuild, narrow the cache to the files that provide the biggest benefit. Confirm that changing the dependency lockfile produces a different cache key when expected.

For artifacts, do a different check. Open the run summary, download the file, and make sure the archive contains the output a reviewer needs. If the artifact is used by a second job, check that job’s log for the exact file it received. The two checks answer different questions: did reuse save time, and did the right output reach its destination?