@samitouri / QOS-React-2 / commits / d56947eb2c

Increase polling threshold for publish-prereleases (#22392)

The publish-preleases command prints the URL of the publish workflow so that you can visit the page and follow along. But it can take a few seconds before the workflow ID is available, after you create the pipeline. So the script polls the workflow endpoint until it's available. The current polling limit is too low so I increased it. I also updated the error message to provide more info.

Andrew Clark committed Sep 21, 2021 at 21:43 UTC d56947eb2c2a0d1599975b90a353b06b58c0e00c
1 file changed +17 -3
scripts/release/publish-using-ci-workflow.js
+17 -3
@@ -22,8 +22,8 @@ function sleep(ms) {
22
23 async function getPublishWorkflowID(pipelineID) {
24 // Since we just created the pipeline in a POST request, the server may 404.
25 - // Try up to three times before giving up.
26 - for (let i = 0; i < 3; i++) {
25 + // Try a few times before giving up.
26 + for (let i = 0; i < 20; i++) {
27 const pipelineWorkflowsResponse = await fetch(
28 `https://circleci.com/api/v2/pipeline/${pipelineID}/workflow`
29 );
@@ -37,7 +37,7 @@ async function getPublishWorkflowID(pipelineID) {
37 // CircleCI server may be stale. Wait a sec and try again.
38 await sleep(1000);
39 }
40 - throw new Error('Failed to create CircleCI workflow.');
40 + return null;
41 }
42
43 async function pollUntilWorkflowFinishes(workflowID) {
@@ -108,6 +108,20 @@ async function main() {
108 2 * 1000 // Estimated time: 2 seconds,
109 );
110
111 + if (workflowID === null) {
112 + console.warn(
113 + theme.yellow(
114 + 'Created a CI pipeline to publish the packages, but the script timed ' +
115 + "out when requesting the associated workflow ID. It's still " +
116 + 'possible the workflow was created.\n\n' +
117 + 'Visit ' +
118 + 'https://app.circleci.com/pipelines/github/facebook/react?branch=main ' +
119 + 'for a list of the latest workflows.'
120 + )
121 + );
122 + process.exit(1);
123 + }
124 +
125 await logPromise(
126 pollUntilWorkflowFinishes(workflowID),
127 theme`{header Publishing in CI workflow}: https://app.circleci.com/pipelines/workflows/${workflowID}`,