|
| 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 = [ |
| 15 | + 'react-native-artifacts', |
| 16 | + 'react-android', |
| 17 | + 'hermes-android', |
| 18 | +]; |
| 19 | +const humanNames = { |
| 20 | + 'react-native-artifacts': 'Hermes for iOS', |
| 21 | + 'react-android': 'React Native for Android', |
| 22 | + 'hermes-android': 'Hermes for Android', |
| 23 | +}; |
| 24 | +const ping_minutes = 5; |
| 25 | +const max_hours = 5; |
| 26 | +const ping_interval = ping_minutes * 60 * 1000; // 5 minutes |
| 27 | +const max_wait = max_hours * 60 * 60 * 1000; // 5 hours |
| 28 | + |
| 29 | +const startTime = Date.now(); |
| 30 | + |
| 31 | +async function pingMaven(artifact, rnVersion) { |
| 32 | + const url = `${baseMavenRepo}/${artifact}/${rnVersion}`; |
| 33 | + const response = await fetch(url, {method: "HEAD"}); |
| 34 | + if (response.status === 200) { |
| 35 | + console.log(`Found artifact for ${humanNames[artifact]}\n`); |
| 36 | + return; |
| 37 | + } else if (response.status !== 404) { |
| 38 | + throw new Error(`Unexpected response code ${response.status} for ${humanNames[artifact]}`); |
| 39 | + } |
| 40 | + |
| 41 | + const elapsedTime = Date.now() - startTime; |
| 42 | + if (elapsedTime > max_wait) { |
| 43 | + throw new Error(`${max_hours} hours has passed. Exiting.`); |
| 44 | + } |
| 45 | + // Wait a bit |
| 46 | + console.log(`${humanNames[artifact]} not available yet. Waiting ${ping_minutes} minutes.\n`); |
| 47 | + await new Promise(resolve => setTimeout(resolve, ping_interval)); |
| 48 | + await pingMaven(url); |
| 49 | +} |
| 50 | + |
| 51 | +async function main() { |
| 52 | + const package = JSON.parse(fs.readFileSync('packages/react-native/package.json', 'utf8')); |
| 53 | + const rnVersion = package.version; |
| 54 | + |
| 55 | + if (rnVersion === '1000.0.0') { |
| 56 | + console.log("We are not on a release branch when a release has been initiated. Exiting."); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + console.log(`Checking artifacts for React Native version ${rnVersion}\n`); |
| 61 | + |
| 62 | + for (const artifact of artifacts) { |
| 63 | + console.log(`Start pinging for ${humanNames[artifact]}`) |
| 64 | + await pingMaven(artifact, rnVersion); |
| 65 | + }; |
| 66 | +} |
| 67 | + |
| 68 | +main(); |
0 commit comments