You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Deploy Python Firebase Functions with GitHub Actions
2
+
This project contains a sample workflow for automating the deployment of a Python Firebase Function with GitHub Actions. The Firebase files and Python code deploy a simple hello world function with Flask as a Firebase serverless Function. Note that Python 3.11 is the latest version supported by Python Firebase Functions v2 as of April 2025.
3
+
4
+
# GitHub Actions Trigger
5
+
The action is triggered from any push to the feature branch `add-deploy-workflow` or a manual trigger. The default for the feature branch is `staging`. The manual trigger allows the user to select a GitHub branch and Firebase alias `staging`/`prod`.
6
+
7
+
# Python package manager
8
+
The project uses `uv`, a modern package manager, which creates a virtual environment named `.venv`. Firebase expects a virtual environment named `venv` with `pip` installed. We can use `uv` commands to do so. Note that we are running `uv sync` with the `--active` flag because we need to maintain two virtual environments: `venv` for Firebase and the default `.venv` for uv.
9
+
10
+
# GCP Service Account
11
+
Deployment depends upon a Google Cloud service account for authentication. Set this up in the GCP console by creating a dedicated service account for GitHub Actions. You'll need to do this for each Firebase project.
12
+
13
+
GCP console > IAM & Admin > Service Accounts > Create Service Account
14
+
Name: github-actions-deploy-staging
15
+
Description: Deploy to Firebase with GitHub Actions
16
+
Roles:
17
+
- Firebase Admin SDK Admin
18
+
- Cloud Functions Admin
19
+
- Service Account User
20
+
Skip granting users access and click Done.
21
+
22
+
Alternatively, use `gcloud` CLI for each project:
23
+
24
+
`gcloud config set project PROJECT_ID`
25
+
26
+
`gcloud iam service-accounts create github-actions-deploy \`
27
+
` --description="Deploy to Firebase project with GitHub Actions" \`
Each Firebase project requires a service account key. Download keys from Google and remember to exclude them from version control.
51
+
52
+
Store the keys as secrets in your repo:
53
+
GitHub repo → Settings → Secrets and variables → Actions
54
+
FIREBASE_PROD_SERVICE_ACCOUNT
55
+
FIREBASE_STAGING_SERVICE_ACCOUNT
56
+
57
+
Alternatively, use GitHub CLI:
58
+
`gh secret set FIREBASE_STAGING_SERVICE_ACCOUNT --repo user/repo-name < key-staging.json`
59
+
`gh secret set FIREBASE_PROD_SERVICE_ACCOUNT --repo user/repo-name < key-prod.json`
60
+
61
+
# Firebase CLI
62
+
It’s important to use the latest version of `firebase-tools`, which will automatically enable the correct APIs for the Python Firebase Function in the corresponding GCP project.
63
+
64
+
# Debugging and Credential Verification
65
+
The steps labeled (Debug) are for debugging, verifying credentials, and checking settings, so they can be omitted. The `firebase deploy` command uses a `--debug` flag that isn't strictly necessary. The GitHub Actions workflow would run faster without the debugging steps and flags.
0 commit comments