Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/releaseBuild.ts
3520 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 { ClientAssertionCredential } from '@azure/identity';
7
import { CosmosClient } from '@azure/cosmos';
8
import { retry } from './retry';
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
const aadCredentials = new ClientAssertionCredential(process.env['AZURE_TENANT_ID']!, process.env['AZURE_CLIENT_ID']!, () => Promise.resolve(process.env['AZURE_ID_TOKEN']!));
49
const client = new CosmosClient({ endpoint: process.env['AZURE_DOCUMENTDB_ENDPOINT']!, aadCredentials });
50
51
if (!force) {
52
const config = await getConfig(client, quality);
53
54
console.log('Quality config:', config);
55
56
if (config.frozen) {
57
console.log(`Skipping release because quality ${quality} is frozen.`);
58
return;
59
}
60
}
61
62
console.log(`Releasing build ${commit}...`);
63
64
const scripts = client.database('builds').container(quality).scripts;
65
await retry(() => scripts.storedProcedure('releaseBuild').execute('', [commit]));
66
}
67
68
const [, , force] = process.argv;
69
70
console.log(process.argv);
71
72
main(/^true$/i.test(force)).then(() => {
73
console.log('Build successfully released');
74
process.exit(0);
75
}, err => {
76
console.error(err);
77
process.exit(1);
78
});
79
80