Skip to content

Commit 4b82896

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Automate checking for artifacts on Maven (facebook#50275)
Summary: Pull Request resolved: facebook#50275 This change adds a check to automate a step in the release process: https://github.com/reactwg/react-native-releases/blob/main/docs/guide-release-process.md#verify-assets-have-been-uploaded-to-maven The script will poll maven for 90 minutes and return when the artifacts are available. If, after 90 minutes, artifacts are not available, it exits with code 1 that should fail the Release workflow. The Release Crew should have a look at what's happened. ## Changelog: [Internal] - Automate the check for artifacts being on Maven Reviewed By: fabriziocucci Differential Revision: D71825014 fbshipit-source-id: 8879bf9c8fc4519e86b55ad8f9bd3ecf3f8ecfb7
1 parent 515976c commit 4b82896

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 {verifyArtifactsAreOnMaven} = require('../verifyArtifactsAreOnMaven');
11+
12+
const mockSleep = jest.fn();
13+
const silence = () => {};
14+
const mockFetch = jest.fn();
15+
const mockExit = jest.fn();
16+
17+
jest.mock('../utils.js', () => ({
18+
log: silence,
19+
sleep: mockSleep,
20+
}));
21+
22+
process.exit = mockExit;
23+
global.fetch = mockFetch;
24+
25+
describe('#verifyArtifactsAreOnMaven', () => {
26+
beforeEach(jest.clearAllMocks);
27+
28+
it('waits for the packages to be published on maven when version has no v', async () => {
29+
mockSleep.mockReturnValueOnce(Promise.resolve()).mockImplementation(() => {
30+
throw new Error('Should not be called again!');
31+
});
32+
mockFetch
33+
.mockReturnValueOnce(Promise.resolve({status: 404}))
34+
.mockReturnValueOnce(Promise.resolve({status: 200}));
35+
36+
const version = '0.78.1';
37+
await verifyArtifactsAreOnMaven(version);
38+
39+
expect(mockSleep).toHaveBeenCalledTimes(1);
40+
expect(mockFetch).toHaveBeenCalledWith(
41+
'https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.78.1',
42+
);
43+
});
44+
45+
it('waits for the packages to be published on maven, when version starts with v', async () => {
46+
mockSleep.mockReturnValueOnce(Promise.resolve()).mockImplementation(() => {
47+
throw new Error('Should not be called again!');
48+
});
49+
mockFetch
50+
.mockReturnValueOnce(Promise.resolve({status: 404}))
51+
.mockReturnValueOnce(Promise.resolve({status: 200}));
52+
53+
const version = 'v0.78.1';
54+
await verifyArtifactsAreOnMaven(version);
55+
56+
expect(mockSleep).toHaveBeenCalledTimes(1);
57+
expect(mockFetch).toHaveBeenCalledWith(
58+
'https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.78.1',
59+
);
60+
});
61+
62+
it('passes immediately if packages are already on Maven', async () => {
63+
mockFetch.mockReturnValueOnce(Promise.resolve({status: 200}));
64+
65+
const version = '0.78.1';
66+
await verifyArtifactsAreOnMaven(version);
67+
68+
expect(mockSleep).toHaveBeenCalledTimes(0);
69+
expect(mockFetch).toHaveBeenCalledWith(
70+
'https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.78.1',
71+
);
72+
});
73+
74+
it('tries 90 times and then exits', async () => {
75+
mockSleep.mockReturnValue(Promise.resolve());
76+
mockFetch.mockReturnValue(Promise.resolve({status: 404}));
77+
78+
const version = '0.78.1';
79+
await verifyArtifactsAreOnMaven(version);
80+
81+
expect(mockSleep).toHaveBeenCalledTimes(90);
82+
expect(mockExit).toHaveBeenCalledWith(1);
83+
expect(mockFetch).toHaveBeenCalledWith(
84+
'https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.78.1',
85+
);
86+
});
87+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 {log, sleep} = require('./utils');
11+
12+
const SLEEP_S = 60; // 1 minute
13+
const MAX_RETRIES = 90; // 90 attempts. Waiting between attempt: 1 min. Total time: 90 min.
14+
const ARTIFACT_URL =
15+
'https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/';
16+
17+
async function verifyArtifactsAreOnMaven(version, retries = MAX_RETRIES) {
18+
if (version.startsWith('v')) {
19+
version = version.substring(1);
20+
}
21+
22+
const artifactUrl = `${ARTIFACT_URL}${version}`;
23+
for (let currentAttempt = 1; currentAttempt <= retries; currentAttempt++) {
24+
const response = await fetch(artifactUrl);
25+
26+
if (response.status !== 200) {
27+
log(
28+
`${currentAttempt}) Artifact's for version ${version} are not on maven yet.\nURL: ${artifactUrl}\nLet's wait a minute and try again.\n`,
29+
);
30+
await sleep(SLEEP_S);
31+
} else {
32+
return;
33+
}
34+
}
35+
36+
log(
37+
`We waited 90 minutes for the artifacts to be on Maven. Check https://status.maven.org/ if there are issues wth the service.`,
38+
);
39+
process.exit(1);
40+
}
41+
42+
module.exports = {verifyArtifactsAreOnMaven};

.github/workflows/publish-release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,10 @@ jobs:
230230
const {isLatest} = require('./.github/workflow-scripts/publishTemplate.js');
231231
const version = "${{ github.ref_name }}";
232232
await verifyReleaseOnNpm(version, isLatest());
233+
- name: Verify that artifacts are on Maven
234+
uses: actions/github-script@v6
235+
with:
236+
script: |
237+
const {verifyArtifactsAreOnMaven} = require('./.github/workflow-scripts/verifyArtifactsAreOnMaven.js');
238+
const version = "${{ github.ref_name }}";
239+
await verifyArtifactsAreOnMaven(version);

0 commit comments

Comments
 (0)