[英]Target particular site among Firebase multiple site hosting for react js and using github actions?
所以我有一个反应 js,我正在使用 firebase 来托管网站。 我创建了一个名为“parentproject”的项目,该项目具有多个站点“site1”“site2”。 我正在使用 GitHub 动作来检测我的两个分支“prod 和 dev”中的任何一个上的推送。 因此,当我推入 prod 分支时,我想部署在“site1”上,而当我推入 dev 分支时,我想部署在“site2”上。 我也在使用 github 工作流程。 我的 firebase 配置是:
.firebaserc
{
"projects": {
"default": "site1"
},
"targets": {
"parentProject": {
"hosting": {
"prod": ["site1"],
"dev": ["site2"],
}
}
}
}
firebase.json
{
"hosting": {
"target": "prod",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
我的推送分支的 yml 文件如下所示:
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools
name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- prod
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '14'
- run: npm ci
- run: CI=false npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
channelId: live
projectId: parentProject
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
每次我推送到产品时,我的网站都会部署在默认的 firebase 托管页面上,而不是“site1”。 任何建议都是有帮助的。
有一个名为“目标”的字段,您可以在其中设置要部署的特定站点,有关它的更多信息,请参见 firebase github 操作的文档: https: //tdeploy/target-stringEx.
(...)
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SECRETKEY }}'
channelId: live
projectId: parentProject
==> target: "<site id here>"
env:
FIREBASE_CLI_PREVIEWS: hostingchannels
您还必须在 firebase.json 上添加“站点”字段,例如:
{
"hosting": {
"target": "prod",
==> "site": "<id of the site in the firebase projet>",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.