部署上線(&A);透過 GitHub 提取要求預覽管道
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以透過 GitHub 動作,將部署作業整合至 Firebase Hosting。這個 GitHub 動作可為您執行下列操作:
為 GitHub 存放區的每個 PR 建立新的預覽管道 (和相關聯的預覽網址)。
在 PR 中新增含有預覽網址的註解,方便您和每位審查人員在應用程式的「預覽」版本中查看及測試 PR 的變更。

系統會自動部署至相關聯的預覽管道,根據每次提交的變更更新預覽網址。網址不會隨著每次新提交而變更。
(選用) 在合併提取要求時,將 GitHub 存放區的目前狀態部署至即時頻道。
提醒:使用預覽網址時,應用程式會與 Firebase 專案的實際後端資源互動。
設定 GitHub Action,以便部署至 Firebase Hosting
建立 GitHub 存放區 (公開或私人),或使用現有存放區。您必須具備存放區的管理員權限。
在存放區的本機版本中,使用 firebase init
指令設定 Firebase Hosting。
按照 CLI 提示操作,指令會自動設定 GitHub Action:
在 Firebase 專案中建立服務帳戶,並授予部署至 Firebase Hosting 的權限。
加密該服務帳戶的 JSON 金鑰,並以 GitHub 密鑰的形式上傳至指定的 GitHub 存放區。
撰寫 GitHub 工作流程 yaml
設定檔,參照新建立的密鑰。這些檔案會設定 GitHub Action,以便部署至 Firebase Hosting。
在 GitHub 中,建立新分支版本並提交 CLI 建立的工作流程 yaml
檔案。
將分支發布至 GitHub 存放區。
合併分支版本。
任務完成!這個 GitHub 存放區中後續的任何 PR,都會自動取得專屬的「預覽網址」!
進一步瞭解 GitHub Action
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[],[],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."]]