Skip to content

fix(functions): deploy functions whose runtime changed in firebase.json - #11599

Open
Ultranmus wants to merge 4 commits into
firebase:mainfrom
Ultranmus:fix/runtime-change-skipped
Open

Ultranmus wants to merge 4 commits into
firebase:mainfrom
Ultranmus:fix/runtime-change-skipped

Conversation

@Ultranmus

Copy link
Copy Markdown
Contributor

Description

Fixes #11597.

firebase deploy --only functions skips a function when its hash matches the deployed one. The hash (getEndpointHash in src/deploy/functions/cache/hash.ts) covers the source archive, env vars and secret versions, but not the runtime. runtime set in firebase.json is not part of the source archive, so changing only the runtime (for example nodejs22 to nodejs24, or python311 to python313) leaves the hash unchanged, and the function is reported as Skipped (No changes detected) while it keeps running on the old runtime.

This adds backend.runtimeChanged(want, have), which is true when both endpoints have a runtime and they differ. It is checked in:

  • calculateChangesets (release/planner.ts), so the function is updated instead of skipped
  • shouldUploadBeSkipped (deploy.ts), so the source is uploaded for the update

I kept the hash itself unchanged on purpose. Adding the runtime to the hash would change every function's hash, so every project would redeploy all of its functions once after upgrading the CLI. The deployed runtime is already read from buildConfig.runtime (gcfv2) and runtime (gcfv1). When it is missing, for example for a deprecated runtime, the existing skip behavior is kept, so this does not cause extra deploys.

Scenarios Tested

  • New tests in release/planner.spec.ts: a function with a matching hash but a different runtime is updated, not skipped; a function whose deployed runtime is unknown is still skipped.
  • New test in deploy.spec.ts: shouldUploadBeSkipped returns false when a runtime changed.
  • Without the change in planner.ts and deploy.ts, the two "runtime changed" tests fail; with it, all 58 tests in both files pass.
  • npm run mocha: 6143 passing. The 2 failures (should return expected tsc path, should output the date in the correct format) also fail on main on my machine; the Auth Emulator email link tests failed once and passed on rerun.
  • tsc --noEmit, eslint and prettier pass.

I have not run a real deploy against a project; the tests use the same runtime values that are read from firebase.json and from the deployed function.

Sample Commands

No command or flag changes. Reproduction from the issue: deploy with "runtime": "nodejs22" in firebase.json, change only the runtime to "nodejs24", and run firebase deploy --only functions again. The function is now updated instead of skipped.

@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 fixes an issue where firebase deploy incorrectly skips functions as unchanged when only their runtime configuration is modified in firebase.json. It introduces a runtimeChanged helper function to detect runtime mismatches and updates both the deployment skipping logic and the release planner to prevent skipping these functions. Unit tests have been added to verify this behavior. Feedback on the PR suggests updating the runtimeChanged function to use explicit strict null checks for undefined instead of implicit falsy checks with !!, in accordance with the repository's style guide.

Comment thread src/deploy/functions/backend.ts Resolved

@IzaakGough IzaakGough 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.

@Ultranmus Thanks for the contribution! This looks good generally, I've left a few comments.

Comment thread src/deploy/functions/release/planner.ts Resolved
Comment thread src/deploy/functions/deploy.ts Resolved
Comment thread src/deploy/functions/deploy.spec.ts Resolved
Comment thread src/deploy/functions/backend.ts Resolved
@codecov-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@03cd14e). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11599   +/-   ##
=======================================
  Coverage        ?   61.34%           
=======================================
  Files           ?      870           
  Lines           ?    51060           
  Branches        ?    10301           
=======================================
  Hits            ?    31322           
  Misses          ?    18598           
  Partials        ?     1140           

☔ 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.

Without a runtime in firebase.json, Python and Dart default to the latest
supported version, so comparing runtimes would redeploy (and re-upload)
every unchanged function after a CLI release moves that default.

- backend.isUnchanged() holds the skip condition (ACTIVE, matching hash,
  and the runtime when compareRuntime is set), used by both
  shouldUploadBeSkipped and calculateChangesets
- release and deploy set compareRuntime from firebase.json through
  projectConfig.hasConfiguredRuntime()
- tests for a defaulted runtime that changed, and for an unknown deployed
  runtime in shouldUploadBeSkipped
@Ultranmus

Copy link
Copy Markdown
Contributor Author

@IzaakGough thanks for the review and for trying it on a real project. I pushed 4648eae with all four changes:

  • Runtimes are only compared when firebase.json sets runtime for the codebase, so a CLI release that moves the default Python (or Dart) version no longer redeploys or re-uploads unchanged functions. An explicit runtime change still redeploys, which covers Changing only the runtime in firebase.json is skipped as an unchanged function (Node.js and Python) #11597.
  • backend.isUnchanged() is now shared by the planner and the upload check.
  • New tests: a defaulted runtime that changed (planner, createDeploymentPlan, upload), the unknown deployed runtime in shouldUploadBeSkipped, isUnchanged, and hasConfiguredRuntime. The release tests now pass a real firebase.json config instead of {}.

npm run mocha: 6153 passing; the only failure (should output the date in the correct format) also fails on main on my machine. tsc, eslint (no new warnings) and prettier pass. I have not run a real deploy, so your python313 → python314 check would be the best confirmation.

Covers the call site in deploy(): an unchanged function whose defaulted
runtime moved is not uploaded, and one whose runtime set in firebase.json
changed is.

This branch has not been deployed

No deployments
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.

Changing only the runtime in firebase.json is skipped as an unchanged function (Node.js and Python)

3 participants