Search code examples
firebasegithubfirebase-hostinggithub-actionsfirebase-cli

How can I deploy to different firebase environments using github actions and w9jds/firebase-action


I'm trying to set up CI to firebase for my angular project using Github Actions, but I have both a staging and production environment and I want to deploy to each of them according to which branch I pushed to.

I know that I can create two different workflow scripts for my master and dev branches, but I can't figure out how to deploy to the different firebase environments using w9jds/firebase-action.

When I use the script:

on:
  push:
    branches:
      - dev

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: Download Artifact
        uses: actions/download-artifact@master
        with:
          name: dist
          path: dist
      - name: Deploy to Firebase
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only hosting:staging
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

I get the following error:

Error: No project active, but project aliases are available.

Run firebase use <alias> with one of these options:

  production (#####)
  staging (#####)

What am I doing wrong?


Solution

  • I think you need:

    with:
      args: deploy --only hosting --project staging
    

    The hosting:* deploy target is for multiple sites in the same project, to specify a project you should use --project or -P.