Path: blob/main/build/azure-pipelines/common/waitForArtifacts.ts
3520 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Artifact, requestAZDOAPI } from '../common/publish';6import { retry } from '../common/retry';78async function getPipelineArtifacts(): Promise<Artifact[]> {9const result = await requestAZDOAPI<{ readonly value: Artifact[] }>('artifacts');10return result.value.filter(a => !/sbom$/.test(a.name));11}1213async function main(artifacts: string[]): Promise<void> {14if (artifacts.length === 0) {15throw new Error(`Usage: node waitForArtifacts.js <artifactName1> <artifactName2> ...`);16}1718// This loop will run for 30 minutes and waits to the x64 and arm64 artifacts19// to be uploaded to the pipeline by the `macOS` and `macOSARM64` jobs. As soon20// as these artifacts are found, the loop completes and the `macOSUnivesrsal`21// job resumes.22for (let index = 0; index < 60; index++) {23try {24console.log(`Waiting for artifacts (${artifacts.join(', ')}) to be uploaded (${index + 1}/60)...`);25const allArtifacts = await retry(() => getPipelineArtifacts());26console.log(` * Artifacts attached to the pipelines: ${allArtifacts.length > 0 ? allArtifacts.map(a => a.name).join(', ') : 'none'}`);2728const foundArtifacts = allArtifacts.filter(a => artifacts.includes(a.name));29console.log(` * Found artifacts: ${foundArtifacts.length > 0 ? foundArtifacts.map(a => a.name).join(', ') : 'none'}`);3031if (foundArtifacts.length === artifacts.length) {32console.log(` * All artifacts were found`);33return;34}35} catch (err) {36console.error(`ERROR: Failed to get pipeline artifacts: ${err}`);37}3839await new Promise(c => setTimeout(c, 30_000));40}4142throw new Error(`ERROR: Artifacts (${artifacts.join(', ')}) were not uploaded within 30 minutes.`);43}4445main(process.argv.splice(2)).then(() => {46process.exit(0);47}, err => {48console.error(err);49process.exit(1);50});515253