From 39acfdb3be2c8bd1bc664a07e003bd50955295d9 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Mon, 29 Jul 2024 12:55:35 -0400 Subject: [PATCH] [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 --- .../get-build-id-for-commit.js | 75 ------------------- .../release/shared-commands/parse-params.js | 20 +---- 2 files changed, 2 insertions(+), 93 deletions(-) delete mode 100644 scripts/release/shared-commands/get-build-id-for-commit.js diff --git a/scripts/release/shared-commands/get-build-id-for-commit.js b/scripts/release/shared-commands/get-build-id-for-commit.js deleted file mode 100644 index dc82bbb3f1..0000000000 --- a/scripts/release/shared-commands/get-build-id-for-commit.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -const fetch = require('node-fetch'); - -const POLLING_INTERVAL = 10 * 1000; // 10 seconds -const RETRY_TIMEOUT = 4 * 60 * 1000; // 4 minutes - -function wait(ms) { - return new Promise(resolve => { - setTimeout(() => resolve(), ms); - }); -} - -function scrapeBuildIDFromStatus(status) { - return /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1]; -} - -async function getBuildIdForCommit(sha, allowBrokenCI = false) { - const retryLimit = Date.now() + RETRY_TIMEOUT; - retry: while (true) { - const statusesResponse = await fetch( - `https://api.github.com/repos/facebook/react/commits/${sha}/status?per_page=100` - ); - - if (!statusesResponse.ok) { - if (statusesResponse.status === 404) { - throw Error('Could not find commit for: ' + sha); - } - const {message, documentation_url} = await statusesResponse.json(); - const msg = documentation_url - ? `${message}\n\t${documentation_url}` - : message; - throw Error(msg); - } - - const {statuses, state} = await statusesResponse.json(); - if (!allowBrokenCI && state === 'failure') { - throw new Error(`Base commit is broken: ${sha}`); - } - for (let i = 0; i < statuses.length; i++) { - const status = statuses[i]; - if (status.context === `ci/circleci: process_artifacts_combined`) { - if (status.state === 'success') { - return scrapeBuildIDFromStatus(status); - } - if (status.state === 'failure') { - throw new Error(`Build job for commit failed: ${sha}`); - } - if (status.state === 'pending') { - if (Date.now() < retryLimit) { - await wait(POLLING_INTERVAL); - continue retry; - } - // GitHub's status API is super flaky. Sometimes it reports a job - // as "pending" even after it completes in CircleCI. If it's still - // pending when we time out, return the build ID anyway. - // TODO: The location of the retry loop is a bit weird. We should - // probably combine this function with the one that downloads the - // artifacts, and wrap the retry loop around the whole thing. - return scrapeBuildIDFromStatus(status); - } - } - } - if (state === 'pending') { - if (Date.now() < retryLimit) { - await wait(POLLING_INTERVAL); - continue retry; - } - throw new Error('Exceeded retry limit. Build job is still pending.'); - } - throw new Error('Could not find build for commit: ' + sha); - } -} - -module.exports = getBuildIdForCommit; diff --git a/scripts/release/shared-commands/parse-params.js b/scripts/release/shared-commands/parse-params.js index 6e3b783709..6f43ba074b 100644 --- a/scripts/release/shared-commands/parse-params.js +++ b/scripts/release/shared-commands/parse-params.js @@ -3,9 +3,7 @@ 'use strict'; const commandLineArgs = require('command-line-args'); -const getBuildIdForCommit = require('./get-build-id-for-commit'); const theme = require('../theme'); -const {logPromise} = require('../utils'); const paramDefinitions = [ { @@ -59,22 +57,8 @@ module.exports = async () => { process.exit(1); } - if (params.build === null && params.commit === null) { - console.error( - theme.error`Either a --commit or --build param must be specified.` - ); - process.exit(1); - } - - try { - if (params.build === null) { - params.build = await logPromise( - getBuildIdForCommit(params.commit, params.allowBrokenCI), - theme`Getting build ID for commit "${params.commit}"` - ); - } - } catch (error) { - console.error(theme.error(error)); + if (params.commit === null) { + console.error(theme.error`A --commit param must be specified.`); process.exit(1); }