Inspired by a couple questions here, I wrote up a way to cache key based on your directories contents using md5sum. Hope it helps. (I’m sure there is a way to do this cleaner too)
- run: |
echo $(find ./migrations -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1) >> CACHE_KEY1
- run: cat CACHE_KEY1
- save_cache:
key: test-cache-v1-{{ checksum "CACHE_KEY1" }}
paths:
- migrations
I have three repos that I run migrations on before doing downstream integration tests. We use Postgres as our database. The migrated repos are django & flask. In one job, we run the migrations in each repo, call pg_dump to dump the data to files on an attached ‘workspace’, then call persist_to_workspace to save the files. This process takes around 10 minutes. In parallel downstream jobs, we call attach_workspace to access those file and restore the database before running the integration tests.
…
https://discuss.circleci.com/t/base-cache-key-on-checksum-of-directory-rather-than-a-single-file/20059
2 Likes
abe
December 13, 2019, 5:32pm
2
This didn’t seem to work for me, I get a different key with the same directory contents.