构建存储在 public 存储库中并需要使用 CI 的令牌密钥的代码的最佳方法是什么?

What is the best way to build code which is stored in public repo and need token key with CI?

我有一个 Android 项目需要令牌密钥,我将其存储在 public 存储库中。我没有将我的密钥提交给回购协议。我将我的 repo 与 Travis CI 集成以进行自动化构建。但是,构建过程将失败,因为找不到令牌密钥。我应该如何向 CI 提供密钥而不将其提交给 repo?

Travis 允许您为这种情况存储加密的环境变量。见 here:

Encrypting environment variables

Encrypt environment variables with the public key attached to your repository using the travis gem:

  1. If you do not have the travis gem installed, run gem install travis.

  2. In your repository directory, run:

     travis encrypt MY_SECRET_ENV=super_secret --add env.matrix
    
  3. Commit the changes to your .travis.yml.

Encryption and decryption keys are tied to the repository. If you fork a project and add it to Travis CI, it will not access to the encrypted variables.

加密方案在 Encryption keys 中有更详细的解释。