Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide/gha-update-image/check-code-build.ts
2500 views
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
import { $ } from "bun";
6
import { parseArgs } from "util";
7
import { appendGitHubOutput, pathToWorkspaceYaml, readWorkspaceYaml } from "./lib/common";
8
9
$.nothrow();
10
11
const workspaceYamlInfo = await readWorkspaceYaml();
12
const rawWorkspaceYaml = workspaceYamlInfo.rawText;
13
const workspaceYaml = workspaceYamlInfo.parsedObj;
14
15
const { values } = parseArgs({
16
args: Bun.argv,
17
options: {
18
branch: {
19
type: "string",
20
},
21
},
22
strict: true,
23
allowPositionals: true,
24
});
25
26
const inputs = {
27
branch: values.branch,
28
};
29
30
// example: bun run check-code-build.ts --branch gp-code/release/1.89
31
const main = async () => {
32
if (!inputs.branch || !inputs.branch.startsWith("gp-code/release/")) {
33
throw new Error(`invalid branch ${inputs.branch}, expected something like \`gp-code/release/1.90\``);
34
}
35
const commit =
36
await $`curl -H 'Accept: application/vnd.github.VERSION.sha' https://api.github.com/repos/gitpod-io/openvscode-server/commits/${inputs.branch}`.text();
37
38
const version = JSON.parse(
39
await $`curl https://raw.githubusercontent.com/gitpod-io/openvscode-server/${commit}/package.json`.text(),
40
).version;
41
42
console.log("fetch gitpod-io/openvscode-server with " + inputs.branch, { commit, version });
43
44
if (workspaceYaml.defaultArgs.codeVersion === version) {
45
console.error("code version is the same, no need to update");
46
return;
47
}
48
console.log(
49
`found different version ${version} (than ${workspaceYaml.defaultArgs.codeVersion}) with commit:${commit} (than ${workspaceYaml.defaultArgs.codeCommit})`,
50
);
51
const newYaml = rawWorkspaceYaml
52
.replace(workspaceYaml.defaultArgs.codeCommit, commit)
53
.replace(workspaceYaml.defaultArgs.codeVersion, version);
54
55
await Bun.write(pathToWorkspaceYaml, newYaml);
56
await appendGitHubOutput(`codeVersion=${version}`)
57
await appendGitHubOutput(`codeCommit=${commit}`)
58
};
59
60
await main();
61
62