Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only prompt for failurePolicies if they are new. #3164

Merged
merged 5 commits into from
Mar 3, 2021

Conversation

inlined
Copy link
Member

@inlined inlined commented Feb 23, 2021

Description

Fixes firebase/firebase-functions#798

We can now conditionally list functions earlier in the deploy pipeline
if there are any functions with a failure policy in the current
set of functions to deploy. Silence the prompt if all functions with
failure policies already had failure policies.

Also modifies prepare.ts to avoid redundantly calling listAllFunctions
later.

Scenarios Tested

  1. Write a function with a failure policy
  2. Deploy (expect a prompt)
  3. Deploy (do not expect a prompt)

Sample Commands

firebase deploy [--only functions]

Notes

Tests previously checked for throwing instead of rejecting, which worked if and only if the throw happened before yielding the thread. This broke all tests that ran into the new check for existing functions.

Fixes firebase/firebase-functions#798

We can now conditionally list functions earlier in the deploy pipeline
if there are any functions with a failure policy in the current
set of functions to deploy. Silence the prompt if all functions with
failure policies already had failure policies.

Also modifies prepare.ts to avoid redndantly calling listallfunctions
later.
@inlined inlined requested a review from joehan February 23, 2021 00:27
@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Feb 23, 2021
Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, but I'd prefer to not repeat API calls unnecessarily


// N.B. Because context is an any, we need to store it in a temporary. This
// lets us do a 'for of' loop later with typeinfo.
const existingFunctions = await gcp.cloudfunctions.listAllFunctions(context.projectId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already make this call once during the deployment process, at the start of 'deploy.ts' - WDYT about reordering things such that we only need to do this once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guarded both cases with existing || await listAllFunctions. In reality, Context should have context.allFunctions() which is a caching implementation and easily mocked. ¯_(ツ)_/¯

1. Cache the lookups to listAllFunctions
2. When passing a mock to listAllFunctions stub, use the API location
   for failurePolicy: {}
3. Add release notes
@inlined inlined merged commit 9895790 into master Mar 3, 2021
@bkendall bkendall deleted the inlined.failure-policy-noforce branch August 4, 2021 19:26
devpeerapong pushed a commit to devpeerapong/firebase-tools that referenced this pull request Dec 14, 2021
* Only prompt for failurePolicies if they are new.

Fixes firebase/firebase-functions#798

We can now conditionally list functions earlier in the deploy pipeline
if there are any functions with a failure policy in the current
set of functions to deploy. Silence the prompt if all functions with
failure policies already had failure policies.

Also modifies prepare.ts to avoid redundantly calling listallfunctions
later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deploying functions with failurePolicy should not always require --force
2 participants