feat: add support for setting Cloud Run execution environment#195
feat: add support for setting Cloud Run execution environment#195Lyokone wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for configuring the Cloud Run execution environment (gen1 or gen2) from function options, updating the builder, manifest generation, documentation, and tests. One important piece of feedback is that the _extractExecutionEnvironment method in spec.dart should be updated to handle parameterized, expression, and reset constructors (e.g., ExecutionEnvironment.param()) to ensure consistency with how other options are parsed.
| Object? _extractExecutionEnvironment(Expression expression) { | ||
| final args = _extractCallArguments(expression); | ||
| final value = args?.firstOrNull; | ||
| final enumName = _extractEnumValueName(value); | ||
| if (enumName != null) { | ||
| return switch (enumName) { | ||
| 'gen1' => 'gen1', | ||
| 'gen2' => 'gen2', | ||
| _ => null, | ||
| }; | ||
| } | ||
| if (value is StringLiteral) { | ||
| return switch (value.stringValue) { | ||
| 'gen1' || 'gen2' => value.stringValue, | ||
| _ => null, | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| } |
There was a problem hiding this comment.
The _extractExecutionEnvironment method does not handle ExecutionEnvironment.param(), ExecutionEnvironment.expression(), or ExecutionEnvironment.reset() constructors. This means that if a user attempts to use a parameterized execution environment (e.g., ExecutionEnvironment.param(myParam)), the builder will fail to extract the parameter reference and return null.\n\nTo ensure consistency with other options like Memory and Cpu, we should check for these constructor names first and extract the parameter reference or CEL expression accordingly.
Object? _extractExecutionEnvironment(Expression expression) {\n if (expression is InstanceCreationExpression) {\n final constructorName = expression.constructorName.name?.name;\n if (constructorName == 'param') {\n return _extractParamReference(expression);\n }\n if (constructorName == 'expression') {\n return _extractCelExpression(\n expression.argumentList.arguments.firstOrNull,\n );\n }\n if (constructorName == 'reset') {\n return null;\n }\n }\n\n final args = _extractCallArguments(expression);\n final value = args?.firstOrNull;\n final enumName = _extractEnumValueName(value);\n if (enumName != null) {\n return switch (enumName) {\n 'gen1' => 'gen1',\n 'gen2' => 'gen2',\n _ => null,\n };\n }\n if (value is StringLiteral) {\n return switch (value.stringValue) {\n 'gen1' || 'gen2' => value.stringValue,\n _ => null,\n };\n }\n\n return null;\n }
closes #192