Rename and document monorepo publish script (#42989)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42989

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D53607805

fbshipit-source-id: 8bbf82c02b54b20404de834800ae49d3fa43baee
This commit is contained in:
Alex Hunt
2024-02-14 02:57:36 -08:00
committed by Facebook GitHub Bot
parent 6a4d011c6b
commit a68ae2e2cc
4 changed files with 45 additions and 16 deletions
+1 -1
View File
@@ -1315,4 +1315,4 @@ jobs:
command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
- run:
name: Find and publish all bumped packages
command: node ./scripts/monorepo/find-and-publish-all-bumped-packages.js
command: node ./scripts/releases-ci/publish-updated-packages.js
+6 -2
View File
@@ -6,10 +6,14 @@ CI-only release scripts — intended to run from a CI workflow (CircleCI or GitH
For information on command arguments, run `node <command> --help`.
### `prepare-package-for-release.js`
### `prepare-package-for-release`
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.
### `publish-npm.js`
### `publish-npm`
Prepares release artifacts and publishes the `react-native` package to npm.
### `publish-updated-packages`
Publishes all updated packages (excluding `react-native`) to npm. Triggered when a commit on a release branch contains `#publish-packages-to-npm`.
@@ -10,9 +10,9 @@
*/
const {
findAndPublishAllBumpedPackages,
getTagsFromCommitMessage,
} = require('../find-and-publish-all-bumped-packages');
publishUpdatedPackages,
} = require('../publish-updated-packages');
const getPackagesMock = jest.fn();
const execSync = jest.fn();
@@ -30,7 +30,7 @@ global.fetch = fetchMock;
const BUMP_COMMIT_MESSAGE =
'bumped packages versions\n\n#publish-packages-to-npm';
describe('findAndPublishAllBumpedPackages', () => {
describe('publishUpdatedPackages', () => {
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
jest.resetAllMocks();
@@ -47,7 +47,7 @@ describe('findAndPublishAllBumpedPackages', () => {
.spyOn(console, 'error')
.mockImplementation(() => {});
await findAndPublishAllBumpedPackages();
await publishUpdatedPackages();
expect(consoleError.mock.calls).toMatchInlineSnapshot(`
Array [
@@ -67,7 +67,7 @@ describe('findAndPublishAllBumpedPackages', () => {
});
const consoleLog = jest.spyOn(console, 'log').mockImplementation(() => {});
await findAndPublishAllBumpedPackages();
await publishUpdatedPackages();
expect(consoleLog.mock.calls).toMatchInlineSnapshot(`
Array [
@@ -99,7 +99,7 @@ describe('findAndPublishAllBumpedPackages', () => {
json: () => Promise.resolve({versions: {}}),
});
await expect(findAndPublishAllBumpedPackages()).rejects.toThrow(
await expect(publishUpdatedPackages()).rejects.toThrow(
`Package version expected to be 0.x.x, but received ${mockedPackageNewVersion}`,
);
});
@@ -144,7 +144,7 @@ describe('findAndPublishAllBumpedPackages', () => {
const consoleLog = jest.spyOn(console, 'log').mockImplementation(() => {});
await findAndPublishAllBumpedPackages();
await publishUpdatedPackages();
expect(consoleLog.mock.calls.flat().join('\n')).toMatchInlineSnapshot(`
"Discovering updated packages
@@ -217,7 +217,7 @@ describe('findAndPublishAllBumpedPackages', () => {
.spyOn(console, 'error')
.mockImplementation(() => {});
await findAndPublishAllBumpedPackages();
await publishUpdatedPackages();
expect(consoleError.mock.calls.flat().join('\n')).toMatchInlineSnapshot(`
"Failed to publish @react-native/package-b. npm publish exited with code 1:
@@ -258,7 +258,7 @@ describe('findAndPublishAllBumpedPackages', () => {
.spyOn(console, 'log')
.mockImplementation(() => {});
await findAndPublishAllBumpedPackages();
await publishUpdatedPackages();
expect(consoleLog).toHaveBeenLastCalledWith('--- Retrying once! ---');
expect(process.exitCode).toBe(1);
@@ -9,14 +9,39 @@
* @oncall react_native
*/
const {PUBLISH_PACKAGES_TAG} = require('../monorepo/constants');
const {publishPackage} = require('../npm-utils');
const {getPackages} = require('../releases/utils/monorepo');
const {PUBLISH_PACKAGES_TAG} = require('./constants');
const {parseArgs} = require('@pkgjs/parseargs');
const {execSync} = require('child_process');
const NPM_CONFIG_OTP = process.env.NPM_CONFIG_OTP;
async function findAndPublishAllBumpedPackages() {
const config = {
options: {
help: {type: 'boolean'},
},
};
async function main() {
const {
values: {help},
} = parseArgs(config);
if (help) {
console.log(`
Usage: node ./scripts/releases/publish-updated-packages.js
Publishes all updated packages (excluding react-native) to npm. This script
is intended to run from a CI workflow.
`);
return;
}
await publishUpdatedPackages();
}
async function publishUpdatedPackages() {
let commitMessage;
try {
@@ -130,10 +155,10 @@ function runPublish(
if (require.main === module) {
// eslint-disable-next-line no-void
void findAndPublishAllBumpedPackages();
void main();
}
module.exports = {
findAndPublishAllBumpedPackages,
getTagsFromCommitMessage,
publishUpdatedPackages,
};