Esegui il deployment nei canali di anteprima e in quelli pubblicati tramite le richieste di pull di GitHub
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi integrare i deployment in Firebase Hosting tramite un'azione GitHub. Ecco
cosa può fare per te questa azione GitHub:
Crea un nuovo canale di anteprima (e il relativo URL di anteprima) per ogni richiesta di pull nel tuo repository GitHub.
Aggiunge un commento alla richiesta di pull con l'URL di anteprima
in modo che tu e ogni revisore possiate visualizzare e testare le modifiche della richiesta di pull in una
versione "anteprima" della tua app.

Aggiorna l'URL di anteprima con le modifiche di ogni commit eseguendo automaticamente
il deployment nel canale di anteprima associato. L'URL non cambia a ogni
nuovo commit.
(Facoltativo) Esegue il deployment dello stato attuale del repository GitHub sul tuo canale live quando la richiesta di pull viene unita.
Promemoria: quando utilizzi gli URL di anteprima, la tua app interagisce con le risorse di backend reali del tuo progetto Firebase.
Configurare l'azione GitHub per il deployment su Firebase Hosting
Crea un repository GitHub (pubblico o privato) o utilizzane uno esistente. Devi
disporre delle autorizzazioni di amministratore per il repository.
In una versione locale del repository, configura Firebase Hosting utilizzando il
comando firebase init
.
Se NON hai configurato Hosting, esegui questa versione del comando
dalla radice della directory locale:
firebase init hosting
Se hai GIÀ configurato Hosting, devi solo configurare la parte di Hosting relativa all'azione GitHub. Esegui questa versione del comando dalla
directory principale della tua directory locale:
firebase init hosting:github
Segui le istruzioni della CLI e il comando si occuperà automaticamente
di configurare l'azione GitHub:
Crea un account di servizio nel tuo progetto Firebase con l'autorizzazione per
il deployment su Firebase Hosting.
Cripta la chiave JSON del service account e la carica nel repository GitHub specificato come
secret GitHub.
Scrive i file di configurazione del flusso di lavoro GitHub yaml
che fanno riferimento al
segreto appena creato. Questi file configurano l'azione GitHub per il deployment in
Firebase Hosting.
In GitHub, crea un nuovo ramo ed esegui il commit dei file yaml
del flusso di lavoro creati
dalla CLI.
Pubblica il ramo nel tuo repository GitHub.
Unisci il ramo.
Ecco fatto. Ogni PR successiva in questo repository GitHub avrà automaticamente il proprio
"URL di anteprima".
Scopri di più sull'azione GitHub
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-08 UTC.
[null,null,["Ultimo aggiornamento 2025-08-08 UTC."],[],[],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."]]