Skip to content

Commit 61d7b78

Browse files
authored
[gha] fix JetBrains Platform Version update script (#20076)
* Add bun script * Update GHA * fix gha
1 parent a803391 commit 61d7b78

File tree

5 files changed

+267
-70
lines changed

5 files changed

+267
-70
lines changed

.github/workflows/jetbrains-update-plugin-platform-template.yml

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ on:
99
description: ID of the plugin in lowercase and without spaces.
1010
type: string
1111
required: true
12-
productCode:
13-
description: JB Product Code
12+
taskId:
13+
description: ID of task to exec
1414
type: string
1515
required: true
16-
productType:
17-
description: JB Product Type
18-
type: string
19-
required: true
20-
gradlePropertiesPath:
21-
description: Path for the gradle.properties file of the plugin.
22-
type: string
16+
isBackendPlugin:
17+
description: Action is execing for Gitpod JetBrains Backend Plugin or not
18+
type: boolean
2319
required: true
2420
secrets:
2521
slackWebhook:
@@ -33,45 +29,34 @@ jobs:
3329
steps:
3430
- name: Checkout Repository
3531
uses: actions/checkout@v4
36-
- name: Get Current Platform Version
37-
id: current-version
32+
- name: Install dependencies
3833
run: |
39-
CURRENT_VERSION=$(cat ${{ inputs.gradlePropertiesPath }} | grep platformVersion= | sed 's/platformVersion=//')
40-
echo "Current platform version: $CURRENT_VERSION"
41-
echo "::set-output name=result::$CURRENT_VERSION"
42-
- name: Get Latest Platform Version
43-
id: latest-version
34+
curl -fsSL https://github.com/csweichel/oci-tool/releases/download/v0.2.1/oci-tool_0.2.1_linux_amd64.tar.gz | tar xz -C /usr/local/bin
35+
chmod +x /usr/local/bin/oci-tool
36+
cd ./components/ide/gha-update-image/
37+
yarn
38+
npm i -g bun
39+
- name: Check for Update
40+
id: change
4441
run: |
45-
URL="https://data.services.jetbrains.com/products/releases?code=${{ inputs.productCode }}&type=${{ inputs.productType }}&platform=linux"
46-
echo "URL: $URL"
47-
RELEASE=$(curl -s "$URL" |jq ".${{ inputs.productCode }}[0]")
48-
MAJOR_VERSION=$(echo $RELEASE |jq -r ".majorVersion")
49-
echo "MAJOR_VERSION: $MAJOR_VERSION"
50-
51-
BUILD=$(echo $RELEASE |jq -r ".build")
52-
echo "BUILD: $BUILD"
53-
MAJOR=$(cut -d. -f1 <<< $BUILD)
54-
echo "MAJOR: $MAJOR"
55-
MINOR=$(cut -d. -f2 <<< $BUILD)
56-
echo "MINOR: $MINOR"
57-
LATEST_VERSION="$MAJOR.$MINOR-EAP-CANDIDATE-SNAPSHOT"
58-
echo "Latest platform version: $LATEST_VERSION"
42+
cd ./components/ide/gha-update-image/
43+
bun run index-jb-platform-update.ts --task=${{ inputs.taskId }}
5944
60-
echo "::set-output name=sinceBuild::$MAJOR.$MINOR"
61-
echo "::set-output name=untilBuild::$MAJOR.*"
62-
echo "::set-output name=majorVersion::$MAJOR_VERSION"
63-
echo "::set-output name=result::$LATEST_VERSION"
64-
- name: Update ${{ inputs.gradlePropertiesPath }}
65-
if: ${{ steps.latest-version.outputs.result != steps.current-version.outputs.result }}
45+
if [ -f /tmp/__gh_output.txt ]
46+
then
47+
cat /tmp/__gh_output.txt >> $GITHUB_OUTPUT
48+
fi
49+
- name: Detect file changes
50+
id: changes
6651
run: |
67-
sed -i "s/pluginSinceBuild=.*/pluginSinceBuild=${{ steps.latest-version.outputs.sinceBuild }}/" ${{ inputs.gradlePropertiesPath }}
68-
sed -i "s/pluginUntilBuild=.*/pluginUntilBuild=${{ steps.latest-version.outputs.untilBuild }}/" ${{ inputs.gradlePropertiesPath }}
69-
sed -i "s/pluginVerifierIdeVersions=.*/pluginVerifierIdeVersions=${{ steps.latest-version.outputs.majorVersion }}/" ${{ inputs.gradlePropertiesPath }}
70-
sed -i 's/platformVersion=${{ steps.current-version.outputs.result }}/platformVersion=${{ steps.latest-version.outputs.result }}/' ${{ inputs.gradlePropertiesPath }}
71-
git diff
52+
if [ $(git status --porcelain | wc -l) -gt 0 ]; then
53+
echo "dirty=true" >> $GITHUB_OUTPUT
54+
else
55+
echo "dirty=false" >> $GITHUB_OUTPUT
56+
fi
7257
- name: Create Pull Request for Gateway Plugin
7358
id: create-gateway-pr
74-
if: ${{ contains(inputs.pluginId, 'gateway-plugin') && steps.latest-version.outputs.result != steps.current-version.outputs.result }}
59+
if: ${{ steps.changes.outputs.dirty && !inputs.isBackendPlugin }}
7560
uses: peter-evans/create-pull-request@v6
7661
with:
7762
title: "[JetBrains] Update Platform Version from ${{ inputs.pluginName }}"
@@ -118,7 +103,7 @@ jobs:
118103
author: Robo Quat <[email protected]>
119104
- name: Create Pull Request for Backend Plugin
120105
id: create-backend-pr
121-
if: ${{ contains(inputs.pluginId, 'backend-plugin') && steps.latest-version.outputs.result != steps.current-version.outputs.result }}
106+
if: ${{ steps.changes.outputs.dirty && inputs.isBackendPlugin }}
122107
uses: peter-evans/create-pull-request@v6
123108
with:
124109
title: "[JetBrains] Update Platform Version from ${{ inputs.pluginName }}"

.github/workflows/jetbrains-update-plugin-platform.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ jobs:
1010
with:
1111
pluginName: JetBrains Backend Plugin (EAP)
1212
pluginId: latest-backend-plugin
13-
productCode: IIU
14-
productType: eap,rc,release
15-
gradlePropertiesPath: components/ide/jetbrains/backend-plugin/gradle-latest.properties
13+
taskId: 1
14+
isBackendPlugin: true
1615
secrets:
1716
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
1817
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
@@ -21,9 +20,8 @@ jobs:
2120
with:
2221
pluginName: JetBrains Gateway Plugin (EAP)
2322
pluginId: latest-gateway-plugin
24-
productCode: GW
25-
productType: eap,rc,release
26-
gradlePropertiesPath: components/ide/jetbrains/gateway-plugin/gradle-latest.properties
23+
taskId: 2
24+
isBackendPlugin: false
2725
secrets:
2826
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
2927
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
@@ -32,9 +30,8 @@ jobs:
3230
with:
3331
pluginName: JetBrains Gateway Plugin (Stable)
3432
pluginId: stable-gateway-plugin
35-
productCode: GW
36-
productType: release
37-
gradlePropertiesPath: components/ide/jetbrains/gateway-plugin/gradle-stable.properties
33+
taskId: 3
34+
isBackendPlugin: false
3835
secrets:
3936
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
4037
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 Platform Version
6+
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+
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+
pluginSinceBuild={{pluginSinceBuild}}
29+
pluginUntilBuild={{pluginUntilBuild}}
30+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
31+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
32+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
33+
# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
34+
platformVersion={{platformVersion}}
35+
`,
36+
},
37+
{
38+
id: 2,
39+
taskName: "Latest Frontend Plugin",
40+
productCode: "GW",
41+
productType: "eap,rc,release",
42+
xmlName: "Gateway",
43+
xmlChannels: ["GW-EAP-licensing-EAP", "GW-RELEASE-licensing-RELEASE", "GW-EAP-licensing-RELEASE"],
44+
useXml: true,
45+
gradlePropertiesPath: path.resolve(
46+
pathToProjectRoot,
47+
"components/ide/jetbrains/gateway-plugin/gradle-latest.properties",
48+
),
49+
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
50+
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
51+
# for insight into build numbers and IntelliJ Platform versions.
52+
pluginSinceBuild={{pluginSinceBuild}}
53+
pluginUntilBuild={{pluginUntilBuild}}
54+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
55+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
56+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
57+
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
58+
platformVersion={{platformVersion}}
59+
`,
60+
},
61+
{
62+
id: 3,
63+
taskName: "Stable Backend Plugin",
64+
productCode: "GW",
65+
productType: "release",
66+
xmlName: "Gateway",
67+
xmlChannels: ["GW-RELEASE-licensing-RELEASE"],
68+
useXml: false,
69+
gradlePropertiesPath: path.resolve(
70+
pathToProjectRoot,
71+
"components/ide/jetbrains/gateway-plugin/gradle-stable.properties",
72+
),
73+
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
74+
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
75+
# for insight into build numbers and IntelliJ Platform versions.
76+
pluginSinceBuild={{pluginSinceBuild}}
77+
pluginUntilBuild={{pluginUntilBuild}}
78+
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
79+
# See https://jb.gg/intellij-platform-builds-list for available build versions.
80+
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
81+
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/updates/updates.xml
82+
platformVersion={{platformVersion}}
83+
`,
84+
},
85+
];
86+
87+
const { values } = parseArgs({
88+
args: Bun.argv,
89+
options: {
90+
task: {
91+
type: "string",
92+
},
93+
},
94+
strict: true,
95+
allowPositionals: true,
96+
});
97+
98+
const taskID = Number.parseInt(values.task ?? "NaN");
99+
100+
const target = targetInfo.find((e) => e.id === taskID);
101+
if (!target) {
102+
throw new Error(
103+
`Invalid task id: ${taskID}, update cmd with \`--task="<name>"\`, available tasks: \n\t- ${targetInfo
104+
.map((e) => `(${e.id}) ${e.taskName}`)
105+
.join("\n\t- ")}`,
106+
);
107+
}
108+
console.log("Updating", target.taskName);
109+
jbUpdatePlatformVersion(target);

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import path from "path";
77
import yaml from "yaml";
88
import { z } from "zod";
99

