feat: support Cloud Functions lifecycle hooks#10728
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for GCF Gen 2 lifecycle hooks (afterInstall and afterUpdate) in Firebase Functions deployments, including manifest parsing, backend validation, and execution of task queue hooks via Cloud Tasks. The review feedback highlights several critical issues: a type mismatch when calling getProjectNumber, a logic bug in codebase filtering that causes hooks to be skipped for the default codebase, validation failures during partial deployments, a potential runtime TypeError when parsing null lifecycle hooks, and the silent skipping of unsupported callable and http hooks during execution.
| throw new FirebaseError(`Target endpoint "${taskHook.function}" does not have a trigger URI.`); | ||
| } | ||
|
|
||
| const projectNumber = await getProjectNumber({ projectId: targetEndpoint.project }); |
There was a problem hiding this comment.
The getProjectNumber utility function expects a string representing the project ID (as seen in release/index.ts line 96), but here it is being passed an object { projectId: targetEndpoint.project }. This will cause a type mismatch and a runtime crash when trying to resolve the project number. We should pass the project ID string directly.
| const projectNumber = await getProjectNumber({ projectId: targetEndpoint.project }); | |
| const projectNumber = await getProjectNumber(targetEndpoint.project); |
| if (hook.callable) { | ||
| logger.info(`Skipping hook execution for unsupported actionType: callable`); | ||
| return false; | ||
| } | ||
|
|
||
| if (hook.http) { | ||
| logger.info(`Skipping hook execution for unsupported actionType: http`); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
While callable and http hooks are successfully parsed and validated, they are currently silently skipped during execution with an info log. This can lead to a confusing user experience where configured hooks silently fail to run. If these hook types are not supported yet, we should throw a validation error in validateLifecycleHooks to inform the user upfront, or implement their execution here.
1. Adds validation of each trigger 2. Ensures they are prefixed properly 3. Resolves SA for OIDC token 4. Outputs a Cloud COnsole log
f688cf8 to
f1e0350
Compare
Description
This PR introduces support for Cloud Functions (CF3) lifecycle hooks, allowing developers to run actions after deployment events. Specifically, it supports the
afterInstallandafterUpdatehooks.The implementation spans:
lifecycleHooksconfig from the generated functions build manifest/metadata. Support is added to definetask(Task Queue functions),callable(Callable functions), andhttp(HTTP functions or custom URLs) hooks. The execution of hook and callable functions is not yet implemented.afterInstallhook target) or a subsequent update (afterUpdatehook target).cloudtasks.ts) to enqueue tasks targeting hook functions. Resolves the service account to attach anoidcTokenso that invocations are securely authenticated.taskhook targeting a task queue function), and are GCF Gen 2 functions.Scenarios Tested