|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +const fetch = require('node-fetch'); |
| 11 | +const fs = require('fs'); |
| 12 | + |
| 13 | +const baseMavenRepo = 'https://repo1.maven.org/maven2/com/facebook/react'; |
| 14 | +const artifacts = ['react-native-artifacts', 'react-android', 'hermes-android']; |
| 15 | +const humanNames = { |
| 16 | + 'react-native-artifacts': 'Hermes for iOS', |
| 17 | + 'react-android': 'React Native for Android', |
| 18 | + 'hermes-android': 'Hermes for Android', |
| 19 | +}; |
| 20 | +const ping_minutes = 5; |
| 21 | +const max_hours = 5; |
| 22 | +const ping_interval = ping_minutes * 60 * 1000; // 5 minutes |
| 23 | +const max_wait = max_hours * 60 * 60 * 1000; // 5 hours |
| 24 | + |
| 25 | +const startTime = Date.now(); |
| 26 | + |
| 27 | +async function pingMaven(artifact, rnVersion) { |
| 28 | + const url = `${baseMavenRepo}/${artifact}/${rnVersion}`; |
| 29 | + const response = await fetch(url, {method: 'HEAD'}); |
| 30 | + if (response.status === 200) { |
| 31 | + console.log(`Found artifact for ${humanNames[artifact]}\n`); |
| 32 | + return; |
| 33 | + } else if (response.status !== 404) { |
| 34 | + throw new Error( |
| 35 | + `Unexpected response code ${response.status} for ${humanNames[artifact]}`, |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + const elapsedTime = Date.now() - startTime; |
| 40 | + if (elapsedTime > max_wait) { |
| 41 | + throw new Error(`${max_hours} hours has passed. Exiting.`); |
| 42 | + } |
| 43 | + // Wait a bit |
| 44 | + console.log( |
| 45 | + `${humanNames[artifact]} not available yet. Waiting ${ping_minutes} minutes.\n`, |
| 46 | + ); |
| 47 | + await new Promise(resolve => setTimeout(resolve, ping_interval)); |
| 48 | + await pingMaven(url); |
| 49 | +} |
| 50 | + |
| 51 | +async function main() { |
| 52 | + const package = JSON.parse( |
| 53 | + fs.readFileSync('packages/react-native/package.json', 'utf8'), |
| 54 | + ); |
| 55 | + const rnVersion = package.version; |
| 56 | + |
| 57 | + if (rnVersion === '1000.0.0') { |
| 58 | + console.log( |
| 59 | + 'We are not on a release branch when a release has been initiated. Exiting.', |
| 60 | + ); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + console.log(`Checking artifacts for React Native version ${rnVersion}\n`); |
| 65 | + |
| 66 | + for (const artifact of artifacts) { |
| 67 | + console.log(`Start pinging for ${humanNames[artifact]}`); |
| 68 | + await pingMaven(artifact, rnVersion); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +main(); |
0 commit comments