Local firebase and GitHub action Firebase functions deployment behave differently

74 views Asked by At

I'm trying to deploy a firebase function similar to:

export const task = scheduler.onSchedule(
  '1 0 * * *',
  async () => {
    await foo();
  },
);

Deploying from my local machine using npm run build && firebase deploy --only functions works fine with no issues. I authenticated with a service account key by setting GOOGLE_APPLICATION_CREDENTIALS

On GitHub actions, it also deployed successfully. Here's the workflow.yml file

name: Deploy firebase functions
on:
  push:
    branches:
      - test

jobs:
  build-and-deploy:
    permissions:
      id-token: write
      contents: read

    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install Fireabase CLI
        run: npm install -g firebase-tools

      - name: Install deps
        run: cd functions && npm install

      - id: auth
        name: Authenticate to Google Cloud
        uses: google-github-actions/auth@v1
        with:
          workload_identity_provider: ${{secrets.WORKLOAD_IDENTITY_PROVIDER}}
          service_account: ${{secrets.SERVICE_ACCOUNT}}

      - name: Using test
        run: cd functions && firebase use project_id

      - name: Create .env file
        run: |
          cd functions
          touch .env
          echo "EMAIL_HOST=${{ secrets.EMAIL_HOST }}" >> .env
          echo "EMAIL_USER=${{ secrets.EMAIL_USER }}" >> .env
          echo "EMAIL_PASS=${{ secrets.EMAIL_PASS }}" >> .env
          echo "INVITE_EMAIL_SENDER='REDACTED' >> .env
          cat .env

      - name: Deploy
        run: cd functions && npm run deploy

I used the SAME service account connected to a Workload Identity Provider. The deployment was fine.

The problem is that for the GitHub actions deployment, the scheduler job has a failed status. Whereas the job runs fine for the local deployment

I replaced

  - id: auth
        name: Authenticate to Google Cloud
        uses: google-github-actions/auth@v1
        with:
          workload_identity_provider: ${{secrets.WORKLOAD_IDENTITY_PROVIDER}}
          service_account: ${{secrets.SERVICE_ACCOUNT}}

with

  - id: auth
        name: Authenticate to Google Cloud
        uses: google-github-actions/auth@v1
        with:
          credentials_json: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}}

and got the same behaviour.

On inspecting the function logs in the Firebase console, I saw this

DEFAULT 2023-11-02T13:29:25.485720Z TypeError: Cannot read properties of undefined (reading 'headers')
DEFAULT 2023-11-02T13:29:25.485757Z at /workspace/node_modules/firebase-functions/lib/v2/trace.js:12:68
DEFAULT 2023-11-02T13:29:25.485771Z at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:141:25
DEFAULT 2023-11-02T13:29:25.485780Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I also notice if i deploy via GitHub actions when the previous deployment was from my local machine, the scheduler job has a status of Has not run yet and vice versa.

Why does the job fail for GitHub actions deployment?

0

There are 0 answers