忽略开发 Pod 时如何在 circleCI 中缓存 Podfiles

问题描述 投票:0回答:1

在我们的 Podfile 中,我们使用

CI
环境变量来决定是否安装某些仅供开发的 Pod(主要是 Flipper)。例如

  if !ENV['CI']
    use_flipper!()
  end

  post_install do |installer|
    if !ENV['CI']
      flipper_post_install(installer)
    end
... etc

这似乎是 Flipper/React Native 推荐的方法。

当我们在本地运行 pod install 时,我们因此创建了一个包含 Flipper 的 Podfile.lock。在 CI 上,Flipper 被正确地排除在外。

这会导致尝试使用 circleCI 进行缓存时出现问题。

            - restore_cache:
                  key: podfile-{{ checksum "./ios/Podfile.lock" }}
            - run:
                  name: Install iOS pods
                  command: |
                      pod install --project-directory=ios/
                      git --no-pager diff --exit-code ios/Podfile.lock | echo "Podfile has been generated differently in CI to the codebase. This means it won't be cached & will be expensive/slow to run each time."

            - save_cache:
                  paths:
                      - ios/Pods
                  key: podfile-{{ checksum "./ios/Podfile.lock" }}

这将始终在 Podfile.lock 中创建相对于已签入内容的更改。

有没有人对这种情况有明智的策略?有更好的校验和吗?

react-native circleci podfile fbflipper podfile-lock
1个回答
0
投票

我已经想出了 a 解决方案,但它很笨重所以很想知道人们是否有更好的解决方案。我创建了一个新脚本来替换 pod install:

#!/bin/bash

export CI='true'
pod install --project-directory=ios/
cp ios/Podfile.lock ios/Podfile.ci.lock
unset CI
pod install --project-directory=ios/

然后您可以将其添加为节点/npm 脚本

"podinstall": "sh ./scripts/pod_install_for_ci.sh"

假设人们使用它而不是

pod install
,这将允许我们使用
ios/Podfile.ci.lock
作为 circleCI 中的缓存键。

缺点显然是本地开发速度较慢,而且要求每个人都使用这种安装方法。

© www.soinside.com 2019 - 2024. All rights reserved.