From 9817f8a2317b283cd358642c86272e6f27dd86ee Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Sat, 12 Aug 2023 18:03:55 +0100 Subject: [PATCH] Add scripts and pipeline to poll for maven --- .circleci/config.yml | 17 +++++++++ scripts/circleci/poll-maven.js | 68 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 scripts/circleci/poll-maven.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f1508213c3341..ce315460d872a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1564,6 +1564,19 @@ jobs: -d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}" # END: Stable releases + poll_maven: + docker: + - image: cimg/node:current + resource_class: small + steps: + - checkout_code_with_cache + - run_yarn + - run: + name: Poll Maven for Artifacts + command: | + node scripts/circleci/poll-maven.js + + # ------------------------- # JOBS: Nightly # ------------------------- @@ -1900,6 +1913,9 @@ workflows: - build_hermesc_linux - build_hermes_macos - build_hermesc_windows + - poll_maven: + requires: + - build_and_publish_npm_package package_and_publish_release_dryrun: when: @@ -1941,6 +1957,7 @@ workflows: - equal: [ false, << pipeline.parameters.run_release_workflow >> ] - equal: [ false, << pipeline.parameters.run_nightly_workflow >> ] jobs: + - poll_maven # Run lints on every commit - analyze_code diff --git a/scripts/circleci/poll-maven.js b/scripts/circleci/poll-maven.js new file mode 100644 index 00000000000000..76fdec41addf5d --- /dev/null +++ b/scripts/circleci/poll-maven.js @@ -0,0 +1,68 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +const fetch = require('node-fetch'); +const fs = require('fs'); + +const baseMavenRepo = 'https://repo1.maven.org/maven2/com/facebook/react'; +const artifacts = [ + 'react-native-artifacts', + 'react-android', + 'hermes-android', +]; +const humanNames = { + 'react-native-artifacts': 'Hermes for iOS', + 'react-android': 'React Native for Android', + 'hermes-android': 'Hermes for Android', +}; +const ping_minutes = 5; +const max_hours = 5; +const ping_interval = ping_minutes * 60 * 1000; // 5 minutes +const max_wait = max_hours * 60 * 60 * 1000; // 5 hours + +const startTime = Date.now(); + +async function pingMaven(artifact, rnVersion) { + const url = `${baseMavenRepo}/${artifact}/${rnVersion}`; + const response = await fetch(url, {method: "HEAD"}); + if (response.status === 200) { + console.log(`Found artifact for ${humanNames[artifact]}\n`); + return; + } else if (response.status !== 404) { + throw new Error(`Unexpected response code ${response.status} for ${humanNames[artifact]}`); + } + + const elapsedTime = Date.now() - startTime; + if (elapsedTime > max_wait) { + throw new Error(`${max_hours} hours has passed. Exiting.`); + } + // Wait a bit + console.log(`${humanNames[artifact]} not available yet. Waiting ${ping_minutes} minutes.\n`); + await new Promise(resolve => setTimeout(resolve, ping_interval)); + await pingMaven(url); +} + +async function main() { + const package = JSON.parse(fs.readFileSync('packages/react-native/package.json', 'utf8')); + const rnVersion = package.version; + + if (rnVersion === '1000.0.0') { + console.log("We are not on a release branch when a release has been initiated. Exiting."); + return; + } + + console.log(`Checking artifacts for React Native version ${rnVersion}\n`); + + for (const artifact of artifacts) { + console.log(`Start pinging for ${humanNames[artifact]}`) + await pingMaven(artifact, rnVersion); + }; +} + +main();