How to Deploy a Static Site to Firebase Hosting From CI
The Firebase CLI deploys the public directory named in firebase.json when authenticated with a service account.
Run firebase deploy --only hosting --project <id> with a service account exported to GOOGLE_APPLICATION_CREDENTIALS, or use the FirebaseExtended/action-hosting-deploy action for previews.
Steps
- Create a service account with the Firebase Hosting Admin role.
- Store the JSON key as a CI secret.
- Set
publicinfirebase.jsonto your build directory. - Run
firebase deploy --only hosting.
Workflow
.github/workflows/ci.yml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
channelId: live
projectId: my-projectGotchas
channelId: livedeploys to production; any other id creates a preview channel.- The
publickey in firebase.json must match your actual build output. - SPA rewrites live in the
rewritesarray of firebase.json.
Related guides
How to Configure SPA Fallback (404 to index.html) on DeployConfigure a single-page app so unknown routes serve index.html instead of a 404, letting the client-side rout…
How to Create a Preview Deploy Per Pull RequestPublish a preview deploy for every pull request from CI and post its URL back on the PR, so reviewers can cli…