Skip to content

Commit a68ae2e

Browse files
huntiefacebook-github-bot
authored andcommitted
Rename and document monorepo publish script (facebook#42989)
Summary: Pull Request resolved: facebook#42989 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D53607805 fbshipit-source-id: 8bbf82c02b54b20404de834800ae49d3fa43baee
1 parent 6a4d011 commit a68ae2e

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

.circleci/configurations/jobs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,4 +1315,4 @@ jobs:
13151315
command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
13161316
- run:
13171317
name: Find and publish all bumped packages
1318-
command: node ./scripts/monorepo/find-and-publish-all-bumped-packages.js
1318+
command: node ./scripts/releases-ci/publish-updated-packages.js

scripts/releases-ci/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ CI-only release scripts — intended to run from a CI workflow (CircleCI or GitH
66

77
For information on command arguments, run `node <command> --help`.
88

9-
### `prepare-package-for-release.js`
9+
### `prepare-package-for-release`
1010

1111
Prepares files within the `react-native` package and template for the target release version. Writes a new commit and tag, which will trigger `publish-npm.js` in a new workflow.
1212

13-
### `publish-npm.js`
13+
### `publish-npm`
1414

1515
Prepares release artifacts and publishes the `react-native` package to npm.
16+
17+
### `publish-updated-packages`
18+
19+
Publishes all updated packages (excluding `react-native`) to npm. Triggered when a commit on a release branch contains `#publish-packages-to-npm`.

scripts/monorepo/__tests__/find-and-publish-all-bumped-packages-test.js renamed to scripts/releases-ci/__tests__/publish-updated-packages-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*/
1111

1212
const {
13-
findAndPublishAllBumpedPackages,
1413
getTagsFromCommitMessage,
15-
} = require('../find-and-publish-all-bumped-packages');
14+
publishUpdatedPackages,
15+
} = require('../publish-updated-packages');
1616

1717
const getPackagesMock = jest.fn();
1818
const execSync = jest.fn();
@@ -30,7 +30,7 @@ global.fetch = fetchMock;
3030
const BUMP_COMMIT_MESSAGE =
3131
'bumped packages versions\n\n#publish-packages-to-npm';
3232

33-
describe('findAndPublishAllBumpedPackages', () => {
33+
describe('publishUpdatedPackages', () => {
3434
beforeEach(() => {
3535
jest.spyOn(console, 'log').mockImplementation(() => {});
3636
jest.resetAllMocks();
@@ -47,7 +47,7 @@ describe('findAndPublishAllBumpedPackages', () => {
4747
.spyOn(console, 'error')
4848
.mockImplementation(() => {});
4949

50-
await findAndPublishAllBumpedPackages();
50+
await publishUpdatedPackages();
5151

5252
expect(consoleError.mock.calls).toMatchInlineSnapshot(`
5353
Array [
@@ -67,7 +67,7 @@ describe('findAndPublishAllBumpedPackages', () => {
6767
});
6868
const consoleLog = jest.spyOn(console, 'log').mockImplementation(() => {});
6969

70-
await findAndPublishAllBumpedPackages();
70+
await publishUpdatedPackages();
7171

7272
expect(consoleLog.mock.calls).toMatchInlineSnapshot(`
7373
Array [
@@ -99,7 +99,7 @@ describe('findAndPublishAllBumpedPackages', () => {
9999
json: () => Promise.resolve({versions: {}}),
100100
});
101101

102-
await expect(findAndPublishAllBumpedPackages()).rejects.toThrow(
102+
await expect(publishUpdatedPackages()).rejects.toThrow(
103103
`Package version expected to be 0.x.x, but received ${mockedPackageNewVersion}`,
104104
);
105105
});
@@ -144,7 +144,7 @@ describe('findAndPublishAllBumpedPackages', () => {
144144

145145
const consoleLog = jest.spyOn(console, 'log').mockImplementation(() => {});
146146

147-
await findAndPublishAllBumpedPackages();
147+
await publishUpdatedPackages();
148148

149149
expect(consoleLog.mock.calls.flat().join('\n')).toMatchInlineSnapshot(`
150150
"Discovering updated packages
@@ -217,7 +217,7 @@ describe('findAndPublishAllBumpedPackages', () => {
217217
.spyOn(console, 'error')
218218
.mockImplementation(() => {});
219219

220-
await findAndPublishAllBumpedPackages();
220+
await publishUpdatedPackages();
221221

222222
expect(consoleError.mock.calls.flat().join('\n')).toMatchInlineSnapshot(`
223223
"Failed to publish @react-native/package-b. npm publish exited with code 1:
@@ -258,7 +258,7 @@ describe('findAndPublishAllBumpedPackages', () => {
258258
.spyOn(console, 'log')
259259
.mockImplementation(() => {});
260260

261-
await findAndPublishAllBumpedPackages();
261+
await publishUpdatedPackages();
262262

263263
expect(consoleLog).toHaveBeenLastCalledWith('--- Retrying once! ---');
264264
expect(process.exitCode).toBe(1);

scripts/monorepo/find-and-publish-all-bumped-packages.js renamed to scripts/releases-ci/publish-updated-packages.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,39 @@
99
* @oncall react_native
1010
*/
1111

12+
const {PUBLISH_PACKAGES_TAG} = require('../monorepo/constants');
1213
const {publishPackage} = require('../npm-utils');
1314
const {getPackages} = require('../releases/utils/monorepo');
14-
const {PUBLISH_PACKAGES_TAG} = require('./constants');
15+
const {parseArgs} = require('@pkgjs/parseargs');
1516
const {execSync} = require('child_process');
1617

1718
const NPM_CONFIG_OTP = process.env.NPM_CONFIG_OTP;
1819

19-
async function findAndPublishAllBumpedPackages() {
20+
const config = {
21+
options: {
22+
help: {type: 'boolean'},
23+
},
24+
};
25+
26+
async function main() {
27+
const {
28+
values: {help},
29+
} = parseArgs(config);
30+
31+
if (help) {
32+
console.log(`
33+
Usage: node ./scripts/releases/publish-updated-packages.js
34+
35+
Publishes all updated packages (excluding react-native) to npm. This script
36+
is intended to run from a CI workflow.
37+
`);
38+
return;
39+
}
40+
41+
await publishUpdatedPackages();
42+
}
43+
44+
async function publishUpdatedPackages() {
2045
let commitMessage;
2146

2247
try {
@@ -130,10 +155,10 @@ function runPublish(
130155

131156
if (require.main === module) {
132157
// eslint-disable-next-line no-void
133-
void findAndPublishAllBumpedPackages();
158+
void main();
134159
}
135160

136161
module.exports = {
137-
findAndPublishAllBumpedPackages,
138162
getTagsFromCommitMessage,
163+
publishUpdatedPackages,
139164
};

0 commit comments

Comments
 (0)