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

Add a way to use different filename for firebase.json #333

Open timofei-iatsenko opened 9 months ago

timofei-iatsenko commented 9 months ago

The use case you're trying to solve

We ha ve a monorepo with multiple firebase projects in it. We have the following layout of monorepo:

.
├── fireabse.project1.json — (firebase configurations for each project in the root)
├── fireabse.project2.json
├── apps (where apps is stored. Firabse functions is also an app)
│  ├── frontendApp1
│  ├── frontendApp2
│  ├── functionsApp1
│  └── functionsApp2
├── libs (— here libs go)
└── projects (here live firebase projects with it's configurations)
  ├── project1
  └── project2
    ├── firestore.rules
    └── rules-testing.spec.ts

The structure of fireabse.project1.json is usually like this:

{
  "firestore": {
    "rules": "projects/project1/firestore.rules",
    "indexes": "projects/project1/firestore.indexes.json"
  },
  "hosting": {
    "public": "dist/apps/frontendApp1",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "functions": [
    {
      "codebase": "functionsApp1",
      "source": "dist/apps/functionsApp1",
      "predeploy": "nx build functionsApp1",
      "runtime": "nodejs18",
      "ignore": ["*.local"]
    },
     {
      "codebase": "functionsApp2",
      "source": "dist/apps/functionsApp2",
      "predeploy": "nx build functionsApp2",
      "runtime": "nodejs18",
      "ignore": ["*.local"]
    }
  ],
  "emulators": {
  }
}

Note that this file lays in the root, and have different path for src and dist.

We usually un all firebase commands just directly passing firebase.json to it

firebase --config=firebase.project1.json

However this action has a slightly diffrent api than native firebase command and it doesn't allow to pass a path to the config file. Instead entrypoint should be a subpath with firebase.json in it

Change to the action that would solve that use case

I think it could be usefull if entryPoint property may accept path to the config, so the logic would detect if the file path passed than use this path, if directory is passed, so cd to this directory and look for default firebase.josn in it.

// pseudocode

let configFile;

if (isDir(entryPoint)) {
  changeDir(entryPoint);
  configFile = 'firebase.json'
} else {
   configFile = entryPoint
}

UPD: i've just tried to workaround the isuue by moving firebase.project1.json into projects/project1/firebase.json and changing paths in the file accordingly. That lead to a path like ../../dist/apps/frontendApp1 and fail with Error: ../../dist/apps/frontendApp1 is outside of project directory. So this improvement even more viable.