gitpod/components/ide/gha-update-image/check-code-build.ts
Huiwen 9e090391aa
Improve ide images updating GHA (#19919)
* Revert "[VS Code Browser] Update stable code to `1.90.1` (#19915)"

This reverts commit a96919f6ae7311f3eac512e067300ae05710c341.

* improve gha

* address feedback

* Address feedback
2024-06-18 18:54:14 +02:00

61 lines
2.1 KiB
TypeScript

// 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.
import { $ } from "bun";
import { parseArgs } from "util";
import { appendGitHubOutput, pathToWorkspaceYaml, readWorkspaceYaml } from "./lib/common";
$.nothrow();
const workspaceYamlInfo = await readWorkspaceYaml();
const rawWorkspaceYaml = workspaceYamlInfo.rawText;
const workspaceYaml = workspaceYamlInfo.parsedObj;
const { values } = parseArgs({
args: Bun.argv,
options: {
branch: {
type: "string",
},
},
strict: true,
allowPositionals: true,
});
const inputs = {
branch: values.branch,
};
// example: bun run check-code-build.ts --branch gp-code/release/1.89
const main = async () => {
if (!inputs.branch || !inputs.branch.startsWith("gp-code/release/")) {
throw new Error(`invalid branch ${inputs.branch}, expected something like \`gp-code/release/1.90\``);
}
const commit =
await $`curl -H 'Accept: application/vnd.github.VERSION.sha' https://api.github.com/repos/gitpod-io/openvscode-server/commits/${inputs.branch}`.text();
const version = JSON.parse(
await $`curl https://raw.githubusercontent.com/gitpod-io/openvscode-server/${commit}/package.json`.text(),
).version;
console.log("fetch gitpod-io/openvscode-server with " + inputs.branch, { commit, version });
if (workspaceYaml.defaultArgs.codeVersion === version) {
console.error("code version is the same, no need to update");
return;
}
console.log(
`found different version ${version} (than ${workspaceYaml.defaultArgs.codeVersion}) with commit:${commit} (than ${workspaceYaml.defaultArgs.codeCommit})`,
);
const newYaml = rawWorkspaceYaml
.replace(workspaceYaml.defaultArgs.codeCommit, commit)
.replace(workspaceYaml.defaultArgs.codeVersion, version);
await Bun.write(pathToWorkspaceYaml, newYaml);
await appendGitHubOutput(`codeVersion=${version}`)
await appendGitHubOutput(`codeCommit=${commit}`)
};
await main();