# Deploy Firebase Functions from GitHub Actions

Yes. An agent adds a GitHub Actions workflow that lints, tests under the emulator and deploys your Firebase Functions on push to main with keyless auth.

[Run this on Rush](https://cloud.getrush.ai/run/add-deploy-workflow/firebase-functions/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the project before it writes a workflow, because a Firebase deploy depends on what `firebase.json` declares. In a project like `Node/quickstarts/uppercase-firestore` in firebase/functions-samples, `firebase.json` names a functions `codebase` of `uppercase-firestore`, points `firestore.rules` and `firestore.indexes.json` at the Firestore config, and sets emulator ports 5001 for functions and 8080 for Firestore with the UI enabled. `functions/package.json` depends on `firebase-functions ^7.4.0` and `firebase-admin ^14.5.0`, sets `engines.node` to `24`, and has scripts `lint` (`eslint --max-warnings=0 .`), `serve`, `shell`, `deploy` (`firebase deploy --only functions`) and `logs`. `functions/index.js` exports two second-generation functions: `addmessage`, an `onRequest` handler that writes `req.query.text` into the `messages` collection, and `makeuppercase`, an `onDocumentCreated("/messages/{documentId}")` trigger that logs through `firebase-functions`' `logger` and writes an `uppercase` field back. The lockfile is `pnpm-lock.yaml`, and the sample's `firestore.rules` only allow authenticated reads and writes. There is no `.firebaserc`, so the project id must come from a secret, and no workflow deploys anything; the repository's own `test_node.yml` lints, compiles and tests but never calls `firebase deploy`.

The agent writes `.github/workflows/deploy-functions.yml` with two jobs. `check` runs on pull requests and pushes: checkout, `pnpm/action-setup`, `actions/setup-node` with `node-version: 24` to match `engines`, `pnpm install --frozen-lockfile` in `functions/`, `pnpm run lint`, then `npx firebase-tools emulators:exec --only functions,firestore "node --test"` so the two functions load under the emulator exactly as `serve` would start them; where the project has no test files yet, the step at least proves the code loads and the emulator starts with the ports from `firebase.json`. `deploy` runs only on `push` to `main`, needs `check`, and runs `npx firebase-tools deploy --only functions:uppercase-firestore --project "$FIREBASE_PROJECT_ID" --non-interactive --force`, using the codebase name so a repository with several codebases deploys only this one. Both jobs set `concurrency` on the branch so two merges in a row cannot deploy out of order.

For credentials the agent avoids a long-lived service account key. The `deploy` job sets `permissions: id-token: write` and `contents: read` and uses `google-github-actions/auth` with `workload_identity_provider` and `service_account` from repository secrets, so Google issues a short-lived token to the workflow run. The pull request lists what the reader must create once in Google Cloud: a Workload Identity Pool and provider trusting `token.actions.githubusercontent.com` for this repository, and a service account with the roles `firebase deploy --only functions` needs (Cloud Functions Developer, Service Account User on the runtime account, Firebase Admin or the narrower Firebase Develop Admin, and Artifact Registry access for the function image). It also lists the three secrets the workflow reads: `FIREBASE_PROJECT_ID`, `GCP_WORKLOAD_IDENTITY_PROVIDER` and `GCP_SERVICE_ACCOUNT`.

In its sandbox the agent runs `pnpm install --frozen-lockfile` and `pnpm run lint` in `functions/`, starts the emulators with `firebase-tools` to confirm both functions register under the configured ports, and runs `actionlint` on the new workflow. It cannot deploy, since the sandbox has no Google Cloud project or identity federation, and the pull request says so plainly. It pins each action to a version tag the way `test_node.yml` pins to SHAs with a comment, and keeps `firebase-tools` invoked through `npx` at a pinned major so the deploy CLI version is visible in the file.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add a GitHub Actions workflow that deploys the Firebase Functions in this project and open a pull request. Read firebase.json, functions/package.json, functions/index.js and any existing workflows first. Write .github/workflows/deploy-functions.yml with a check job on pull requests and pushes that installs with the lockfile's package manager at the Node version engines declares, runs the lint script and starts the functions and Firestore emulators to prove the functions load, and a deploy job that runs only on push to main after check, authenticates with google-github-actions/auth using Workload Identity Federation from secrets rather than a service account key, and runs firebase-tools deploy for this project's functions codebase only, non-interactively, with concurrency on the branch. Pin every action. Do not commit a .firebaserc; read the project id from a secret. Run the install, lint, emulator start and actionlint in the sandbox and quote the output. In the description list the Google Cloud resources, IAM roles and repository secrets the reader must create, and state that no deploy was made.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds one file, `.github/workflows/deploy-functions.yml`, and nothing else. The `check` job mirrors the project's own `lint` script and emulator ports; the `deploy` job is gated on `main`, authenticates with Workload Identity and deploys the `uppercase-firestore` codebase only. `firebase.json`, `functions/index.js` and `package.json` are unchanged.

The description quotes `pnpm run lint`, the emulator start-up lines showing `addmessage` and `makeuppercase` registered, and the `actionlint` result from the sandbox. It has a numbered setup list for the Workload Identity Pool, provider, service account, IAM roles and three repository secrets, and it states that no deploy ran. The repository's existing CI runs on the pull request as before.

Before merging, a reviewer creates the Google Cloud resources from the list, adds the three secrets, and reads the `deploy` job's `if:` and `concurrency` settings against their branching model. If the project also deploys Firestore rules or hosting, they decide whether to widen `--only` in a follow-up; the agent keeps it to functions on purpose.

## Run it on every Firebase project deployed by hand

A team with several Firebase projects sends one `POST /o/{org}/sessions` per repository with this prompt and the repository in `resources`. `GET /o/{org}/github` lists the repositories the Rush GitHub App installation reaches, so a script can start a run for each one that has a `firebase.json` with a `functions` block and no workflow calling `firebase deploy`. Each run reads that project's codebase name, Node engine, package manager and emulator ports, so a TypeScript project with a `build` script gets a compile step before the emulator, and an npm project gets `npm ci`.

Set a webhook URL on the API key and Rush POSTs `run.completed` or `run.failed` when each turn ends, with `session_url` to read the pull request link. Send a fresh UUID as `request_id` with each request so a retried request returns the run already started.

## Why run it on Rush?

A deploy workflow is a small file with many places to be wrong: the Node version, the package manager, the codebase name in `--only`, the IAM roles behind a token exchange. In its own sandbox the agent reads each value from `firebase.json` and `functions/package.json`, starts the real emulators to prove the functions load under those settings, and lints the workflow, with every command's output kept in the run's record. The pull request is a workflow that matches the project, plus the exact cloud setup list the reader needs.

Keyless authentication is the part teams most often skip because it takes research; here the research is in the description. The same request runs across every Firebase repository a team owns, each in its own sandbox, each with a pull request tailored to its own `firebase.json`.

## Frequently asked questions

### Why Workload Identity instead of a FIREBASE_TOKEN or a service account JSON secret?

Because both are long-lived credentials sitting in repository secrets, and `firebase login:ci` tokens are deprecated. With Workload Identity Federation the workflow run exchanges its GitHub OIDC token for a short-lived Google token scoped to one service account, and nothing to rotate is stored in GitHub.

### Does the agent deploy anything itself?

No. The sandbox has no Google Cloud project or identity federation, so it stops at install, lint, emulator start and `actionlint`, and the pull request says so. The first real deploy happens from the workflow after you add the secrets and merge.

### What about Firestore rules and indexes?

The workflow deploys functions only, with `--only functions:<codebase>`, because rules changes deserve their own review and a `firestore.rules` deploy is instant and hard to roll back. If you want rules deployed from the same workflow, widening `--only` is a one-token change the description points at.

### Will the emulator step fail if the project has no tests?

No. The step runs `emulators:exec` with a command that only needs the functions to load; if the functions export fails or `firebase.json` names a missing codebase, the emulator exits non-zero and the job fails. When tests exist the agent runs them inside the same `emulators:exec` so they get the emulated Firestore.

## More Firebase Functions jobs

- [Add Input Validation to Firebase Cloud Functions](https://getrush.ai/run/add-input-validation/firebase-functions/)
- [Add Rate Limiting to Firebase Callable Functions](https://getrush.ai/run/add-rate-limiting/firebase-functions/)
- [Turn On Safe Retries for Event-Driven Firebase Cloud Functions](https://getrush.ai/run/add-retry-policies/firebase-functions/)

## The same job on other stacks

- [Add a GitHub Pages Deploy Workflow to a Hugo Site](https://getrush.ai/run/add-deploy-workflow/hugo/)
- [Add a GitHub Pages Deploy Workflow to a Jekyll Site](https://getrush.ai/run/add-deploy-workflow/jekyll/)
- [Add a Deploy Workflow for a Lit Component's Docs Site](https://getrush.ai/run/add-deploy-workflow/lit/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
