[英]Google services json file for github actions?
I am currently working on a android project and I use github action to test the project.我目前正在处理一个 android 项目,我使用 github 操作来测试该项目。 But whenever it build it ends up with an error for not finding the google-services.json
file.但无论何时构建,它都会以找不到google-services.json
文件的错误告终。
The error generated is as follows产生的错误如下
File google-services.json is missing. The Google Services Plugin cannot function without it.
Now, I don't want to commit or upload the google-services.json
file on the github. So, Is there any other way to solve this?现在,我不想在 github 上提交或上传google-services.json
文件。那么,还有其他方法可以解决这个问题吗?
If you are making any public repo or any sample app, you should not commit the google-services.json
file to the Github repo.如果您正在制作任何公共存储库或任何示例应用程序,则不应将google-services.json
文件提交到 Github 存储库。
While you are working on private repo it depends on how collaborators are managing the firebase credentials.当您处理私人回购时,这取决于合作者如何管理 firebase 凭证。 google-services.json
file will have access key and fingerprints of firebase projects. google-services.json
文件将包含 firebase 项目的访问密钥和指纹。
Conclusion: Don't share the google-services.json
file over any SVN or Git repo.结论:不要在任何 SVN 或 Git 存储库上共享google-services.json
文件。 User can add their own google-services.json
file to the project and run it on the testing environment.用户可以将自己的google-services.json
文件添加到项目中,并在测试环境中运行。
Well... I have found the solution but in case if anyone needs I am explaining here.嗯......我已经找到了解决方案,但如果有人需要,我会在这里解释。
We can store the content of google-sevices.json
in Environment variable (aka Secrets in github).我们可以将google-sevices.json
的内容存储在环境变量(又名 github 中的 Secrets)中。 Actually github uses linux based cli so we have to execute some command on the cli using github actions.实际上 github 使用基于 linux 的 cli,所以我们必须使用 github 动作在 cli 上执行一些命令。
There will be two steps...会有两个步骤...
- name: Create file
run: cat /home/runner/work/<Project-Name>/<Project-Name>/app/google-services.json | base64
- name: Putting data
env:
DATA: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $DATA > /home/runner/work/<Project-Name>/<Project-Name>/app/google-services.json
google-services.json
file in the github secrets via: Setting > Secrets > New Repository Secret
using name GOOGLE_SERVICES_JSON
然后在 github 机密中定义google-services.json
文件的内容: Setting > Secrets > New Repository Secret
使用名称GOOGLE_SERVICES_JSON
的新存储库机密Both of these commands should be placed before the gradle build command in gradle.yml
这两个命令都应该放在 gradle.yml 中的gradle.yml
构建命令之前
By doing this your google-services.json
file will be created and has data also so the app will build successfully.通过这样做,您的google-services.json
文件将被创建并包含数据,因此应用程序将成功构建。
Adding any sort of credentials to your GitHub repo is dangerous and ill-advised.向您的 GitHub 存储库添加任何类型的凭据都是危险且不明智的。 Even if the repo is private and you are the only one using it right now, maybe you'll invite other people later and unless you change the git history, your credentials will always be accessible even if you delete them via a new commit.即使 repo 是私有的并且你现在是唯一一个使用它的人,也许你稍后会邀请其他人,除非你更改 git 历史记录,即使你通过新提交删除它们,你的凭据也将始终可以访问。
Instead, put your credentials (in this case, google-services.json
) in a GitHub Action secret and read that secret from the CI file.相反,将您的凭据(在本例中为google-services.json
)放入 GitHub 操作机密中,并从 CI 文件中读取该机密。 GitHub secrets are a great place to store this information because only the actions you run can read them and not other members of the repository. GitHub 秘密是存储此信息的好地方,因为只有您运行的操作才能读取它们,而存储库的其他成员则不能。
base64 google-services.json
在本地计算机上将您的文件编码为 base64,以便它可以轻松存储在环境变量中: base64 google-services.json
GOOGLE_SERVICES_JSON
复制 output 并将其存储在名为GOOGLE_SERVICES_JSON
的新 GitHub Action secret(可以在存储库的“设置”选项卡中找到)中- name: Create Google Services JSON File
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $GOOGLE_SERVICES_JSON | base64 -di > ./<folder>/google-services.json
<folder>
is whatever folder you need for your build. <folder>
是您构建所需的任何文件夹。 In my Action, I was trying to build an android APK, so my path was ./android/app/google-services.json
.在我的 Action 中,我试图构建一个 android APK,所以我的路径是./android/app/google-services.json
。 Also, depending on your path, you may need to create the directory first: run: mkdir <folder> && echo $GOOGLE_SERVICES_JSON | base64 -di >./<folder>/google-services.json
此外,根据您的路径,您可能需要先创建目录: run: mkdir <folder> && echo $GOOGLE_SERVICES_JSON | base64 -di >./<folder>/google-services.json
run: mkdir <folder> && echo $GOOGLE_SERVICES_JSON | base64 -di >./<folder>/google-services.json
base64 -di
decodes the encoded file and also gets rid of "garbage" characters, like newlines that were probably brought over when you copied the original encoded file into the Action secret. base64 -di
解码编码文件并去除“垃圾”字符,例如当您将原始编码文件复制到 Action secret 时可能带来的换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.