Search code examples
firebasegithub-actionsfirebase-hosting

Firebase Hosting config requires public field when using Github Actions but works if deploying locally?


I'm hosting a NextJS web app on Firebase Hosting. I'd like to get the Github Actions Integration to work for distributing my web app.

In the documentation, the public field is required but I specify a source: https://firebase.google.com/docs/hosting/full-config#specify-files-to-deply

When I run firebase deploy --only hosting on my local machine (with no public), everything works as intended and my web app is deployed.

My issue is using Github Actions. When I approve my Pull Request on Github, the Action triggers but has an error on the FirebaseExtended/action-hosting-deploy@v0 step:

Must supply a \"public\" directory or at least one rewrite or redirect in each \"hosting\" config. 

.firebaserc

{
  "hosting": {
    "source": ".",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "frameworksBackend": {
      "region": "us-central1"
    }
  }
}

.github/workflows/deploy-to-firebase-hosting.yml

This is autogenerated by the firebase init hosting command.

name: Deploy to Firebase Hosting on PR merge
"on":
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm ci && npm run build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_CHECKMATE_PROD }}"
          channelId: live
          projectId: myproject

I added "public": "public" to the .firebaserc which is successful in deploying but the page looks like this:

From what I can see my issues are:

  • Include public field but Firebase Hosting doesn't see anything in the file. Maybe I'm not specifying the correct public directory? Not sure if this is different if NextJS build runs.
    • ChatGPT suggested I use out as the public directory but this resulted in an error Error: Directory 'out' for Hosting does not exist.
  • Include source but Firebase Hosting requires a public (yet I can get away from public if I deploy locally)

Solution

  • I found that upgrading firebase-tools made this issue go away.

    npm install firebase-tools

    When I upgrade and rerun the v2 becomes v3:

    steps:
          - uses: actions/checkout@v3
          - run: npm ci && npm run build
          - uses: FirebaseExtended/action-hosting-deploy@v0
    

    There are a myriad of other issues with permissions I need to resolve but at least this issue is no longer the case.