FirebaseExtended / action-hosting-deploy

Automatically deploy shareable previews for your Firebase Hosting sites
https://firebase.google.com/docs/hosting/github-integration
Apache License 2.0
705 stars 203 forks source link

[BUG] Github action does not find my project #298

Open clockwork189 opened 1 year ago

clockwork189 commented 1 year ago

I am running into a very weird bug that has had me stumped. The issue that I have is if I use my staging project Id: "metricwire.com:api-project-737636097603" the firebase build will fail. My guess is because it is not getting the project Id in th e build phase as indicated by this part in the debug:

  /usr/local/bin/npx firebase-tools@latest hosting:channel:deploy pr8-github-actions --only app-staging --expires 7d --project *** --debug

I tried changing my projectId to anything else, literally anything else eg: "test", "staging", "abc" and while the build still fails (because I am using a non-existent project which I am aware of), the error log still shows:

  /usr/local/bin/npx firebase-tools@latest hosting:channel:deploy pr8-github-actions --only app-staging --expires 7d --project test --debug

So my current problem is that if my projectId is "metricwire.com:api-project-737636097603" I get the *** in the build step for --project and it fails otherwise it shows the proper project Id in the build debug.

My current workaround is to create a completely different firebase project for staging, but it is still curious that this issue occurs.

Action config

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

name: Deploy to Firebase Hosting on PR
"on": pull_request
jobs:
    build_and_generate_previce:
        if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
        runs-on: ubuntu-latest
        environment: Development-App
        steps:
            - uses: actions/checkout@v3
            # - run: npm ci && npm run build
            - uses: FirebaseExtended/action-hosting-deploy@v0
              with:
                  repoToken: "${{ secrets.GITHUB_TOKEN }}"
                  firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING }}"
                  projectId: "metricwire.com:api-project-737636097603"
                  target: "app-staging"

Error message

/usr/local/bin/npx firebase-tools@latest hosting:channel:deploy pr8-github-actions --only app-staging --expires 7d --project *** --json
  npm WARN exec The following package was not found and will be installed: firebase-tools@12.4.5
  npm WARN deprecated har-validator@5.1.5: this library is no longer supported
  npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/[31](https://github.com/MetricWire/research-m5/actions/runs/5613999017/job/15211305490#step:3:34)42
  npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
  {
    "status": "error",
    "error": "Failed to authenticate, have you run \u001b[1mfirebase login\u001b[22m?"
  }
  {
    "status": "error",
    "error": "Failed to authenticate, have you run \u001b[1mfirebase login\u001b[22m?"
  }

  The process '/usr/local/bin/npx' failed with exit code 1
  Retrying deploy with the --debug flag for better error output
  /usr/local/bin/npx firebase-tools@latest hosting:channel:deploy pr8-github-actions --only app-staging --expires 7d --project *** --debug
  [2023-07-20T17:22:48.040Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
  [2023-07-20T17:22:48.060Z] SyntaxError: Unexpected token m in JSON at position 0
      at JSON.parse (<anonymous>)
      at ReadStream.<anonymous> (/home/runner/.npm/_npx/ba4f1959e38407b5/node_modules/google-auth-library/build/src/auth/googleauth.js:375:43)
      at ReadStream.emit (node:events:513:28)
      at ReadStream.emit (node:domain:489:12)
      at endReadableNT (node:internal/streams/readable:1[35](https://github.com/MetricWire/research-m5/actions/runs/5613999017/job/15211305490#step:3:38)9:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

  Error: Failed to authenticate, have you run firebase login?
  [2023-07-20T17:22:48.040Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
  [2023-07-20T17:22:48.060Z] SyntaxError: Unexpected token m in JSON at position 0
      at JSON.parse (<anonymous>)
      at ReadStream.<anonymous> (/home/runner/.npm/_npx/ba4f1959e38407b5/node_modules/google-auth-library/build/src/auth/googleauth.js:[37](https://github.com/MetricWire/research-m5/actions/runs/5613999017/job/15211305490#step:3:40)5:43)
      at ReadStream.emit (node:events:513:28)
      at ReadStream.emit (node:domain:489:12)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

  Error: Failed to authenticate, have you run firebase login?

  The process '/usr/local/bin/npx' failed with exit code 1
  Error: The process '/usr/local/bin/npx' failed with exit code 1

Expected behavior

Successful Build

Actual behavior

Build Fails

Psycarlo commented 1 year ago

Any fixes for this one?

seth-acuitymd commented 1 year ago

I wonder if this isn't actually something with the Firebase Action, but GitHub Actions itself thinking that your projectID is a secret value? If you pass it in as an environment variable to the workflow and call it that way, does anything change?

Something like

jobs:
    build_and_generate_previce:
        if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
        env:
          project-id: "metricwire.com:api-project-737636097603"
        runs-on: ubuntu-latest
        environment: Development-App
        steps:
            - uses: actions/checkout@v3
            # - run: npm ci && npm run build
            - uses: FirebaseExtended/action-hosting-deploy@v0
              with:
                  repoToken: "${{ secrets.GITHUB_TOKEN }}"
                  firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING }}"
                  projectId: ${{ env.project-id }}
                  target: "app-staging"
Psycarlo commented 1 year ago

I wonder if this isn't actually something with the Firebase Action, but GitHub Actions itself thinking that your projectID is a secret value? If you pass it in as an environment variable to the workflow and call it that way, does anything change?

Something like


jobs:

    build_and_generate_previce:

        if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"

        env:

          project-id: "metricwire.com:api-project-737636097603"

        runs-on: ubuntu-latest

        environment: Development-App

        steps:

            - uses: actions/checkout@v3

            # - run: npm ci && npm run build

            - uses: FirebaseExtended/action-hosting-deploy@v0

              with:

                  repoToken: "${{ secrets.GITHUB_TOKEN }}"

                  firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING }}"

                  projectId: ${{ env.project-id }}

                  target: "app-staging"

I don't think so because I have another project with the projectId like that and runs fine.

chirag-biradar commented 3 months ago

@clockwork189 did you find any fix?