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

Strengthen typing of Runtimes+Langauges and their support timelines. #6866

Merged
merged 11 commits into from
Mar 27, 2024

Conversation

inlined
Copy link
Member

@inlined inlined commented Mar 10, 2024

  • Factors out Runtimes into a new file so that they can be imported into firebaseConfig.ts and have a single source of truth and prevent the error encountered in Functions Python version conflict 3.12 and 3.11 #6774 (comment)
  • Adds a formal concept of languages and the ability to discriminate runtimes per language
  • Makes all information about a runtime table driven so there can never be a runtime without all necessary metadata
  • Adds the ability to dynamically fetch the latest runtime for a language
  • Adds support timelines for all runtimes
  • Unifies runtime support checks across all runtimes/languages. There are now separate warnings for when deprecation is upcoming (90d), when a runtime is deprecated, and when a runtime is decommissioned.

- Factors out Runtimes into a new file so that they can be imported into
  firebaseConfig.ts and have a single source of truth and prevent the
  error encountered in #6774 (comment)
- Adds a formal concept of languages and the ability to discriminate
  runtimes per language
- Makes all information about a runtime table driven so there can never
  be a runtime without all necessary metadata
- Adds the ability to dynamically fetch the latest runtime for a
  language
- Adds support timelines for all runtimes
- Unifies runtime support checks across all runtimes/languages. There
  are now separate warnings for when deprecation is upcoming (90d), when
  a runtime is deprecated, and when a runtime is decommissioned.
@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 64.42308% with 37 lines in your changes are missing coverage. Please review.

Project coverage is 54.27%. Comparing base (27088cd) to head (bca4ff7).

Files Patch % Lines
src/deploy/functions/prepare.ts 11.11% 8 Missing ⚠️
src/deploy/functions/runtimes/python/index.ts 45.45% 6 Missing ⚠️
src/deploy/functions/runtimes/supported.ts 86.48% 2 Missing and 3 partials ⚠️
src/emulator/controller.ts 16.66% 5 Missing ⚠️
src/deploy/functions/runtimes/index.ts 20.00% 4 Missing ⚠️
src/gcp/cloudfunctions.ts 25.00% 1 Missing and 2 partials ⚠️
src/emulator/functionsEmulator.ts 0.00% 2 Missing ⚠️
src/gcp/cloudfunctionsv2.ts 33.33% 0 Missing and 2 partials ⚠️
src/deploy/functions/runtimes/node/index.ts 80.00% 1 Missing ⚠️
src/functional.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6866      +/-   ##
==========================================
+ Coverage   54.26%   54.27%   +0.01%     
==========================================
  Files         352      353       +1     
  Lines       24536    24573      +37     
  Branches     5083     5090       +7     
==========================================
+ Hits        13315    13338      +23     
- Misses      10007    10022      +15     
+ Partials     1214     1213       -1     

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

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.

MInor nits, but lgtm!

};
const firebaseJsonRuntime = codebaseConfig.runtime;
if (firebaseJsonRuntime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional - prefer this as a single if statement

Suggested change
if (firebaseJsonRuntime) {
if (firebaseJsonRuntime && !supported.isRuntime(firebaseJsonRuntime as string)) {


import { FirebaseError } from "../../../../error";
import * as runtimes from "../../runtimes";
import * as supported from "../supported";

// have to require this because no @types/cjson available
// eslint-disable-next-line @typescript-eslint/no-var-requires
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, unrelated to this PR: Looks like there are types now! https://www.npmjs.com/package/@types/cjson

const runtime = context.runtime ? context.runtime : LATEST_VERSION;
if (!runtimes.isValidRuntime(runtime)) {
throw new FirebaseError(`Runtime ${runtime} is not a valid Python runtime`);
const runtime = context.runtime ? context.runtime : supported.latest("python");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: context.runtime ?? supported.latest("python") is probably cleaner than a ternary

@@ -21,7 +21,7 @@ const BINDING = {
const SPEC = {
region: "us-west1",
project: projectNumber,
runtime: "nodejs14",
runtime: "nodejs14" as const,
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL that as const satisfies enums without having to import them - good to know!

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, "as const" will make a string literal type rather than just a string type.

@inlined inlined merged commit 1a3b885 into master Mar 27, 2024
35 checks passed
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