Skip to content

Commit f24a610

Browse files
Enable displaying JB warmup tasks in the Prebuilds UI (#19945)
* Enable displaying JB warmup tasks in the Prebuilds UI * a hacky comment * shorten jb warmup task id prefix * update converter tests * Capitalize product names * Fix IDE order * update golden test results
1 parent a4c4c57 commit f24a610

File tree

4 files changed

+123
-8
lines changed

4 files changed

+123
-8
lines changed

components/public-api/typescript-common/fixtures/toPrebuild_1.golden

+38-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,44 @@
2222
"startTime": "2023-11-17T10:42:00Z",
2323
"message": "",
2424
"logUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/5fba7d7c-e740-4339-b928-0e3c5975eb37",
25-
"taskLogs": [],
25+
"taskLogs": [
26+
{
27+
"taskId": "0",
28+
"taskLabel": "Task [1]",
29+
"taskJson": "{\"init\":\"true\",\"command\":\"npm install\"}",
30+
"logUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/5fba7d7c-e740-4339-b928-0e3c5975eb37/0"
31+
},
32+
{
33+
"taskId": "1",
34+
"taskLabel": "Task [2]",
35+
"taskJson": "{\"command\":\"npm run build\"}",
36+
"logUrl": ""
37+
},
38+
{
39+
"taskId": "2",
40+
"taskLabel": "Task [3]",
41+
"taskJson": "{\"command\":\"npm run start\"}",
42+
"logUrl": ""
43+
},
44+
{
45+
"taskId": "jb-warmup-clion-stable",
46+
"taskLabel": "JetBrains Clion warmup (stable)",
47+
"taskJson": "",
48+
"logUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/5fba7d7c-e740-4339-b928-0e3c5975eb37/3"
49+
},
50+
{
51+
"taskId": "jb-warmup-intellij-stable",
52+
"taskLabel": "JetBrains Intellij warmup (stable)",
53+
"taskJson": "",
54+
"logUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/5fba7d7c-e740-4339-b928-0e3c5975eb37/4"
55+
},
56+
{
57+
"taskId": "jb-warmup-intellij-latest",
58+
"taskLabel": "JetBrains Intellij warmup (latest)",
59+
"taskJson": "",
60+
"logUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/5fba7d7c-e740-4339-b928-0e3c5975eb37/5"
61+
}
62+
],
2663
"imageBuildLogUrl": "https://gitpod-test.preview.gitpod-dev.com/prebuild-logs/eb276a90-0970-49fb-947f-3cefe856efdc/image-build"
2764
},
2865
"configurationName": "parcel-demo"

components/public-api/typescript-common/fixtures/toPrebuild_1.json

+27-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,33 @@
1919
"changeUrl": "https://github.com/akosyakov/parcel-demo/tree/master"
2020
},
2121
"workspace": {
22-
"id": "eb276a90-0970-49fb-947f-3cefe856efdc"
22+
"id": "eb276a90-0970-49fb-947f-3cefe856efdc",
23+
"config": {
24+
"tasks": [
25+
{
26+
"init": "true",
27+
"command": "npm install"
28+
},
29+
{
30+
"command": "npm run build"
31+
},
32+
{
33+
"command": "npm run start"
34+
}
35+
],
36+
"jetbrains": {
37+
"intellij": {
38+
"prebuilds": {
39+
"version": "both"
40+
}
41+
},
42+
"clion": {
43+
"prebuilds": {
44+
"version": "stable"
45+
}
46+
}
47+
}
48+
}
2349
},
2450
"status": "building"
2551
}

components/public-api/typescript-common/src/public-api-converter.ts

+51-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
EnvVarWithValue,
2222
IDESettings,
2323
Identity as IdentityProtocol,
24+
JetBrainsProductConfig,
2425
NamedWorkspaceFeatureFlag,
2526
PrebuiltWorkspaceState,
2627
ProjectEnvVar,
@@ -35,8 +36,9 @@ import {
3536
WithEnvvarsContext,
3637
WithPrebuild,
3738
WorkspaceAutostartOption,
38-
WorkspaceContext, WorkspaceInfo,
39-
WorkspaceSession as WorkspaceSessionProtocol
39+
WorkspaceContext,
40+
WorkspaceInfo,
41+
WorkspaceSession as WorkspaceSessionProtocol,
4042
} from "@gitpod/gitpod-protocol/lib/protocol";
4143
import {
4244
OrgMemberInfo,
@@ -134,7 +136,8 @@ import {
134136
ParseContextURLResponse,
135137
PrebuildInitializer,
136138
SnapshotInitializer,
137-
UpdateWorkspaceRequest_UpdateTimeout, Workspace,
139+
UpdateWorkspaceRequest_UpdateTimeout,
140+
Workspace,
138141
WorkspaceClass,
139142
WorkspaceGitStatus,
140143
WorkspaceInitializer,
@@ -151,7 +154,7 @@ import {
151154
WorkspaceSpec_WorkspaceType,
152155
WorkspaceStatus,
153156
WorkspaceStatus_PrebuildResult,
154-
WorkspaceStatus_WorkspaceConditions
157+
WorkspaceStatus_WorkspaceConditions,
155158
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
156159
import { getPrebuildLogPath } from "./prebuild-utils";
157160
import { InvalidGitpodYMLError, RepositoryNotFoundError, UnauthorizedRepositoryAccessError } from "./public-api-errors";
@@ -1194,8 +1197,10 @@ export class PublicAPIConverter {
11941197

11951198
toPrebuildStatus(gitpodHost: string, prebuild: PrebuildWithStatus): PrebuildStatus {
11961199
const tasks: TaskLog[] = [];
1200+
let taskIndex = 0;
11971201
if (prebuild.workspace?.config?.tasks) {
11981202
for (let i = 0; i < prebuild.workspace.config.tasks.length; i++) {
1203+
taskIndex = i;
11991204
const task = prebuild.workspace.config.tasks[i];
12001205
tasks.push(
12011206
new TaskLog({
@@ -1211,6 +1216,48 @@ export class PublicAPIConverter {
12111216
);
12121217
}
12131218
}
1219+
1220+
const capitalize = (input: string) => {
1221+
return input.charAt(0).toUpperCase() + input.slice(1);
1222+
};
1223+
1224+
// This is a hack mimicking the supervisor behavior of adding dynamic IDE tasks https://github.com/gitpod-io/gitpod/blob/e7d79c355e2cd6ac34056ea52d7bdcda45975839/components/ide-service/pkg/server/server.go#L508-L540
1225+
if (prebuild.workspace.config.jetbrains) {
1226+
const jetbrainsIdes = Object.entries(prebuild.workspace.config.jetbrains).sort(([a], [b]) =>
1227+
a.localeCompare(b),
1228+
) as [string, JetBrainsProductConfig][];
1229+
for (const [ide, ideConfig] of jetbrainsIdes) {
1230+
if (!ideConfig.prebuilds) {
1231+
continue;
1232+
}
1233+
1234+
if (ideConfig.prebuilds.version !== "latest") {
1235+
tasks.push(
1236+
new TaskLog({
1237+
taskId: `jb-warmup-${ide}-stable`,
1238+
taskLabel: `JetBrains ${capitalize(ide)} warmup (stable)`,
1239+
logUrl: new URL(
1240+
getPrebuildLogPath(prebuild.info.id, `${++taskIndex}`),
1241+
gitpodHost,
1242+
).toString(),
1243+
}),
1244+
);
1245+
}
1246+
if (ideConfig.prebuilds.version !== "stable") {
1247+
tasks.push(
1248+
new TaskLog({
1249+
taskId: `jb-warmup-${ide}-latest`,
1250+
taskLabel: `JetBrains ${capitalize(ide)} warmup (latest)`,
1251+
logUrl: new URL(
1252+
getPrebuildLogPath(prebuild.info.id, `${++taskIndex}`),
1253+
gitpodHost,
1254+
).toString(),
1255+
}),
1256+
);
1257+
}
1258+
}
1259+
}
1260+
12141261
return new PrebuildStatus({
12151262
phase: new PrebuildPhase({
12161263
name: this.toPrebuildPhase(prebuild.status),

components/supervisor/pkg/supervisor/config.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"math"
1312
"net/http"
1413
"net/url"
1514
"os"
1615
"path/filepath"
16+
"slices"
17+
"strings"
1718
"time"
1819

1920
env "github.com/Netflix/go-env"
@@ -593,7 +594,7 @@ func loadDesktopIDEs(static *StaticConfig) ([]*IDEConfig, error) {
593594
uniqueDesktopIDEs[desktopIDE.GetUniqueKey()] = struct{}{}
594595
}
595596

596-
files, err := ioutil.ReadDir(static.DesktopIDERoot)
597+
files, err := os.ReadDir(static.DesktopIDERoot)
597598
if err != nil {
598599
return nil, err
599600
}
@@ -616,6 +617,10 @@ func loadDesktopIDEs(static *StaticConfig) ([]*IDEConfig, error) {
616617
}
617618
}
618619

620+
slices.SortFunc(desktopIDEs, func(a, b *IDEConfig) int {
621+
return strings.Compare(a.Name, b.Name)
622+
})
623+
619624
return desktopIDEs, nil
620625
}
621626

0 commit comments

Comments
 (0)