Skip to content

Commit 22d1e89

Browse files
authored
Add scripts and pipeline to poll for maven (#38980) (#39039)
1 parent 209e743 commit 22d1e89

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,19 @@ jobs:
15641564
-d "{\"event_type\": \"publish\", \"client_payload\": { \"version\": \"${CIRCLE_TAG:1}\" }}"
15651565
# END: Stable releases
15661566

1567+
poll_maven:
1568+
docker:
1569+
- image: cimg/node:current
1570+
resource_class: small
1571+
steps:
1572+
- checkout_code_with_cache
1573+
- run_yarn
1574+
- run:
1575+
name: Poll Maven for Artifacts
1576+
command: |
1577+
node scripts/circleci/poll-maven.js
1578+
1579+
15671580
# -------------------------
15681581
# JOBS: Nightly
15691582
# -------------------------
@@ -1869,6 +1882,9 @@ workflows:
18691882
- build_hermesc_linux
18701883
- build_hermes_macos
18711884
- build_hermesc_windows
1885+
- poll_maven:
1886+
requires:
1887+
- build_and_publish_npm_package
18721888

18731889
package_and_publish_release_dryrun:
18741890
jobs:

scripts/circleci/poll-maven.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)