Using a checksum to identify a unique directory

I have a rails app that compiles assets as part of the test suite. What was working before is no longer working:

steps:
      - checkout
      - run: mkdir -p tmp/test/cache/assets
      - attach_workspace:
          at: ~/fworkspace
      - run: tar -cf - app/assets | md5sum > asset_checksum.txt
      - restore_cache:
          keys:
            - v4-app-assets-{{ checksum "asset_checksum.txt" }}
            - v4-app-assets-
      - run: npm install
      - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
      - run: bundle exec rake assets:precompile
      - save_cache:
          key: v4-app-assets-{{ checksum "asset_checksum.txt" }}
          paths:
            - tmp/test/cache/assets
            - public/assets
      - persist_to_workspace:
          root: ~/fworkspace
          paths:
            - tmp/test/cache/assets
            - public/assets

This used to check if there are any changes in the app/assets folder, and if not restore from cache, but if there are, go ahead and compile assets without restoring from cache.

I also tried a second suggestion found on the discussion boards:
- run: | echo $(find ./app/assets -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1) >> ASSET_CACHE_KEY

This also does not see to generate the same key for the same app/assets. Any suggests what I may be doing wrong here?

Checksum different before and after bundle install - #11 by PADomine or Caching Dependencies - CircleCI may address the issue you encountered, @abe.

This wasn’t relevant. Tar is taking into account more than just file contents, like creation date and other meta datawhich would be different on each checkout. Ended up going with an alternative.

find app/assets -type f -exec md5sum {} \; | sort -k 2 | md5sum > asset_checksum.txt