Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/releaseBuild.ts
5263 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CosmosClient } from '@azure/cosmos';
7
import { retry } from './retry.ts';
8
import { checkCopilotChatCompatibility } from './checkCopilotChatCompatibility.ts';
9
10
function getEnv(name: string): string {
11
const result = process.env[name];
12
13
if (typeof result === 'undefined') {
14
throw new Error('Missing env: ' + name);
15
}
16
17
return result;
18
}
19
20
interface Config {
21
id: string;
22
frozen: boolean;
23
}
24
25
function createDefaultConfig(quality: string): Config {
26
return {
27
id: quality,
28
frozen: false
29
};
30
}
31
32
async function getConfig(client: CosmosClient, quality: string): Promise<Config> {
33
const query = `SELECT TOP 1 * FROM c WHERE c.id = "${quality}"`;
34
35
const res = await client.database('builds').container('config').items.query(query).fetchAll();
36
37
if (res.resources.length === 0) {
38
return createDefaultConfig(quality);
39
}
40
41
return res.resources[0] as Config;
42
}
43
44
async function main(force: boolean): Promise<void> {
45
const commit = getEnv('BUILD_SOURCEVERSION');
46
const quality = getEnv('VSCODE_QUALITY');
47
48
// Check Copilot Chat compatibility before releasing insider builds
49
if (quality === 'insider') {
50
await checkCopilotChatCompatibility();
51
}
52
53
const { cosmosDBAccessToken } = JSON.parse(getEnv('PUBLISH_AUTH_TOKENS'));
54
const client = new CosmosClient({ endpoint: process.env['AZURE_DOCUMENTDB_ENDPOINT']!, tokenProvider: () => Promise.resolve(`type=aad&ver=1.0&sig=${cosmosDBAccessToken.token}`) });
55
56
if (!force) {
57
const config = await getConfig(client, quality);
58
59
console.log('Quality config:', config);
60
61
if (config.frozen) {
62
console.log(`Skipping release because quality ${quality} is frozen.`);
63
return;
64
}
65
}
66
67
console.log(`Releasing build ${commit}...`);
68
69
let rolloutDurationMs = undefined;
70
71
// If the build is insiders or exploration, start a rollout of 4 hours
72
if (quality === 'insider') {
73
rolloutDurationMs = 4 * 60 * 60 * 1000; // 4 hours
74
}
75
76
const scripts = client.database('builds').container(quality).scripts;
77
await retry(() => scripts.storedProcedure('releaseBuild').execute('', [commit, rolloutDurationMs]));
78
}
79
80
const [, , force] = process.argv;
81
82
console.log(process.argv);
83
84
main(/^true$/i.test(force)).then(() => {
85
console.log('Build successfully released');
86
process.exit(0);
87
}, err => {
88
console.error(err);
89
process.exit(1);
90
});
91
92