Skip to content

feat: Add Eventarc deployment for Dart Cloud Run functions - #10851

Open
Lyokone wants to merge 2 commits into
firebase:mainfrom
invertase:feat/dart-cloud-run-eventarc
Open

feat: Add Eventarc deployment for Dart Cloud Run functions#10851
Lyokone wants to merge 2 commits into
firebase:mainfrom
invertase:feat/dart-cloud-run-eventarc

Conversation

@Lyokone

@Lyokone Lyokone commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds production deployment support for Eventarc-backed Dart functions running directly on Cloud Run.

  • Discover and reconcile Firebase-managed Dart Cloud Run services alongside GCF functions
  • Create, update, replace, roll back, and delete Eventarc triggers
  • Support Firestore CloudEvents with protobuf payloads
  • Configure Eventarc receiver and Cloud Run invoker IAM roles
  • Preserve service identity and deployment metadata across updates
  • Validate unsupported event types and retry policies before deployment
  • Handle legacy Dart CloudEvent services and partial deployment failures

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for event-triggered Cloud Run functions (such as Dart functions) using Eventarc triggers. It introduces trigger lifecycle management (creation, updates, replacements, and deletion), IAM role provisioning for Eventarc delivery agents, API enablement checks, and deployment validations. Feedback on the changes suggests trimming trailing hyphens from the sliced prefix in eventarcTriggerIdForFunction to prevent consecutive hyphens, and refactoring the complex, nested try-catch blocks in upsertEventarcTrigger into helper functions to align with the repository's style guide on reducing nesting.

Comment on lines +546 to +547
const hash = crypto.createHash("sha256").update(fullId).digest("hex").slice(0, 8);
return `${fullId.slice(0, 54)}-${hash}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If fullId.slice(0, 54) ends with a hyphen, appending -${hash} will result in consecutive hyphens (e.g., --hash). While Eventarc trigger IDs can technically contain consecutive hyphens, it is cleaner and more robust to trim any trailing hyphens from the sliced prefix before appending the hash.

  const hash = crypto.createHash(\"sha256\").update(fullId).digest(\"hex\").slice(0, 8);\n  const prefix = fullId.slice(0, 54).replace(/-+$/, \"\");\n  return prefix + \"-\" + hash;

Comment on lines +953 to +1004
} else {
let replacementStarted = false;
try {
await this.executor.run(
async () => {
const deleteOp = await eventarc.deleteTrigger(trigger.name);
replacementStarted = true;
await poller.pollOperation<void>({
...eventarcPollerOptions,
pollerName: `replace-eventarc-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`,
operationResourceName: deleteOp.name,
});
const op = await eventarc.createTrigger(reconciledTrigger);
await poller.pollOperation<eventarc.Trigger>({
...eventarcPollerOptions,
pollerName: `create-eventarc-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`,
operationResourceName: op.name,
});
},
{ retryCodes: [] },
);
} catch (err) {
if (replacementStarted) {
try {
const failedReplacement = await eventarc.getTrigger(trigger.name);
if (failedReplacement) {
const cleanupOp = await eventarc.deleteTrigger(trigger.name);
await poller.pollOperation<void>({
...eventarcPollerOptions,
pollerName: `cleanup-eventarc-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`,
operationResourceName: cleanupOp.name,
});
}
const rollbackOp = await eventarc.createTrigger(eventarc.triggerForCreate(existing));
await poller.pollOperation<eventarc.Trigger>({
...eventarcPollerOptions,
pollerName: `rollback-eventarc-${endpoint.codebase}-${endpoint.region}-${endpoint.id}`,
operationResourceName: rollbackOp.name,
});
previousTriggerRestored = true;
} catch (rollbackError) {
const rollbackMessage =
rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
throw new FirebaseError(
`Failed to replace Eventarc trigger ${trigger.name} and failed to restore the previous trigger: ${rollbackMessage}`,
{ original: err as Error },
);
}
}
throw err;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The nested try-catch blocks and conditional branches within upsertEventarcTrigger make the code quite complex and hard to follow, violating the repository style guide rule to 'Reduce nesting as much as possible'. Consider extracting the trigger replacement and rollback logic into a separate helper function (e.g., replaceEventarcTrigger) to improve readability and maintainability.

References
  1. Reduce nesting as much as possible. Code should avoid unnecessarily deep nesting or long periods of nesting. Handle edge cases early and exit or fold them into the general case. Consider helper functions that can completely encapsulate branching. (link)

@Lyokone
Lyokone force-pushed the feat/dart-cloud-run-eventarc branch from c0d5bf2 to 37dff48 Compare July 27, 2026 15:15
@codecov-commenter

codecov-commenter commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.17757% with 36 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@e4f28d5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/deploy/functions/release/fabricator.ts 76.53% 10 Missing and 13 partials ⚠️
src/gcp/eventarc.ts 86.36% 0 Missing and 6 partials ⚠️
src/deploy/functions/checkIam.ts 85.71% 1 Missing and 3 partials ⚠️
src/gcp/runv2.ts 88.23% 1 Missing and 1 partial ⚠️
src/deploy/functions/validate.ts 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10851   +/-   ##
=======================================
  Coverage        ?   58.65%           
=======================================
  Files           ?      621           
  Lines           ?    40812           
  Branches        ?     8300           
=======================================
  Hits            ?    23939           
  Misses          ?    14866           
  Partials        ?     2007           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants