w9jds / firebase-action

GitHub Action for interacting with Firebase
MIT License
927 stars 200 forks source link

feat: export runtime config > .runtimeconfig.json #114

Open weilinzung opened 3 years ago

weilinzung commented 3 years ago

Fixes #29

weilinzung commented 3 years ago

@w9jds

weilinzung commented 3 years ago

Need to confirm something first. to draft for now.

w9jds commented 3 years ago

Once you have confirmed yourself let me know, but his one looks fine.

weilinzung commented 3 years ago

@w9jds It is clearly no need with runtimeconfig.json when deploy from local with firebase deploy --only functions. Not sure why it keeps failing. Log here: https://github.com/w9jds/firebase-action/issues/86#issuecomment-949732011

Can we confirm the firebase-tools version that is used for this action?

w9jds commented 3 years ago

With the PR I just merged it is now v9.21.0

weilinzung commented 3 years ago

@w9jds thanks. for the log I provided, do you have any insights? From my local testing with firebase-tools, everything is working fine without runtimeconfig.json.

w9jds commented 3 years ago

Not sure, but another PR that was just opened is going to allow you to set them as an environment variable, but it looks like since the code immediately does env.client_id it doesn't check to make sure that env is set which makes it sound like on live the config isn't set up.

weilinzung commented 3 years ago

Hmmm. Also for the PR you mentioned that also has an other issue => https://github.com/w9jds/firebase-action/issues/86#issuecomment-949601323

It doesn't make sense to save as secrets because the config variables could be updated/unset from local and doing config:set with this action would overwrite the variable again.

w9jds commented 3 years ago

That should also work for paths, the firebase config cli command supports a path to a json file too.

weilinzung commented 3 years ago

did a test with the latest version(https://github.com/w9jds/firebase-action/commit/6e669f5311c3e35a0e0fccf706ded07793cc25ad) with the latest firebase tool and still failed.

w9jds commented 3 years ago

Probably because you can't just export a file, and expect it to be accessible in other steps of a pipeline, that is why you have to use artifacts. From the change you just export to a file, you would need to somehow include it in an artifact for the next step to pull. Is accessing it in other steps your issue?

weilinzung commented 3 years ago

firebase deploy should already take care of the build. I can tell the build have no issue, just about the deploy part. Does matter we have to upload/download the artifact?

    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint "src/**/*"

Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'client_id' of undefined
w9jds commented 3 years ago

Yeah, but all you're doing is exporting config into a local file. Also, this change doesn't really address anything except for maybe your specific bug, which looks like a compile issue. Looking at this better, you are using typescript this is a TypeError which means compile error not firebase-tools related.

weilinzung commented 3 years ago

The thing is no issue at all when deploy from local.

People have same the issue here as well: https://stackoverflow.com/questions/69395116/firebase-functions-deployment-undefined-environment-datas-with-github-actions

weilinzung commented 3 years ago

Close this PR for now. 100% we don;t need runtimeconfig.json for deploy. it is for sure not certain what is going on.

weilinzung commented 3 years ago

@w9jds figured it out https://github.com/w9jds/firebase-action/issues/86#issuecomment-949958246

weilinzung commented 2 years ago

@w9jds reopen this, it is useful when running emulators has runtimeconfig.

An example that need to get variables with functions.config(): https://firebase.google.com/docs/functions/config-env#access_environment_configuration_in_a_function

My test log:

Storing GCP_SA_KEY in /opt/gcp_key.json
Exporting GOOGLE_APPLICATION_CREDENTIALS=/opt/gcp_key.json
i  emulators: Starting emulators: functions, hosting, pubsub
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, storage
✔  functions: Using node@14 from host.
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /opt/gcp_key.json. Non-emulated services will access production using these credentials. Be careful!
⚠  It appears you are running in a CI environment. You can avoid downloading the Pub/Sub Emulator repeatedly by caching the /github/home/.cache/firebase/emulators directory.
i  pubsub: downloading pubsub-emulator-0.1.0.zip...
i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i  hosting[staging]: Serving hosting files from: dist/frontend
✔  hosting[staging]: Local server: http://localhost:5000
i  functions: Watching "/github/workspace/projects" for Cloud Functions...
⚠  It looks like you're trying to access functions.config().name but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator
⚠  TypeError: Cannot read property 'client_id' of undefined
    at Object.<anonymous> (/github/workspace/projects/backend/lib/src/conversion-handler/utils.js:27:41)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/github/workspace/projects/backend/lib/src/conversion-handler/conversion-adjuster.js:8:17)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
⚠  We were unable to load your functions code. (see above)
   - It appears your code is written in Typescript, which must be compiled before emulation.
   - You may be able to run "npm run build" in your functions directory to resolve this.
weilinzung commented 2 years ago

@w9jds any feedbacks?

w9jds commented 2 years ago

Have you tested this build with that particular test case to see if it actually resolves the issue?

weilinzung commented 2 years ago

@w9jds would you mind to help, where/how can I build this PR for testing from this action?

What I test so far is adding the runtime config to my branch and testing with this action, everything is good as long as the runtimeconfig is there.

w9jds commented 2 years ago

Ideally the best way to test is to create a branch fork or branch and then point your job to use the new version (not the docker image) then run the job you are trying to fix. If it does what you expected then the build is good to go. I don't have something that I could use reliably for what you are trying to solve.

aliechti commented 2 years ago

Is there still something going on here?

I need this feature to deploy the functions after merge. Otherwise it fails with:

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'app_id' of undefined
w9jds commented 2 years ago

If you want to test this @weilinzung I have setup a new deployment system for this action. What we can do it is resolve conflicts, then get this merged into master. The master image will deployed to docker hub and you can point to the master version and we should be able to run this in an actual action flow to make sure just exporting the file to local will be enough to share it between steps.