Path: blob/main/components/ide/gha-update-image/check-code-build.ts
2500 views
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34import { $ } from "bun";5import { parseArgs } from "util";6import { appendGitHubOutput, pathToWorkspaceYaml, readWorkspaceYaml } from "./lib/common";78$.nothrow();910const workspaceYamlInfo = await readWorkspaceYaml();11const rawWorkspaceYaml = workspaceYamlInfo.rawText;12const workspaceYaml = workspaceYamlInfo.parsedObj;1314const { values } = parseArgs({15args: Bun.argv,16options: {17branch: {18type: "string",19},20},21strict: true,22allowPositionals: true,23});2425const inputs = {26branch: values.branch,27};2829// example: bun run check-code-build.ts --branch gp-code/release/1.8930const main = async () => {31if (!inputs.branch || !inputs.branch.startsWith("gp-code/release/")) {32throw new Error(`invalid branch ${inputs.branch}, expected something like \`gp-code/release/1.90\``);33}34const commit =35await $`curl -H 'Accept: application/vnd.github.VERSION.sha' https://api.github.com/repos/gitpod-io/openvscode-server/commits/${inputs.branch}`.text();3637const version = JSON.parse(38await $`curl https://raw.githubusercontent.com/gitpod-io/openvscode-server/${commit}/package.json`.text(),39).version;4041console.log("fetch gitpod-io/openvscode-server with " + inputs.branch, { commit, version });4243if (workspaceYaml.defaultArgs.codeVersion === version) {44console.error("code version is the same, no need to update");45return;46}47console.log(48`found different version ${version} (than ${workspaceYaml.defaultArgs.codeVersion}) with commit:${commit} (than ${workspaceYaml.defaultArgs.codeCommit})`,49);50const newYaml = rawWorkspaceYaml51.replace(workspaceYaml.defaultArgs.codeCommit, commit)52.replace(workspaceYaml.defaultArgs.codeVersion, version);5354await Bun.write(pathToWorkspaceYaml, newYaml);55await appendGitHubOutput(`codeVersion=${version}`)56await appendGitHubOutput(`codeCommit=${commit}`)57};5859await main();606162