[ci] Fix incorrect polling
Oops. Actually poll correctly by fetching the latest workflow run each retry, and not just checking the first attempt. Test plan: https://github.com/facebook/react/actions/runs/10165564989 ghstack-source-id: 3202d8f6aeb1e1dead95d82a33c04dce80cd44b4 Pull Request resolved: https://github.com/facebook/react/pull/30531
Lauren Tan committed
Jul 30, 2024 at 11:53 UTC
ab7c1663131aa0f572f21ebd8575dddb7db1b372
1 file changed
+51
-42
scripts/release/shared-commands/download-build-artifacts.js
+51
-42
@@ -87,11 +87,51 @@ async function getArtifact(workflowRunId, artifactName) {
87
return artifact;
88
}
89
90
+async function processArtifact(artifact, releaseChannel) {
91
+ // Download and extract artifact
92
+ const cwd = join(__dirname, '..', '..', '..');
93
+ await exec(`rm -rf ./build`, {cwd});
94
+ await exec(
95
+ `curl -L ${GITHUB_HEADERS} ${artifact.archive_download_url} \
96
+ > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz`,
97
+ {
98
+ cwd,
99
+ }
100
+ );
101
+
102
+ // Copy to staging directory
103
+ // TODO: Consider staging the release in a different directory from the CI
104
+ // build artifacts: `./build/node_modules` -> `./staged-releases`
105
+ if (!existsSync(join(cwd, 'build'))) {
106
+ await exec(`mkdir ./build`, {cwd});
107
+ } else {
108
+ await exec(`rm -rf ./build/node_modules`, {cwd});
109
+ }
110
+ let sourceDir;
111
+ // TODO: Rename release channel to `next`
112
+ if (releaseChannel === 'stable') {
113
+ sourceDir = 'oss-stable';
114
+ } else if (releaseChannel === 'experimental') {
115
+ sourceDir = 'oss-experimental';
116
+ } else if (releaseChannel === 'rc') {
117
+ sourceDir = 'oss-stable-rc';
118
+ } else if (releaseChannel === 'latest') {
119
+ sourceDir = 'oss-stable-semver';
120
+ } else {
121
+ console.error('Internal error: Invalid release channel: ' + releaseChannel);
122
+ process.exit(releaseChannel);
123
+ }
124
+ await exec(`cp -r ./build/${sourceDir} ./build/node_modules`, {
125
+ cwd,
126
+ });
127
+}
128
+
129
async function downloadArtifactsFromGitHub(commit, releaseChannel) {
91
- const workflowRun = await getWorkflowRun(commit);
130
+ let workflowRun;
131
let retries = 0;
132
// wait up to 10 mins for build to finish: 10 * 60 * 1_000) / 30_000 = 20
133
while (retries < 20) {
134
+ workflowRun = await getWorkflowRun(commit);
135
if (typeof workflowRun.status === 'string') {
136
switch (workflowRun.status) {
137
case 'queued':
@@ -108,49 +148,11 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) {
148
workflowRun.id,
149
'artifacts_combined'
150
);
111
-
112
- // Download and extract artifact
113
- const cwd = join(__dirname, '..', '..', '..');
114
- await exec(`rm -rf ./build`, {cwd});
115
- await exec(
116
- `curl -L ${GITHUB_HEADERS} ${artifact.archive_download_url} \
117
- > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz`,
118
- {
119
- cwd,
120
- }
121
- );
122
-
123
- // Copy to staging directory
124
- // TODO: Consider staging the release in a different directory from the CI
125
- // build artifacts: `./build/node_modules` -> `./staged-releases`
126
- if (!existsSync(join(cwd, 'build'))) {
127
- await exec(`mkdir ./build`, {cwd});
128
- } else {
129
- await exec(`rm -rf ./build/node_modules`, {cwd});
130
- }
131
- let sourceDir;
132
- // TODO: Rename release channel to `next`
133
- if (releaseChannel === 'stable') {
134
- sourceDir = 'oss-stable';
135
- } else if (releaseChannel === 'experimental') {
136
- sourceDir = 'oss-experimental';
137
- } else if (releaseChannel === 'rc') {
138
- sourceDir = 'oss-stable-rc';
139
- } else if (releaseChannel === 'latest') {
140
- sourceDir = 'oss-stable-semver';
141
- } else {
142
- console.error(
143
- 'Internal error: Invalid release channel: ' + releaseChannel
144
- );
145
- process.exit(releaseChannel);
146
- }
147
- await exec(`cp -r ./build/${sourceDir} ./build/node_modules`, {
148
- cwd,
149
- });
151
+ await processArtifact(artifact, releaseChannel);
152
return;
153
} else {
154
console.log(
153
- theme`{error Could not download build for ${commit} from GitHub as its conclusion was: ${workflowRun.conclusion}}`
155
+ theme`{error Could not download build as its conclusion was: ${workflowRun.conclusion}}`
156
);
157
process.exit(1);
158
}
@@ -163,11 +165,18 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) {
165
process.exit(1);
166
}
167
}
168
+ } else {
169
+ retries++;
170
+ console.log(
171
+ theme`{error Expected workflow run status to be a string, got: ${workflowRun.status}. Retrying...}`
172
+ );
173
}
174
}
175
176
console.log(
170
- theme`{error Could not download build for ${commit} from GitHub as it timed out}`
177
+ theme`{error Could not download build from GitHub. Last workflow run: }
178
+
179
+${workflowRun != null ? JSON.stringify(workflowRun, null, '\t') : workflowRun}`
180
);
181
process.exit(1);
182
}