Bail out of build early if exact cache key already exists


I would like a way to halt a build (exit with success) if an exact cache key is already populated.

I have a build in my workflow that is responsible for generating a cache (bundle install) a la…

    <<: *image_config
    parallelism: 1
      - checkout

      - restore_cache:
          key: my-bundle-cache-key-{{ checksum "Gemfile.lock" }}
      - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
      - save_cache:
          key: my-bundle-cache-key-{{ checksum "Gemfile.lock" }}
          paths: "vendor/bundle"

If I can halt the build after just checkout is done and I know the cache already exists and is good, this could save me from doing
a) a whole restore of the gems (8-15 seconds at present on my project - as we add gems, I expect that to go up)
b) Unnecessary calculations to build a cache that won’t be saved (as it already exists)

(I was asked by @fernfernfern on the support team to file this feature request here - more detail in ticket #26391)

closed #2