DEV Community

Emmanuel Barroga
Emmanuel Barroga

Posted on

Autodeploy subdirectory to Firebase

Google Firebase has a pretty straightforward guide to setting up auto-deploy from Github, which you can take a look at here: https://firebase.google.com/docs/hosting/github-integration

In a nutshell, you follow these steps:

  • Install firebase-tools via npm:

    npm install -g firebase-tools

  • Setup your project for firebase hosting:

    firebase init hosting

  • Setup your project with Github Actions to auto-deploy on PR/Merge:

    firebase init hosting:github

One thing to note is the root directory of your repository is the working directory for the Github actions. For example, if you have a repository that has a subdirectory named "front", which contains your actual project files, package.json, etc.., you have to modify the generated .yml file that firebase-tools generates so that the actions run within the working directory. After you run an npm command, you use 'working-directory'

You also need to set the working directory for the 'FirebaseExtended/action-hosting-deploy@v0' action, which is set like so: entryPoint: <directory_that_your_firebase.json_is_in>

Here is an example:

# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '14.17.3'
      - run: npm ci 
        working-directory: ./front
      - run: npm run build
        working-directory: ./front
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT }}'
          channelId: live
          projectId: project
          entryPoint: ./front
Enter fullscreen mode Exit fullscreen mode

Top comments (0)