Skip to content

Commit 9817f8a

Browse files
committed
Add scripts and pipeline to poll for maven
1 parent fe804b8 commit 9817f8a

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

.circleci/config.yml

Lines changed: 17 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
# -------------------------
@@ -1900,6 +1913,9 @@ workflows:
19001913
- build_hermesc_linux
19011914
- build_hermes_macos
19021915
- build_hermesc_windows
1916+
- poll_maven:
1917+
requires:
1918+
- build_and_publish_npm_package
19031919

19041920
package_and_publish_release_dryrun:
19051921
when:
@@ -1941,6 +1957,7 @@ workflows:
19411957
- equal: [ false, << pipeline.parameters.run_release_workflow >> ]
19421958
- equal: [ false, << pipeline.parameters.run_nightly_workflow >> ]
19431959
jobs:
1960+
- poll_maven
19441961
# Run lints on every commit
19451962
- analyze_code
19461963

scripts/circleci/poll-maven.js

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

Comments
 (0)