CircleCI - 如何仅在未缓存时下载依赖项

CircleCI - how to download dependency only if not cached

简述

使用 circleci 进行 运行 单元测试时,我必须下载并安装 LibreOffice。不缓存怎么才能下载呢?

p.s。也发布在 circleci 支持 here

详情

LibreOffice 下载和安装通常需要 30 多秒才能完成。

所以我打算使用save_cache特性来缓存它here

我的 google search leads me to when steps here,虽然指南中没有明确说明如何检查缓存键是否存在。

我将标记 HOW_TO 放在代码段下方的 .circleci/config.yml 中

      - restore_cache:
          key: cache-libreoffice

      - when:
          condition: <<HOW_TO check if cache key exists >>
          steps:
            - run:
                name: install atlas Pipfile
                command: |
                  mkdir -p /tmp/libreoffice
                  cd /tmp/libreoffice
                    wget https://download.documentfoundation.org/libreoffice/stable/6.3.3/deb/x86_64/LibreOffice_6.3.3_Linux_x86-64_deb.tar.gz

      - save_cache:
          key: cache-libreoffice
          paths:  # the paths to save to cache entry
            - /tmp/libreoffice

由于 circleci 官方支持似乎对这个问题提供的提示不太有用,我的解决方法是使用 custom docker image 并在那里安装这些依赖项。