Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/waitForArtifacts.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 { Artifact, requestAZDOAPI } from '../common/publish';
7
import { retry } from '../common/retry';
8
9
async function getPipelineArtifacts(): Promise<Artifact[]> {
10
const result = await requestAZDOAPI<{ readonly value: Artifact[] }>('artifacts');
11
return result.value.filter(a => !/sbom$/.test(a.name));
12
}
13
14
async function main(artifacts: string[]): Promise<void> {
15
if (artifacts.length === 0) {
16
throw new Error(`Usage: node waitForArtifacts.js <artifactName1> <artifactName2> ...`);
17
}
18
19
// This loop will run for 30 minutes and waits to the x64 and arm64 artifacts
20
// to be uploaded to the pipeline by the `macOS` and `macOSARM64` jobs. As soon
21
// as these artifacts are found, the loop completes and the `macOSUnivesrsal`
22
// job resumes.
23
for (let index = 0; index < 60; index++) {
24
try {
25
console.log(`Waiting for artifacts (${artifacts.join(', ')}) to be uploaded (${index + 1}/60)...`);
26
const allArtifacts = await retry(() => getPipelineArtifacts());
27
console.log(` * Artifacts attached to the pipelines: ${allArtifacts.length > 0 ? allArtifacts.map(a => a.name).join(', ') : 'none'}`);
28
29
const foundArtifacts = allArtifacts.filter(a => artifacts.includes(a.name));
30
console.log(` * Found artifacts: ${foundArtifacts.length > 0 ? foundArtifacts.map(a => a.name).join(', ') : 'none'}`);
31
32
if (foundArtifacts.length === artifacts.length) {
33
console.log(` * All artifacts were found`);
34
return;
35
}
36
} catch (err) {
37
console.error(`ERROR: Failed to get pipeline artifacts: ${err}`);
38
}
39
40
await new Promise(c => setTimeout(c, 30_000));
41
}
42
43
throw new Error(`ERROR: Artifacts (${artifacts.join(', ')}) were not uploaded within 30 minutes.`);
44
}
45
46
main(process.argv.splice(2)).then(() => {
47
process.exit(0);
48
}, err => {
49
console.error(err);
50
process.exit(1);
51
});
52
53