[ci] Fix ci prep script
During params parsing for this script, it previously would call out to CircleCI for a build ID, but this is no longer needed. ghstack-source-id: 9c70824498382827306a1b18b86e319745ab18fd Pull Request resolved: https://github.com/facebook/react/pull/30499
Lauren Tan committed
Jul 29, 2024 at 12:55 UTC
39acfdb3be2c8bd1bc664a07e003bd50955295d9
2 files changed
+2
-93
scripts/release/shared-commands/get-build-id-for-commit.js
deleted
-75
@@ -1,75 +0,0 @@
1
-'use strict';
2
-
3
-const fetch = require('node-fetch');
4
-
5
-const POLLING_INTERVAL = 10 * 1000; // 10 seconds
6
-const RETRY_TIMEOUT = 4 * 60 * 1000; // 4 minutes
7
-
8
-function wait(ms) {
9
- return new Promise(resolve => {
10
- setTimeout(() => resolve(), ms);
11
- });
12
-}
13
-
14
-function scrapeBuildIDFromStatus(status) {
15
- return /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
16
-}
17
-
18
-async function getBuildIdForCommit(sha, allowBrokenCI = false) {
19
- const retryLimit = Date.now() + RETRY_TIMEOUT;
20
- retry: while (true) {
21
- const statusesResponse = await fetch(
22
- `https://api.github.com/repos/facebook/react/commits/${sha}/status?per_page=100`
23
- );
24
-
25
- if (!statusesResponse.ok) {
26
- if (statusesResponse.status === 404) {
27
- throw Error('Could not find commit for: ' + sha);
28
- }
29
- const {message, documentation_url} = await statusesResponse.json();
30
- const msg = documentation_url
31
- ? `${message}\n\t${documentation_url}`
32
- : message;
33
- throw Error(msg);
34
- }
35
-
36
- const {statuses, state} = await statusesResponse.json();
37
- if (!allowBrokenCI && state === 'failure') {
38
- throw new Error(`Base commit is broken: ${sha}`);
39
- }
40
- for (let i = 0; i < statuses.length; i++) {
41
- const status = statuses[i];
42
- if (status.context === `ci/circleci: process_artifacts_combined`) {
43
- if (status.state === 'success') {
44
- return scrapeBuildIDFromStatus(status);
45
- }
46
- if (status.state === 'failure') {
47
- throw new Error(`Build job for commit failed: ${sha}`);
48
- }
49
- if (status.state === 'pending') {
50
- if (Date.now() < retryLimit) {
51
- await wait(POLLING_INTERVAL);
52
- continue retry;
53
- }
54
- // GitHub's status API is super flaky. Sometimes it reports a job
55
- // as "pending" even after it completes in CircleCI. If it's still
56
- // pending when we time out, return the build ID anyway.
57
- // TODO: The location of the retry loop is a bit weird. We should
58
- // probably combine this function with the one that downloads the
59
- // artifacts, and wrap the retry loop around the whole thing.
60
- return scrapeBuildIDFromStatus(status);
61
- }
62
- }
63
- }
64
- if (state === 'pending') {
65
- if (Date.now() < retryLimit) {
66
- await wait(POLLING_INTERVAL);
67
- continue retry;
68
- }
69
- throw new Error('Exceeded retry limit. Build job is still pending.');
70
- }
71
- throw new Error('Could not find build for commit: ' + sha);
72
- }
73
-}
74
-
75
-module.exports = getBuildIdForCommit;
scripts/release/shared-commands/parse-params.js
+2
-18
@@ -3,9 +3,7 @@
3
'use strict';
4
5
const commandLineArgs = require('command-line-args');
6
-const getBuildIdForCommit = require('./get-build-id-for-commit');
6
const theme = require('../theme');
8
-const {logPromise} = require('../utils');
7
8
const paramDefinitions = [
9
{
@@ -59,22 +57,8 @@ module.exports = async () => {
57
process.exit(1);
58
}
59
62
- if (params.build === null && params.commit === null) {
63
- console.error(
64
- theme.error`Either a --commit or --build param must be specified.`
65
- );
66
- process.exit(1);
67
- }
68
-
69
- try {
70
- if (params.build === null) {
71
- params.build = await logPromise(
72
- getBuildIdForCommit(params.commit, params.allowBrokenCI),
73
- theme`Getting build ID for commit "${params.commit}"`
74
- );
75
- }
76
- } catch (error) {
77
- console.error(theme.error(error));
60
+ if (params.commit === null) {
61
+ console.error(theme.error`A --commit param must be specified.`);
62
process.exit(1);
63
}
64