Skip to content

Commit

Permalink
[server] When a user triggers a new prebuild, always force the creati…
Browse files Browse the repository at this point in the history
…on of a new prebuild
  • Loading branch information
jankeromnes committed Dec 5, 2022
1 parent d0ccc7f commit 7166de2
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,37 @@ export class PrebuildManager {
`Running prebuilds without a project is no longer supported. Please add '${cloneURL}' as a project in a Gitpod team.`,
);
}
const existingPB = await this.findNonFailedPrebuiltWorkspace({ span }, cloneURL, commitSHAIdentifier);

// If the existing prebuild is failed, it will be retriggered in the afterwards
const config = await this.fetchConfig({ span }, user, context);
if (existingPB) {
// If the existing prebuild is based on an outdated project config, we also want to retrigger it.
const existingPBWS = await this.workspaceDB.trace({ span }).findById(existingPB.buildWorkspaceId);
const existingConfig = existingPBWS?.config;
log.debug(
`startPrebuild | commits: ${commitSHAIdentifier}, existingPB: ${
existingPB.id
}, existingConfig: ${JSON.stringify(existingConfig)}, newConfig: ${JSON.stringify(config)}}`,
);
const filterPrebuildTasks = (tasks: TaskConfig[] = []) =>
tasks
.map((task) =>
Object.keys(task)
.filter((key) => ["before", "init", "prebuild"].includes(key))
// @ts-ignore
.reduce((obj, key) => ({ ...obj, [key]: task[key] }), {}),
)
.filter((task) => Object.keys(task).length > 0);
const isSameConfig =
JSON.stringify(filterPrebuildTasks(existingConfig?.tasks)) ===
JSON.stringify(filterPrebuildTasks(config?.tasks));
// If there is an existing prebuild that isn't failed and it's based on the current config, we return it here instead of triggering a new prebuild.
if (isSameConfig) {
return { prebuildId: existingPB.id, wsid: existingPB.buildWorkspaceId, done: true };

if (!forcePrebuild) {
// Check for an existing, successful prebuild, before triggering a new one.
const existingPB = await this.findNonFailedPrebuiltWorkspace({ span }, cloneURL, commitSHAIdentifier);
if (existingPB) {
// But if the existing prebuild is failed, or based on an outdated config, it will still be retriggered below.
const existingPBWS = await this.workspaceDB.trace({ span }).findById(existingPB.buildWorkspaceId);
const existingConfig = existingPBWS?.config;
log.debug(
`startPrebuild | commits: ${commitSHAIdentifier}, existingPB: ${
existingPB.id
}, existingConfig: ${JSON.stringify(existingConfig)}, newConfig: ${JSON.stringify(config)}}`,
);
const filterPrebuildTasks = (tasks: TaskConfig[] = []) =>
tasks
.map((task) =>
Object.keys(task)
.filter((key) => ["before", "init", "prebuild"].includes(key))
// @ts-ignore
.reduce((obj, key) => ({ ...obj, [key]: task[key] }), {}),
)
.filter((task) => Object.keys(task).length > 0);
const isSameConfig =
JSON.stringify(filterPrebuildTasks(existingConfig?.tasks)) ===
JSON.stringify(filterPrebuildTasks(config?.tasks));
// If there is an existing prebuild that isn't failed and it's based on the current config, we return it here instead of triggering a new prebuild.
if (isSameConfig) {
return { prebuildId: existingPB.id, wsid: existingPB.buildWorkspaceId, done: true };
}
}
}
if (project && context.ref && !project.settings?.keepOutdatedPrebuildsRunning) {
Expand Down

0 comments on commit 7166de2

Please sign in to comment.