Skip to content

Commit

Permalink
Use set-version in nightly publishes
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal] - Update nightly flow to use set-version

This change first fixes `set-version` to update the `packages/react-native` native source and build files (as `set-rn-version` does) -- this was an oversight but not an issue as `set-version` isn't actually used anywhere right now.

Then, this change updates `publish-npm` script to use `set-version` only for nightlies -- as `dry-run` and `pre-alpha` are non-functioning build types right now.

This does not change the flow of build-type `'release'` -- that will still use `set-rn-version` via CircleCI ([job](https://fburl.com/code/6xo3ijwg), [script](https://fburl.com/code/bo8np0tb))  We will eventually replace that too but that will be later.

The reason for this change today is to delete the nightly-specific `get-and-update-packages` script to eventually conform all release flows to use this. 

Secondly, we want to use this script to bump everything on `main` after we make an rc.0 -- to replace `yarn bump-all-updated-packages --release-branch-cutoff` as detailed in this step: https://reactnative.dev/contributing/release-branch-cut-and-rc0#12-bump-minor-version-of-all-monorepo-packages-in-main

Differential Revision: D53463414
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Feb 6, 2024
1 parent bc3fe0d commit 9f9fad7
Show file tree
Hide file tree
Showing 11 changed files with 862 additions and 69 deletions.
34 changes: 16 additions & 18 deletions scripts/releases-ci/__tests__/publish-npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const echoMock = jest.fn();
const exitMock = jest.fn();
const consoleErrorMock = jest.fn();
const isTaggedLatestMock = jest.fn();
const setReactNativeVersionMock = jest.fn();
const setVersionMock = jest.fn();
const publishAndroidArtifactsToMavenMock = jest.fn();
const removeNewArchFlags = jest.fn();
const env = process.env;
Expand All @@ -29,18 +29,15 @@ jest
getCurrentCommit: () => 'currentco_mmit',
isTaggedLatest: isTaggedLatestMock,
}))
.mock('path', () => ({
...jest.requireActual('path'),
join: () => '../../packages/react-native',
.mock('fs', () => ({
...jest.requireActual('fs'),
writeFileSync: jest.fn(),
}))
.mock('fs')
.mock('../../releases/utils/release-utils', () => ({
generateAndroidArtifacts: jest.fn(),
publishAndroidArtifactsToMaven: publishAndroidArtifactsToMavenMock,
}))
.mock('../../releases/set-rn-version', () => ({
setReactNativeVersion: setReactNativeVersionMock,
}))
.mock('../../releases/set-version', () => setVersionMock)
.mock('../../monorepo/get-and-update-packages')
.mock('../../releases/remove-new-arch-flags', () => ({
removeNewArchFlags,
Expand All @@ -49,6 +46,10 @@ jest
const date = new Date('2023-04-20T23:52:39.543Z');

const {publishNpm} = require('../publish-npm');
const path = require('path');

const REPO_ROOT = path.resolve(__filename, '../../../..');

let consoleError;

describe('publish-npm', () => {
Expand Down Expand Up @@ -88,11 +89,7 @@ describe('publish-npm', () => {
expect(echoMock).toHaveBeenCalledWith(
'Skipping `npm publish` because --dry-run is set.',
);
expect(setReactNativeVersionMock).toBeCalledWith(
'1000.0.0-currentco',
null,
'dry-run',
);
expect(setVersionMock).toBeCalledWith('1000.0.0-currentco');
});
});

Expand All @@ -106,6 +103,7 @@ describe('publish-npm', () => {
await publishNpm('nightly');

expect(removeNewArchFlags).not.toHaveBeenCalled();
expect(setVersionMock).toBeCalledWith(expectedVersion);
expect(publishAndroidArtifactsToMavenMock).toHaveBeenCalledWith(
expectedVersion,
'nightly',
Expand All @@ -123,7 +121,7 @@ describe('publish-npm', () => {
it('should fail to set version', async () => {
execMock.mockReturnValueOnce({stdout: '0.81.0-rc.1\n', code: 0});
const expectedVersion = '0.82.0-nightly-20230420-currentco';
setReactNativeVersionMock.mockImplementation(() => {
setVersionMock.mockImplementation(() => {
throw new Error('something went wrong');
});

Expand Down Expand Up @@ -166,7 +164,7 @@ describe('publish-npm', () => {
);
expect(execMock).toHaveBeenCalledWith(
`npm publish --tag 0.81-stable --otp otp`,
{cwd: '../../packages/react-native'},
{cwd: path.join(REPO_ROOT, 'packages/react-native')},
);
expect(echoMock).toHaveBeenCalledWith(
`Published to npm ${expectedVersion}`,
Expand All @@ -191,7 +189,7 @@ describe('publish-npm', () => {
);
expect(execMock).toHaveBeenCalledWith(
`npm publish --tag latest --otp ${process.env.NPM_CONFIG_OTP}`,
{cwd: '../../packages/react-native'},
{cwd: path.join(REPO_ROOT, 'packages/react-native')},
);
expect(echoMock).toHaveBeenCalledWith(
`Published to npm ${expectedVersion}`,
Expand All @@ -216,7 +214,7 @@ describe('publish-npm', () => {
);
expect(execMock).toHaveBeenCalledWith(
`npm publish --tag latest --otp ${process.env.NPM_CONFIG_OTP}`,
{cwd: '../../packages/react-native'},
{cwd: path.join(REPO_ROOT, 'packages/react-native')},
);
expect(echoMock).toHaveBeenCalledWith(`Failed to publish package to npm`);
expect(exitMock).toHaveBeenCalledWith(1);
Expand All @@ -239,7 +237,7 @@ describe('publish-npm', () => {
);
expect(execMock).toHaveBeenCalledWith(
`npm publish --tag next --otp ${process.env.NPM_CONFIG_OTP}`,
{cwd: '../../packages/react-native'},
{cwd: path.join(REPO_ROOT, 'packages/react-native')},
);
expect(echoMock).toHaveBeenCalledWith(
`Published to npm ${expectedVersion}`,
Expand Down
15 changes: 4 additions & 11 deletions scripts/releases-ci/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import type {BuildType} from '../releases/utils/version-utils';
*/

const getAndUpdatePackages = require('../monorepo/get-and-update-packages');
const {getNpmInfo, publishPackage} = require('../npm-utils');
const {removeNewArchFlags} = require('../releases/remove-new-arch-flags');
const {setReactNativeVersion} = require('../releases/set-rn-version');
const setVersion = require('../releases/set-version');
const {
generateAndroidArtifacts,
publishAndroidArtifactsToMaven,
Expand Down Expand Up @@ -75,17 +74,11 @@ async function publishNpm(buildType /*: BuildType */) /*: Promise<void> */ {
}

// Here we update the react-native package and template package with the right versions
// For releases, CircleCI job `prepare_package_for_release` handles this
// For stable releases, CircleCI job `prepare_package_for_release` handles this
if (['dry-run', 'nightly', 'prealpha'].includes(buildType)) {
// Publish monorepo nightlies and prealphas if there are updates, returns the new version for each package
const monorepoVersions =
// $FlowFixMe[incompatible-call]
buildType === 'dry-run' ? null : getAndUpdatePackages(version, buildType);

// Update all monorepo packages (incl. react-native) to the same version and update every dependency
try {
// Update the react-native and template packages with the react-native version
// and nightly versions of monorepo deps
await setReactNativeVersion(version, monorepoVersions, buildType);
await setVersion(version);
} catch (e) {
console.error(`Failed to set version number to ${version}`);
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION_NAME=1000.0.0
Loading

0 comments on commit 9f9fad7

Please sign in to comment.