-
Notifications
You must be signed in to change notification settings - Fork 24k
/
poll-maven.js
72 lines (62 loc) · 2.08 KB
/
poll-maven.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* 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();