GitHub Action for Python based Firebase projects
ActionsTags
(2)This Action for firebase-tools enables arbitrary actions with the
firebase command-line client, it is a shameless fork of firebase-action
but with a python focus as I could not get that library to work properly to create a virtual environment.
args- Required. This is the arguments you want to use for thefirebasecli
-
GCP_SA_KEY- A normal service account key (json format) or a base64 encoded service account key with the needed permissions for what you are trying to deploy/update.- Since the service account is using the App Engine default service account in the deploy process, it also needs the
Service Account Userrole. - If deploying functions, you would also need the
Cloud Functions Developerrole.- If the deploy has scheduled functions, include the
Cloud Scheduler Adminrole. - If the deploy requires access to secrets, include the
Secret Manager Viewerrole. - If updating Firestore Rules, include the
Firebase Rules Adminrole. - If the project is using Blocking functions (beforeCreate or beforeSignin) , include the
Firebase Functions Adminrole.
- If the deploy has scheduled functions, include the
- If updating Firestore Indexes, include the
Cloud Datastore Index Adminrole. - If deplying Hosting files, include the
Firebase Hosting Adminrole. - For more details: https://firebase.google.com/docs/hosting/github-integration
- Since the service account is using the App Engine default service account in the deploy process, it also needs the
-
GOOGLE_APPLICATION_CREDENTIALS- **Required if GCP_SA_KEY **. the location of a credential JSON file. For more details: https://cloud.google.com/docs/authentication/application-default-credentials#GAC -
PROJECT_ID- Optional. To specify a specific project to use for all commands. Not required if you specify a project in your.firebasercfile. If you use this, you need to giveViewerpermission roles to your service account otherwise the action will fail with authentication errors. -
PROJECT_PATH- Optional. The path to where your requirements.txt should exist and where the python virtual environment will be created -
CREATE_VENV- Optional. This determines whether to create the virtual environment based on the requirements.txt, you will need -
CONFIG_VALUES- Optional. The configuration values for Firebase function that would normally be set withfirebase functions:config:set [value]. Example:CONFIG_VALUES: stripe.secret_key=SECRET_KEY zapier.secret_key=SECRET_KEY.
To authenticate with Firebase, and deploy to a Firebase Function on merges/pushes to main branch:
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build-prod
- name: Archive Production Artifact
uses: actions/upload-artifact@master
with:
name: dist
path: dist
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Deploy to Firebase
uses: gannonk08/firebase-action-python@v0.0.1
with:
args: deploy --only functions --debug
env:
CREATE_VENV: true
PROJECT_PATH: functions
GCP_SA_KEY: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_KEY }}If you have multiple hosting environments you can specify which one in the args line.
e.g. args: deploy --only hosting:[environment name]
If you want to add a message to a deployment (e.g. the Git commit message) you need to take extra care and escape the quotes or the YAML breaks.
with:
args: deploy --message \"${{ github.event.head_commit.message }}\"The versioning of this project increments with firebase-tools starting at version 13.16.0. The container is versioned
alongside in order to allow different version of firebase-tools to be used. You can also pull down the container locally
to modify and inspect it as needed. e.g.
name: Deploy to Firebase
uses: docker://gannonk/firebase-action-python:master
with:
args: deploy --only functions --debug
env:
CREATE_VENV: true
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
The Dockerfile and associated scripts and documentation in this project are released under the MIT License.
If you decide to do separate jobs for build and deployment (which is probably advisable), then make sure to clone your
repo as the Firebase-cli requires the firebase repo to deploy (specifically the firebase.json)
I have only personally used this to deploy a firebase function. If there are issues deploying other python firebase components feel free to submit an issue or create a pull request.
GitHub Action for Python based Firebase projects is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.