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
695 stars 202 forks source link

[BUG] Fails to deploy NextJS app #254

Open Barefoot-Dev opened 1 year ago

Barefoot-Dev commented 1 year ago

I'm able to deploy my NextJS app directly (firebase deploy), however when I deploy via a PR or Merge action I get an error.

My repo is structured like so (the next app is in /frontend)

My firebase.json is:

{
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "source": "frontend",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
  }
}

Action config

name: Deploy to Firebase Hosting on PR
'on': pull_request
jobs:
  build_and_preview:
    if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SDXCRYPTO_ALGOVERA }}'
          projectId: sdxcrypto-algovera

Error message

Error: Cannot deploy a web framework to hosting because the experiment webframeworks is not enabled. To enable webframeworks run firebase experiments:enable webframeworks

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

Expected behavior

Deploys sucessfully. I have enabled the webframeworks experiment and re-tried but to no avail.

Actual behavior

Fails to deploy.

BolajiAyodeji commented 1 year ago

I'm experiencing the same issue. I tried adding the installation command for firebase to the action and manually enabling experiment webframeworks but it all still fails. Is there something that can be done to automatically enable this with actions?

Screenshot 2022-11-11 at 8 07 35 AM
bruceharrison1984 commented 1 year ago

You have to enable the experiments for firebase tools as a separate command:

      - name: Enable Firebase Experiments
        run: /usr/local/bin/npx firebase-tools@latest experiments:enable webframeworks

      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_POETZ_LAKE_HOUSE }}'
          channelId: live
          projectId: poetz-lake-house

It's annoying, but required for now

irealva commented 1 year ago

Seemingly still an issue to deploy to a preview channel. Is there any workaround or would this get fixed anytime soon?

Screen Shot 2022-11-17 at 4 33 28 PM

Thanks

Barefoot-Dev commented 1 year ago

You have to enable the experiments for firebase tools as a separate command:

      - name: Enable Firebase Experiments
        run: /usr/local/bin/npx firebase-tools@latest experiments:enable webframeworks

      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_POETZ_LAKE_HOUSE }}'
          channelId: live
          projectId: poetz-lake-house

It's annoying, but required for now

For me this raises the error Could not determine the web framework in use.

isheraz commented 1 year ago

For Next.js I found that it needs SSR to be deployed as a function as well, which is why the deploy fails and we see the error on pipeline but shows a different error. deploys successfully when we use firebase deploy You can see this error when you try replicating the deploy process and run : firebase hosting:channel:deploy hosting-channel-name-here --expires 7d --project project-name-here --json

{
  "status": "error",
  "error": "Web frameworks with dynamic content do not yet support deploying to preview channels"
}
isheraz commented 1 year ago

I see there are 2 potential fixes submitted but @FirebaseExtended hasn't accepted either one. Fix # 1 Fix # 2

Potential Replacement: https://github.com/w9jds/firebase-action

dannydeut commented 1 year ago

I got this to work by adding the environment variable FIREBASE_CLI_EXPERIMENTS which is part of firebase-tools.

- name: Deploy to Firebase
  uses: FirebaseExtended/action-hosting-deploy@v0
  with:
    repoToken: '${{ secrets.GITHUB_TOKEN }}'
    firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT }}'
    channelId: live
    projectId: ...
  env:
    FIREBASE_CLI_EXPERIMENTS: webframeworks