Skip to content

Commit

Permalink
Run lifecycle hooks for specific functions (#6023)
Browse files Browse the repository at this point in the history
* run lifecycle hooks for individual functions
  • Loading branch information
blidd-google authored Jun 28, 2023
1 parent 0bcee86 commit 55e8949
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Run lifecycle hooks for specific functions. (#6023)
- Increased extension instance create poll timeout to 1h to match backend (#5969).
- Refactored `ext:install` to use the latest extension metadata. (#5997)
- Added descriptive error when repo is private or not found during `ext:dev:upload`. (#6052)
Expand Down
40 changes: 34 additions & 6 deletions src/deploy/lifecycleHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,46 @@ function getReleventConfigs(target: string, options: Options) {

onlyTargets = onlyTargets
.filter((individualOnly) => {
return individualOnly.indexOf(`${target}:`) === 0;
return individualOnly.startsWith(`${target}:`);
})
.map((individualOnly) => {
return individualOnly.replace(`${target}:`, "");
});

return targetConfigs.filter((config: any) => {
if (target === "functions") {
return onlyTargets.includes(config.codebase);
if (target === "functions") {
let onlyConfigs = [];
const matched = onlyTargets.reduce(
(matched: object, target: string) => ({ ...matched, [target]: false }),
{}
);
for (const config of targetConfigs) {
if (!config.codebase) {
onlyConfigs.push(config);
} else {
const found = onlyTargets.find(
(individualOnly) => config.codebase === individualOnly.split(":")[0]
);
if (found) {
onlyConfigs.push(config);
matched[found] = true;
}
}
}
return !config.target || onlyTargets.includes(config.target);
});
// if there are --only targets that failed to match, we assume that the target is a
// individually specified function and so we run lifecycle hooks for all codebases.
// However, this also means that codebases or functions that don't exist will also run
// the all codebase lifecycle hooks. Until we can significantly refactor the way we
// identify which functions are in which codebase in the predeploy phase, we have to live
// with this default behavior.
if (!Object.values(matched).every((matched) => matched)) {
onlyConfigs = targetConfigs;
}
return onlyConfigs;
} else {
return targetConfigs.filter((config: any) => {
return !config.target || onlyTargets.includes(config.target);
});
}
}

export function lifecycleHooks(
Expand Down

0 comments on commit 55e8949

Please sign in to comment.