Skip to content
Latchkey

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 public in firebase.json to 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-project

Gotchas

  • channelId: live deploys to production; any other id creates a preview channel.
  • The public key in firebase.json must match your actual build output.
  • SPA rewrites live in the rewrites array of firebase.json.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →