Skip to content

Commit 66e6ea6

Browse files
committed
[jb-gha] draft nightly script and update file structure
1 parent eb279a9 commit 66e6ea6

File tree

9 files changed

+410
-200
lines changed

9 files changed

+410
-200
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"image": "eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-d54058956db3274084249bdbc4f508ab111b8c51",
4+
"detail": {
5+
"pluginSinceBuild": "242.19533",
6+
"pluginUntilBuild":"242.*"
7+
}
8+
},
9+
{
10+
"image": "eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-d54058956db3274084249bdbc4f508ab111b8c51-latest",
11+
"detail": {
12+
"pluginSinceBuild": "242.19533",
13+
"pluginUntilBuild":"242.*"
14+
}
15+
}
16+
]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
// Update JetBrains latest editor images
6+
//
7+
// ```
8+
// bun run index-jb-nightly.ts --task=<id> --productCode=<code>
9+
// ```
10+
11+
import { $ } from "bun";
12+
import { pathToBackendPluginGradleLatest, readWorkspaceYaml } from "./lib/common";
13+
import { maybeCompatible, parseGradleProperties, parseGradlePropertiesFromTaskConfig } from "./lib/jb-helper/jb-helper";
14+
import { fetchProductReleases, ReleaseItem, releaseItemStr } from "./lib/jb-helper/jb-releases";
15+
import { getTaskFromArgs } from "./lib/jb-helper/jb-gradle-task-config";
16+
17+
$.nothrow(); // git likes to respond with non-zero codes, but it is alright for us
18+
19+
const task = getTaskFromArgs(true);
20+
21+
if (task.id !== 1) {
22+
throw new Error(`Only task 1 is supported, got ${task.id}`);
23+
}
24+
25+
console.log(`Updating nightly editor for ${task.productId} (${task.productType})`);
26+
27+
const { parsedObj: parsedWorkspaceYaml } = await readWorkspaceYaml();
28+
29+
const downloadUrl = parsedWorkspaceYaml.defaultArgs[task.productId + "DownloadUrl"] as string;
30+
31+
const latestGradle = parseGradleProperties(await Bun.file(pathToBackendPluginGradleLatest).text());
32+
33+
const platformVersionType = "build";
34+
35+
const releases = await fetchProductReleases({ productCode: task.productCode, productType: task.productType });
36+
37+
let maybeCompatibleRelease: ReleaseItem | undefined;
38+
for (const release of releases) {
39+
switch (platformVersionType) {
40+
case "build": {
41+
const ok = maybeCompatible(release, latestGradle);
42+
if (ok) {
43+
maybeCompatibleRelease = release;
44+
break;
45+
} else {
46+
console.error(`${releaseItemStr(release)} incompatible`);
47+
}
48+
}
49+
}
50+
if (maybeCompatibleRelease) {
51+
break;
52+
}
53+
}
54+
55+
if (maybeCompatibleRelease) {
56+
console.log(`${releaseItemStr(maybeCompatibleRelease)} maybe compatible`);
57+
}
58+
59+
const targetRelease = maybeCompatibleRelease || releases.find((e) => e.downloads.linux?.link === downloadUrl);
60+
61+
if (!targetRelease) {
62+
throw new Error(`No compatible release found`);
63+
}
64+
65+
console.log(`Preparing to use ${releaseItemStr(targetRelease)} as latest version for ${task.productId}`);
66+
67+
const targetConfig = parseGradlePropertiesFromTaskConfig(task, targetRelease);
68+
69+
// TODO: actually update nightly editor
70+
console.log(
71+
`Going to exec \`leeway build -Dversion=latest -DimageRepoBase=$imageRepoBase -DbuildNumber=${targetConfig.platformVersion} components/ide/jetbrains/image:${task.productId}-latest -DjbBackendVersion=${targetRelease.version}\``,
72+
);

components/ide/gha-update-image/index-jb-platform-update.ts

Lines changed: 28 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,113 +2,37 @@
22
// Licensed under the GNU Affero General Public License (AGPL).
33
// See License.AGPL.txt in the project root for license information.
44

5-
// Update JetBrains Platform Version
5+
// Update JetBrains Plugins (gateway / backend) Platform Version
6+
//
7+
// ```
8+
// bun run index-jb-platform-update.ts --task=<id>
9+
// ```
610

7-
import path from "path";
8-
import { parseArgs } from "util";
9-
import { pathToProjectRoot } from "./lib/common";
10-
import { jbUpdatePlatformVersion } from "./lib/jb-update-platform-version";
11+
import { getTaskFromArgs } from "./lib/jb-helper/jb-gradle-task-config";
12+
import {
13+
parseGradleProperties,
14+
renderPropertiesTemplate,
15+
parseGradlePropertiesFromTaskConfig,
16+
} from "./lib/jb-helper/jb-helper";
17+
import { fetchProductReleases } from "./lib/jb-helper/jb-releases";
1118

12-
const targetInfo = [
13-
{
14-
id: 1,
15-
taskName: "Latest Backend Plugin",
16-
productCode: "IIU",
17-
productType: "eap,rc,release",
18-
xmlName: "IntelliJ IDEA",
19-
xmlChannels: ["IC-IU-EAP-licensing-RELEASE", "IC-IU-EAP-licensing-EAP", "IC-IU-RELEASE-licensing-RELEASE"],
20-
useXml: true,
21-
gradlePropertiesPath: path.resolve(
22-
pathToProjectRoot,
23-
"components/ide/jetbrains/backend-plugin/gradle-latest.properties",
24-
),
25-
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
26-
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
27-
# for insight into build numbers and IntelliJ Platform versions.
28-
# revert pluginSinceBuild if it's unnecessary
29-
pluginSinceBuild={{pluginSinceBuild}}
30-
pluginUntilBuild={{pluginUntilBuild}}
31-
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
32-
# See https://jb.gg/intellij-platform-builds-list for available build versions.
33-
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
34-
# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
35-
platformVersion={{platformVersion}}
36-
`,
37-
},
38-
{
39-
id: 2,
40-
taskName: "Latest Frontend Plugin",
41-
productCode: "GW",
42-
productType: "eap,rc,release",
43-
xmlName: "Gateway",
44-
xmlChannels: ["GW-EAP-licensing-EAP", "GW-RELEASE-licensing-RELEASE", "GW-EAP-licensing-RELEASE"],
45-
useXml: true,
46-
useHumanreadableVersion: true,
47-
gradlePropertiesPath: path.resolve(
48-
pathToProjectRoot,
49-
"components/ide/jetbrains/gateway-plugin/gradle-latest.properties",
50-
),
51-
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
52-
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
53-
# for insight into build numbers and IntelliJ Platform versions.
54-
# revert pluginSinceBuild if it's unnecessary
55-
pluginSinceBuild={{pluginSinceBuild}}
56-
pluginUntilBuild={{pluginUntilBuild}}
57-
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
58-
# See https://jb.gg/intellij-platform-builds-list for available build versions.
59-
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
60-
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
61-
platformVersion={{platformVersion}}
62-
`,
63-
},
64-
{
65-
id: 3,
66-
taskName: "Stable Frontend Plugin",
67-
productCode: "GW",
68-
productType: "release",
69-
xmlName: "Gateway",
70-
xmlChannels: ["GW-RELEASE-licensing-RELEASE"],
71-
useXml: true,
72-
useHumanreadableVersion: true,
73-
gradlePropertiesPath: path.resolve(
74-
pathToProjectRoot,
75-
"components/ide/jetbrains/gateway-plugin/gradle-stable.properties",
76-
),
77-
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
78-
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
79-
# for insight into build numbers and IntelliJ Platform versions.
80-
# revert pluginSinceBuild if it's unnecessary
81-
pluginSinceBuild={{pluginSinceBuild}}
82-
pluginUntilBuild={{pluginUntilBuild}}
83-
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
84-
# See https://jb.gg/intellij-platform-builds-list for available build versions.
85-
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
86-
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/updates/updates.xml
87-
platformVersion={{platformVersion}}
88-
`,
89-
},
90-
];
19+
const task = getTaskFromArgs(false);
9120

92-
const { values } = parseArgs({
93-
args: Bun.argv,
94-
options: {
95-
task: {
96-
type: "string",
97-
},
98-
},
99-
strict: true,
100-
allowPositionals: true,
101-
});
21+
console.log("Updating", task.taskName);
10222

103-
const taskID = Number.parseInt(values.task ?? "NaN");
23+
const releases = await fetchProductReleases(task);
24+
const newProps = parseGradlePropertiesFromTaskConfig(task, releases[0]);
25+
console.log("New properties info:", newProps);
26+
const oldProps = parseGradleProperties(await Bun.file(task.gradlePropertiesPath).text());
27+
console.log("Old properties info:", oldProps);
10428

105-
const target = targetInfo.find((e) => e.id === taskID);
106-
if (!target) {
107-
throw new Error(
108-
`Invalid task id: ${taskID}, update cmd with \`--task="<name>"\`, available tasks: \n\t- ${targetInfo
109-
.map((e) => `(${e.id}) ${e.taskName}`)
110-
.join("\n\t- ")}`,
111-
);
29+
if (newProps.platformVersion === oldProps.platformVersion) {
30+
console.warn("PlatformVersion are the same, no need to update platform version");
31+
process.exit(0);
11232
}
113-
console.log("Updating", target.taskName);
114-
jbUpdatePlatformVersion(target);
33+
34+
const newGradleContent = renderPropertiesTemplate("gha-update-image/index-jb-platform-update.ts", task, newProps);
35+
36+
await Bun.write(task.gradlePropertiesPath, newGradleContent);
37+
38+
console.log("Updated platform version to:", newProps.platformVersion);

components/ide/gha-update-image/lib/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ export const pathToBackendPluginGradleStable = path.resolve(
5353
"components/ide/jetbrains/backend-plugin/gradle-stable.properties",
5454
);
5555

56+
// gradle-latest.properties
57+
export const pathToBackendPluginGradleLatest = path.resolve(
58+
pathToProjectRoot,
59+
"components/ide/jetbrains/backend-plugin/gradle-latest.properties",
60+
);
61+
62+
export const pathToBackendPluginDir = path.resolve(pathToProjectRoot, "components/ide/jetbrains/backend-plugin");
63+
5664
// ide-configmap.json
5765
export const pathToConfigmap = path.resolve(
5866
pathToProjectRoot,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import path from "path";
2+
import { AllProductCodes, AllProductIDs, TargetInfo } from "./jb-helper";
3+
import { pathToProjectRoot } from "../common";
4+
import { parseArgs } from "util";
5+
6+
export type TaskInfo = TargetInfo & { id: number; taskName: string };
7+
8+
export const latestBackendPluginGradleTarget: TaskInfo = {
9+
id: 1,
10+
taskName: "Latest Backend Plugin",
11+
productId: "intellij",
12+
productCode: "IIU",
13+
productType: "eap,rc,release",
14+
usePlatformVersionType: "build",
15+
gradlePropertiesPath: path.resolve(
16+
pathToProjectRoot,
17+
"components/ide/jetbrains/backend-plugin/gradle-latest.properties",
18+
),
19+
gradlePropertiesTemplate: `# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
20+
# for insight into build numbers and IntelliJ Platform versions.
21+
# revert pluginSinceBuild if it's unnecessary
22+
pluginSinceBuild={{pluginSinceBuild}}
23+
pluginUntilBuild={{pluginUntilBuild}}
24+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
25+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
26+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
27+
# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
28+
platformVersion={{platformVersion}}
29+
`,
30+
};
31+
32+
export const latestGatewayPluginGradleTarget: TaskInfo = {
33+
id: 2,
34+
taskName: "Latest Frontend Plugin",
35+
productId: "gateway",
36+
productCode: "GW",
37+
productType: "eap,rc,release",
38+
usePlatformVersionType: "version",
39+
gradlePropertiesPath: path.resolve(
40+
pathToProjectRoot,
41+
"components/ide/jetbrains/gateway-plugin/gradle-latest.properties",
42+
),
43+
gradlePropertiesTemplate: `# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
44+
# for insight into build numbers and IntelliJ Platform versions.
45+
# revert pluginSinceBuild if it's unnecessary
46+
pluginSinceBuild={{pluginSinceBuild}}
47+
pluginUntilBuild={{pluginUntilBuild}}
48+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
49+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
50+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
51+
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
52+
platformVersion={{platformVersion}}
53+
`,
54+
};
55+
56+
export const stableGatewayPluginGradleTarget: TaskInfo = {
57+
id: 3,
58+
taskName: "Stable Frontend Plugin",
59+
productId: "gateway",
60+
productCode: "GW",
61+
productType: "release",
62+
usePlatformVersionType: "version",
63+
gradlePropertiesPath: path.resolve(
64+
pathToProjectRoot,
65+
"components/ide/jetbrains/gateway-plugin/gradle-stable.properties",
66+
),
67+
gradlePropertiesTemplate: `# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
68+
# for insight into build numbers and IntelliJ Platform versions.
69+
# revert pluginSinceBuild if it's unnecessary
70+
pluginSinceBuild={{pluginSinceBuild}}
71+
pluginUntilBuild={{pluginUntilBuild}}
72+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
73+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
74+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
75+
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/updates/updates.xml
76+
platformVersion={{platformVersion}}
77+
`,
78+
};
79+
80+
export const AllTasks = [
81+
latestBackendPluginGradleTarget,
82+
latestGatewayPluginGradleTarget,
83+
stableGatewayPluginGradleTarget,
84+
];
85+
86+
export const getTaskFromArgs = (requireProductCode: boolean) => {
87+
const { values } = parseArgs({
88+
args: Bun.argv,
89+
options: {
90+
task: {
91+
type: "string",
92+
},
93+
productCode: {
94+
type: "string",
95+
},
96+
},
97+
allowPositionals: true,
98+
});
99+
100+
const taskID = Number.parseInt(values.task ?? "NaN");
101+
102+
const target = AllTasks.find((e) => e.id === taskID);
103+
if (!target) {
104+
throw new Error(
105+
`Invalid task id: ${taskID}, update cmd with \`--task="<id>"\`, available tasks: \n\t- ${AllTasks.map(
106+
(e) => `(${e.id}) ${e.taskName}`,
107+
).join("\n\t- ")}`,
108+
);
109+
}
110+
if (requireProductCode && !values.productCode) {
111+
throw new Error(`\`--productCode\` is required, available codes: ${AllProductCodes.join(", ")}`);
112+
}
113+
if (values.productCode) {
114+
const index = AllProductCodes.indexOf(values.productCode as any);
115+
if (index === -1) {
116+
throw new Error(
117+
`Invalid \`--productCode\`: ${values.productCode}, available codes: ${AllProductCodes.join(", ")}`,
118+
);
119+
}
120+
target.productCode = values.productCode as any;
121+
target.productId = AllProductIDs[index];
122+
}
123+
return target;
124+
};

0 commit comments

Comments
 (0)