From 6380f6fd21caf5630f652a4b63c47dc258919d24 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 14 Feb 2024 02:25:26 -0800 Subject: [PATCH] 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: 3955e5fec09e77b653fa2a58630539096ecc0919 --- .circleci/configurations/jobs.yml | 2 +- scripts/releases-ci/README.md | 8 +++-- .../publish-updated-packages-test.js} | 18 +++++----- .../publish-updated-packages.js} | 33 ++++++++++++++++--- 4 files changed, 45 insertions(+), 16 deletions(-) rename scripts/{monorepo/__tests__/find-and-publish-all-bumped-packages-test.js => releases-ci/__tests__/publish-updated-packages-test.js} (94%) rename scripts/{monorepo/find-and-publish-all-bumped-packages.js => releases-ci/publish-updated-packages.js} (84%) diff --git a/.circleci/configurations/jobs.yml b/.circleci/configurations/jobs.yml index 603e35d1066309..974d17a7f25446 100644 --- a/.circleci/configurations/jobs.yml +++ b/.circleci/configurations/jobs.yml @@ -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 diff --git a/scripts/releases-ci/README.md b/scripts/releases-ci/README.md index 1900b92954e64d..d55f1e19c1f91c 100644 --- a/scripts/releases-ci/README.md +++ b/scripts/releases-ci/README.md @@ -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 --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`. diff --git a/scripts/monorepo/__tests__/find-and-publish-all-bumped-packages-test.js b/scripts/releases-ci/__tests__/publish-updated-packages-test.js similarity index 94% rename from scripts/monorepo/__tests__/find-and-publish-all-bumped-packages-test.js rename to scripts/releases-ci/__tests__/publish-updated-packages-test.js index ab961bde30d736..9f7845ba93e10d 100644 --- a/scripts/monorepo/__tests__/find-and-publish-all-bumped-packages-test.js +++ b/scripts/releases-ci/__tests__/publish-updated-packages-test.js @@ -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); diff --git a/scripts/monorepo/find-and-publish-all-bumped-packages.js b/scripts/releases-ci/publish-updated-packages.js similarity index 84% rename from scripts/monorepo/find-and-publish-all-bumped-packages.js rename to scripts/releases-ci/publish-updated-packages.js index 55230030c5f108..f20a7d5b45bf95 100644 --- a/scripts/monorepo/find-and-publish-all-bumped-packages.js +++ b/scripts/releases-ci/publish-updated-packages.js @@ -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, };