Draft
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for locally built sources in App Hosting deployments by updating the release logic to distinguish between locally built and archive-based sources. It adds the LocallyBuiltSource interface and populates build configurations such as runCommand and environment variables. A review comment identified a potential runtime crash due to missing optional chaining when accessing buildConfig properties and suggested refactoring the code to reduce redundant lookups and improve maintainability in accordance with the repository's style guide.
Comment on lines
+46
to
+71
| const isLocallyBuilt = !!context.backendLocalBuilds[backendId]; | ||
| const source = isLocallyBuilt | ||
| ? { | ||
| locallyBuilt: { | ||
| userStorageUri: context.backendStorageUris[backendId], | ||
| rootDirectory: context.backendConfigs[backendId].rootDir, | ||
| runCommand: context.backendLocalBuilds[backendId]?.buildConfig.runCommand, | ||
| env: context.backendLocalBuilds[backendId]?.buildConfig.env, | ||
| }, | ||
| } | ||
| : { | ||
| archive: { | ||
| userStorageUri: context.backendStorageUris[backendId], | ||
| rootDirectory: context.backendConfigs[backendId].rootDir, | ||
| }, | ||
| }; | ||
|
|
||
| return orchestrateRollout({ | ||
| projectId, | ||
| backendId, | ||
| location: context.backendLocations[backendId], | ||
| buildInput: { | ||
| config: context.backendLocalBuilds[backendId]?.buildConfig, | ||
| source: { | ||
| archive: { | ||
| userStorageUri: context.backendStorageUris[backendId], | ||
| rootDirectory: context.backendConfigs[backendId].rootDir, | ||
| locallyBuiltSource: !!context.backendLocalBuilds[backendId], | ||
| }, | ||
| }, | ||
| source, | ||
| }, | ||
| }), | ||
| ); | ||
| }); |
Contributor
There was a problem hiding this comment.
The current implementation has a potential runtime crash and performs redundant lookups.
- Safety: If
context.backendLocalBuilds[backendId]exists but itsbuildConfigproperty is undefined, accessing.runCommandor.env(lines 52-53) will throw aTypeError. Optional chaining should be used forbuildConfigas well. - Efficiency: The code performs multiple lookups for
context.backendLocalBuilds[backendId],context.backendStorageUris[backendId], andcontext.backendConfigs[backendId]. - Maintainability: Consolidating these lookups into local variables improves readability and adheres to the repository's style guide regarding reducing complexity and handling null/undefined explicitly.
const localBuild = context.backendLocalBuilds[backendId];
const userStorageUri = context.backendStorageUris[backendId];
const rootDirectory = context.backendConfigs[backendId].rootDir;
const source = localBuild
? {
locallyBuilt: {
userStorageUri,
rootDirectory,
runCommand: localBuild.buildConfig?.runCommand,
env: localBuild.buildConfig?.env,
},
}
: {
archive: {
userStorageUri,
rootDirectory,
},
};
return orchestrateRollout({
projectId,
backendId,
location: context.backendLocations[backendId],
buildInput: {
config: localBuild?.buildConfig,
source,
},
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Updates the Local Build API calls to use the new "Effective Config" fields. Basically, we just want to call the correct API fields now.
Scenarios Tested