Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/createBuild.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
if (process.argv.length !== 3) {
11
console.error('Usage: node createBuild.js VERSION');
12
process.exit(-1);
13
}
14
15
function getEnv(name: string): string {
16
const result = process.env[name];
17
18
if (typeof result === 'undefined') {
19
throw new Error('Missing env: ' + name);
20
}
21
22
return result;
23
}
24
25
async function main(): Promise<void> {
26
const [, , _version] = process.argv;
27
const quality = getEnv('VSCODE_QUALITY');
28
const commit = getEnv('BUILD_SOURCEVERSION');
29
const queuedBy = getEnv('BUILD_QUEUEDBY');
30
const sourceBranch = getEnv('BUILD_SOURCEBRANCH');
31
const version = _version + (quality === 'stable' ? '' : `-${quality}`);
32
33
console.log('Creating build...');
34
console.log('Quality:', quality);
35
console.log('Version:', version);
36
console.log('Commit:', commit);
37
38
const build = {
39
id: commit,
40
timestamp: (new Date()).getTime(),
41
version,
42
isReleased: false,
43
private: process.env['VSCODE_PRIVATE_BUILD']?.toLowerCase() === 'true',
44
sourceBranch,
45
queuedBy,
46
assets: [],
47
updates: {}
48
};
49
50
const aadCredentials = new ClientAssertionCredential(process.env['AZURE_TENANT_ID']!, process.env['AZURE_CLIENT_ID']!, () => Promise.resolve(process.env['AZURE_ID_TOKEN']!));
51
const client = new CosmosClient({ endpoint: process.env['AZURE_DOCUMENTDB_ENDPOINT']!, aadCredentials });
52
const scripts = client.database('builds').container(quality).scripts;
53
await retry(() => scripts.storedProcedure('createBuild').execute('', [{ ...build, _partitionKey: '' }]));
54
}
55
56
main().then(() => {
57
console.log('Build successfully created');
58
process.exit(0);
59
}, err => {
60
console.error(err);
61
process.exit(1);
62
});
63
64