Skip to content

Commit

Permalink
[gha] fix JetBrains Platform Version update script (#20076)
Browse files Browse the repository at this point in the history
* Add bun script

* Update GHA

* fix gha
  • Loading branch information
mustard-mh authored Aug 1, 2024
1 parent a803391 commit 61d7b78
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 70 deletions.
71 changes: 28 additions & 43 deletions .github/workflows/jetbrains-update-plugin-platform-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ on:
description: ID of the plugin in lowercase and without spaces.
type: string
required: true
productCode:
description: JB Product Code
taskId:
description: ID of task to exec
type: string
required: true
productType:
description: JB Product Type
type: string
required: true
gradlePropertiesPath:
description: Path for the gradle.properties file of the plugin.
type: string
isBackendPlugin:
description: Action is execing for Gitpod JetBrains Backend Plugin or not
type: boolean
required: true
secrets:
slackWebhook:
Expand All @@ -33,45 +29,34 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Current Platform Version
id: current-version
- name: Install dependencies
run: |
CURRENT_VERSION=$(cat ${{ inputs.gradlePropertiesPath }} | grep platformVersion= | sed 's/platformVersion=//')
echo "Current platform version: $CURRENT_VERSION"
echo "::set-output name=result::$CURRENT_VERSION"
- name: Get Latest Platform Version
id: latest-version
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
chmod +x /usr/local/bin/oci-tool
cd ./components/ide/gha-update-image/
yarn
npm i -g bun
- name: Check for Update
id: change
run: |
URL="https://data.services.jetbrains.com/products/releases?code=${{ inputs.productCode }}&type=${{ inputs.productType }}&platform=linux"
echo "URL: $URL"
RELEASE=$(curl -s "$URL" |jq ".${{ inputs.productCode }}[0]")
MAJOR_VERSION=$(echo $RELEASE |jq -r ".majorVersion")
echo "MAJOR_VERSION: $MAJOR_VERSION"
BUILD=$(echo $RELEASE |jq -r ".build")
echo "BUILD: $BUILD"
MAJOR=$(cut -d. -f1 <<< $BUILD)
echo "MAJOR: $MAJOR"
MINOR=$(cut -d. -f2 <<< $BUILD)
echo "MINOR: $MINOR"
LATEST_VERSION="$MAJOR.$MINOR-EAP-CANDIDATE-SNAPSHOT"
echo "Latest platform version: $LATEST_VERSION"
cd ./components/ide/gha-update-image/
bun run index-jb-platform-update.ts --task=${{ inputs.taskId }}
echo "::set-output name=sinceBuild::$MAJOR.$MINOR"
echo "::set-output name=untilBuild::$MAJOR.*"
echo "::set-output name=majorVersion::$MAJOR_VERSION"
echo "::set-output name=result::$LATEST_VERSION"
- name: Update ${{ inputs.gradlePropertiesPath }}
if: ${{ steps.latest-version.outputs.result != steps.current-version.outputs.result }}
if [ -f /tmp/__gh_output.txt ]
then
cat /tmp/__gh_output.txt >> $GITHUB_OUTPUT
fi
- name: Detect file changes
id: changes
run: |
sed -i "s/pluginSinceBuild=.*/pluginSinceBuild=${{ steps.latest-version.outputs.sinceBuild }}/" ${{ inputs.gradlePropertiesPath }}
sed -i "s/pluginUntilBuild=.*/pluginUntilBuild=${{ steps.latest-version.outputs.untilBuild }}/" ${{ inputs.gradlePropertiesPath }}
sed -i "s/pluginVerifierIdeVersions=.*/pluginVerifierIdeVersions=${{ steps.latest-version.outputs.majorVersion }}/" ${{ inputs.gradlePropertiesPath }}
sed -i 's/platformVersion=${{ steps.current-version.outputs.result }}/platformVersion=${{ steps.latest-version.outputs.result }}/' ${{ inputs.gradlePropertiesPath }}
git diff
if [ $(git status --porcelain | wc -l) -gt 0 ]; then
echo "dirty=true" >> $GITHUB_OUTPUT
else
echo "dirty=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request for Gateway Plugin
id: create-gateway-pr
if: ${{ contains(inputs.pluginId, 'gateway-plugin') && steps.latest-version.outputs.result != steps.current-version.outputs.result }}
if: ${{ steps.changes.outputs.dirty && !inputs.isBackendPlugin }}
uses: peter-evans/create-pull-request@v6
with:
title: "[JetBrains] Update Platform Version from ${{ inputs.pluginName }}"
Expand Down Expand Up @@ -118,7 +103,7 @@ jobs:
author: Robo Quat <[email protected]>
- name: Create Pull Request for Backend Plugin
id: create-backend-pr
if: ${{ contains(inputs.pluginId, 'backend-plugin') && steps.latest-version.outputs.result != steps.current-version.outputs.result }}
if: ${{ steps.changes.outputs.dirty && inputs.isBackendPlugin }}
uses: peter-evans/create-pull-request@v6
with:
title: "[JetBrains] Update Platform Version from ${{ inputs.pluginName }}"
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/jetbrains-update-plugin-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ jobs:
with:
pluginName: JetBrains Backend Plugin (EAP)
pluginId: latest-backend-plugin
productCode: IIU
productType: eap,rc,release
gradlePropertiesPath: components/ide/jetbrains/backend-plugin/gradle-latest.properties
taskId: 1
isBackendPlugin: true
secrets:
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
Expand All @@ -21,9 +20,8 @@ jobs:
with:
pluginName: JetBrains Gateway Plugin (EAP)
pluginId: latest-gateway-plugin
productCode: GW
productType: eap,rc,release
gradlePropertiesPath: components/ide/jetbrains/gateway-plugin/gradle-latest.properties
taskId: 2
isBackendPlugin: false
secrets:
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
Expand All @@ -32,9 +30,8 @@ jobs:
with:
pluginName: JetBrains Gateway Plugin (Stable)
pluginId: stable-gateway-plugin
productCode: GW
productType: release
gradlePropertiesPath: components/ide/jetbrains/gateway-plugin/gradle-stable.properties
taskId: 3
isBackendPlugin: false
secrets:
slackWebhook: ${{ secrets.IDE_SLACK_WEBHOOK }}
roboquatRepoPat: ${{ secrets.ROBOQUAT_REPO_PAT }}
109 changes: 109 additions & 0 deletions components/ide/gha-update-image/index-jb-platform-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.

// Update JetBrains Platform Version

import path from "path";
import { parseArgs } from "util";
import { pathToProjectRoot } from "./lib/common";
import { jbUpdatePlatformVersion } from "./lib/jb-update-platform-version";

const targetInfo = [
{
id: 1,
taskName: "Latest Backend Plugin",
productCode: "IIU",
productType: "eap,rc,release",
xmlName: "IntelliJ IDEA",
xmlChannels: ["IC-IU-EAP-licensing-RELEASE", "IC-IU-EAP-licensing-EAP", "IC-IU-RELEASE-licensing-RELEASE"],
useXml: true,
gradlePropertiesPath: path.resolve(
pathToProjectRoot,
"components/ide/jetbrains/backend-plugin/gradle-latest.properties",
),
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild={{pluginSinceBuild}}
pluginUntilBuild={{pluginUntilBuild}}
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
# Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
platformVersion={{platformVersion}}
`,
},
{
id: 2,
taskName: "Latest Frontend Plugin",
productCode: "GW",
productType: "eap,rc,release",
xmlName: "Gateway",
xmlChannels: ["GW-EAP-licensing-EAP", "GW-RELEASE-licensing-RELEASE", "GW-EAP-licensing-RELEASE"],
useXml: true,
gradlePropertiesPath: path.resolve(
pathToProjectRoot,
"components/ide/jetbrains/gateway-plugin/gradle-latest.properties",
),
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild={{pluginSinceBuild}}
pluginUntilBuild={{pluginUntilBuild}}
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/intellij-repository/snapshots
platformVersion={{platformVersion}}
`,
},
{
id: 3,
taskName: "Stable Backend Plugin",
productCode: "GW",
productType: "release",
xmlName: "Gateway",
xmlChannels: ["GW-RELEASE-licensing-RELEASE"],
useXml: false,
gradlePropertiesPath: path.resolve(
pathToProjectRoot,
"components/ide/jetbrains/gateway-plugin/gradle-stable.properties",
),
gradlePropertiesTemplate: `# Code generated by gha-update-image/index-jb-platform-update.ts. DO NOT EDIT.
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild={{pluginSinceBuild}}
pluginUntilBuild={{pluginUntilBuild}}
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions={{pluginVerifierIdeVersions}}
# Version from "com.jetbrains.gateway" which can be found at https://www.jetbrains.com/updates/updates.xml
platformVersion={{platformVersion}}
`,
},
];

const { values } = parseArgs({
args: Bun.argv,
options: {
task: {
type: "string",
},
},
strict: true,
allowPositionals: true,
});

const taskID = Number.parseInt(values.task ?? "NaN");

const target = targetInfo.find((e) => e.id === taskID);
if (!target) {
throw new Error(
`Invalid task id: ${taskID}, update cmd with \`--task="<name>"\`, available tasks: \n\t- ${targetInfo
.map((e) => `(${e.id}) ${e.taskName}`)
.join("\n\t- ")}`,
);
}
console.log("Updating", target.taskName);
jbUpdatePlatformVersion(target);
50 changes: 32 additions & 18 deletions components/ide/gha-update-image/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import path from "path";
import yaml from "yaml";
import { z } from "zod";

const pathToProjectRoot = path.resolve(__dirname, "../../../../");
export const pathToProjectRoot = path.resolve(__dirname, "../../../../");

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

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

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

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

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

export const renderInstallerIDEConfigMap = async (version?: string) => {
const installationVersion = await getInstallerVersion(version);
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) => {
throw new Error("Failed to render gitpod.config.yaml: " + e);
})
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) => {
throw new Error(`Failed to render ide-configmap: ` + e);
});
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) => {
throw new Error("Failed to render gitpod.config.yaml: " + e);
},
);
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) => {
throw new Error(`Failed to render ide-configmap: ` + e);
});
const ideConfigmapJsonObj = JSON.parse(ideConfigMapStr);
const ideConfigmapJson = ideConfigmapJsonSchema.parse(ideConfigmapJsonObj);
return ideConfigmapJson;
}
};

export const getIDEVersionOfImage = async (img: string) => {
console.log("Fetching IDE version in image:", `oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`)
const version = await $`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`.text().catch((e) => {
throw new Error("Failed to fetch ide version in image: " + e);
}).then(str => str.replaceAll("\n", ""));
console.log(
"Fetching IDE version in image:",
`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`,
);
const version = await $`oci-tool fetch image ${img} | jq -r '.config.Labels["io.gitpod.ide.version"]'`
.text()
.catch((e) => {
throw new Error("Failed to fetch ide version in image: " + e);
})
.then((str) => str.replaceAll("\n", ""));
console.log("IDE version in image:", version);
return version;
}
};
Loading

0 comments on commit 61d7b78

Please sign in to comment.