10-
const pathToProjectRoot = path.resolve(__dirname, "../../../../");
10+
export const pathToProjectRoot = path.resolve(__dirname, "../../../../");
1111

1212
const pathToOutput = path.resolve("/tmp/__gh_output.txt");
1313

1414
export const appendGitHubOutput = async (kv: string) => {
1515
console.log("Appending to GitHub output:", kv);
1616
return await $`echo ${kv} >> ${pathToOutput}`;
17-
}
17+
};
1818

1919
// WORKSPACE.yaml
2020
export const pathToWorkspaceYaml = path.resolve(pathToProjectRoot, "WORKSPACE.yaml");
@@ -119,15 +119,18 @@ const getInstallerVersion = async (version: string | undefined) => {
119119
throw new Error("Failed to parse installer version from git tag: " + e);
120120
});
121121
return installationVersion.replaceAll("\n", "");
122-
}
122+
};
123123

124124
// installer versions
125125
export const getLatestInstallerVersions = async (version?: string) => {
126126
const installationVersion = await getInstallerVersion(version);
127127
console.log("Fetching installer versions for", installationVersion);
128-
const versionData = await $`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${installationVersion} cat /versions.yaml`.text().catch((e) => {
129-
throw new Error("Failed to get installer versions: " + e);
130-
});
128+
const versionData =
129+
await $`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${installationVersion} cat /versions.yaml`
130+
.text()
131+
.catch((e) => {
132+
throw new Error("Failed to get installer versions: " + e);
133+
});
131134

132135
const versionObj = z.object({ version: z.string() });
133136
return z
@@ -172,22 +175,33 @@ export const getLatestInstallerVersions = async (version?: string) => {
172175

173176
export const renderInstallerIDEConfigMap = async (version?: string) => {
174177
const installationVersion = await getInstallerVersion(version);
175-
await $`docker run --rm -v /tmp:/tmp eu.gcr.io/gitpod-core-dev/build/installer:${installationVersion} config init --overwrite --log-level=error -c /tmp/gitpod.config.yaml`.catch((e) => {
176-
throw new Error("Failed to render gitpod.config.yaml: " + e);
177-
})
178-
const ideConfigMapStr = await $`cat /tmp/gitpod.config.yaml | docker run -i --rm eu.gcr.io/gitpod-core-dev/build/installer:${installationVersion} ide-configmap -c -`.text().catch((e) => {
179-
throw new Error(`Failed to render ide-configmap: ` + e);
180-
});
178+
await $`docker run --rm -v /tmp:/tmp eu.gcr.io/gitpod-core-dev/build/installer:${installationVersion} config init --overwrite --log-level=error -c /tmp/gitpod.config.yaml`.catch(
179+
(e) => {
180+
throw new Error("Failed to render gitpod.config.yaml: " + e);
181+
},
182+
);
183+
const ideConfigMapStr =
184+
await $`cat /tmp/gitpod.config.yaml | docker run -i --rm eu.gcr.io/gitpod-core-dev/build/installer:${installationVersion} ide-configmap -c -`
185+
.text()
186+
.catch((e) => {
187+
throw new Error(`Failed to render ide-configmap: ` + e);
188+
});
181189
const ideConfigmapJsonObj = JSON.parse(ideConfigMapStr);
182190
const ideConfigmapJson = ideConfigmapJsonSchema.parse(ideConfigmapJsonObj);
183191
return ideConfigmapJson;
184-
}
192+
};
185193

186194
export const getIDEVersionOfImage = async (img: string) => {
187-
console.log("Fetching IDE version in image:", `oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`)
188-
const version = await $`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`.text().catch((e) => {
189-
throw new Error("Failed to fetch ide version in image: " + e);
190-
}).then(str => str.replaceAll("\n", ""));
195+
console.log(
196+
"Fetching IDE version in image:",
197+
`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`,
198+
);
199+
const version = await $`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`
200+
.text()
201+
.catch((e) => {
202+
throw new Error("Failed to fetch ide version in image: " + e);
203+
})
204+
.then((str) => str.replaceAll("\n", ""));
191205
console.log("IDE version in image:", version);
192206
return version;
193-
}
207+
};

0 commit comments

Comments
 (0)