通过 GitHub 拉取请求在实际和预览渠道中实施部署
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以通过 GitHub 操作将部署集成到 Firebase Hosting。以下是此 GitHub 操作可以完成的任务:
为 GitHub 代码库中的每个拉取请求 (PR) 创建一个新的预览渠道(及其关联的预览网址)。
向 PR 添加注释并附上预览网址,这样您和每位审核者都可以在应用的“预览”版本中查看和测试 PR 的更改。

自动在关联的预览渠道中实施部署,以便每次提交时使用所做更改来更新预览网址。该网址不会随着每次提交新内容而发生变化。
(可选)在合并 PR 时,将 GitHub 代码库的当前状态部署到您的实际渠道。
提醒:使用预览网址时,您的应用会与 Firebase 项目的实际后端资源进行互动。
设置“在 Firebase Hosting 中实施部署”这项 GitHub 操作
创建 GitHub 代码库(公共或专用),或使用现有代码库。您必须拥有代码库的管理员权限。
在代码库的本地版本中,使用 firebase init
命令设置 Firebase Hosting。
按照 CLI 提示进行操作,该命令会自动完成 GitHub 操作的设置:
在您的 Firebase 项目中创建有权在 Firebase Hosting 中实施部署的服务账号。
加密该服务账号的 JSON 密钥,并将其作为 GitHub 密钥上传到指定的 GitHub 代码库。
写入 GitHub 工作流 yaml
配置文件,这些文件引用的是新创建的密钥。这些文件用于配置可在 Firebase Hosting 中实施部署的 GitHub 操作。
在 GitHub 中,创建一个新分支并提交 CLI 创建的工作流 yaml
文件。
将该分支发布到 GitHub 代码库。
合并该分支。
大功告成!此 GitHub 代码库中的任何后续 PR 都将自动获得相应的“预览网址”!
详细了解 GitHub 操作
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-12。
[null,null,["最后更新时间 (UTC):2025-08-12。"],[],[],null,["\u003cbr /\u003e\n\nYou can integrate deploys to Firebase Hosting via a GitHub Action. Here's\nwhat this GitHub Action can do for you:\n\n- Creates a new preview channel (and its associated preview URL) for every PR on\n your GitHub repository.\n\n- Adds a comment to the PR with the preview URL\n so that you and each reviewer can view and test the PR's changes in a\n \"preview\" version of your app.\n\n- Updates the preview URL with changes from each commit by automatically\n deploying to the associated preview channel. The URL doesn't change with each\n new commit.\n\n- *(Optional)* Deploys the current state of your GitHub repo to your live\n channel when the PR is merged.\n\nReminder: When using preview URLs, your app interacts with the *real* backend\nresources of your Firebase project.\n\nSet up the GitHub Action to deploy to Firebase Hosting\n\n1. Create a GitHub repository (public or private) or use an existing one. You\n must have admin permissions for the repository.\n\n2. In a local version of your repo, set up Firebase Hosting using the\n [`firebase init` command](/docs/hosting/quickstart#initialize).\n\n - If you've NOT set up Hosting, run this version of the command\n from the root of your local directory:\n\n ```\n firebase init hosting\n ```\n - If you've ALREADY set up Hosting, then you just need to set up the\n GitHub Action part of Hosting. Run this version of the command from\n the root of your local directory:\n\n ```\n firebase init hosting:github\n ```\n3. Follow the CLI prompts, and the command will automatically take care of\n setting up the GitHub Action:\n\n - Creates a service account in your Firebase project with permission to\n deploy to Firebase Hosting.\n\n - Encrypts that service account's JSON key and uploads it to the specified\n GitHub repository as a\n [GitHub secret](//docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets).\n\n - Writes GitHub workflow `yaml` configuration files that reference the\n newly created secret. These files configure the GitHub Action to deploy to\n Firebase Hosting.\n\n4. In GitHub, create a new branch and commit the workflow `yaml` files created\n by the CLI.\n\n5. Publish the branch to your GitHub repository.\n\n6. Merge the branch.\n\nThat's it! Any subsequent PR in this GitHub repo will automatically get its own\n\"preview URL\"!\n\nLearn more about the GitHub Action\n\n- Firebase maintains the \"Deploy to Firebase Hosting\" GitHub Action as an\n open-source project.\n [View the source code.](//github.com/marketplace/actions/deploy-to-firebase-hosting)\n\n- The \"Deploy to Firebase Hosting\" GitHub Action allows for further\n configuration, like customizing the expiry date for a preview channel or\n setting a non-live channel to deploy to when a PR is merged.\n [Learn about the available configuration options.](//github.com/marketplace/actions/deploy-to-firebase-hosting#options)\n\n- Learn more about\n [GitHub Actions](//docs.github.com/en/free-pro-team@latest/actions),\n in general."]]