Skip to content

Commit

Permalink
Delete validation in set-rn-version (#37814)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37814

Changelog: [Internal] - deleting file validation, do we need this?

Reviewed By: NickGerleman

Differential Revision: D46584771

fbshipit-source-id: 69a8853872b2b1582318a2e65d9919e2b50b2475
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Jun 14, 2023
1 parent 31eb235 commit be34852
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 88 deletions.
46 changes: 1 addition & 45 deletions scripts/__tests__/set-rn-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @format
*/

const execMock = jest.fn();
const echoMock = jest.fn();
const catMock = jest.fn();
const sedMock = jest.fn();
Expand All @@ -16,23 +15,15 @@ const updateTemplatePackageMock = jest.fn();

jest
.mock('shelljs', () => ({
exec: execMock,
echo: echoMock,
cat: catMock,
sed: sedMock,
}))
.mock('./../update-template-package', () => updateTemplatePackageMock)
.mock('./../scm-utils', () => ({
saveFiles: jest.fn(),
}))
.mock('path', () => ({
join: () => '../packages/react-native',
}))
.mock('fs', () => ({
writeFileSync: writeFileSyncMock,
mkdtempSync: () => './rn-set-version/',
}))
.mock('os');
}));

const setReactNativeVersion = require('../set-rn-version');

Expand All @@ -58,7 +49,6 @@ describe('set-rn-version', () => {
}
});

execMock.mockReturnValueOnce({stdout: 'line1\nline2\nline3\n'});
sedMock.mockReturnValueOnce({code: 0});

const version = '0.81.0-nightly-29282302-abcd1234';
Expand Down Expand Up @@ -115,7 +105,6 @@ describe('set-rn-version', () => {
return 'exports.version = {major: ${major}, minor: ${minor}, patch: ${patch}, prerelease: ${prerelease}}';
});

execMock.mockReturnValueOnce({stdout: 'line1\nline2\nline3\n'});
sedMock.mockReturnValueOnce({code: 0});

const version = '0.81.0';
Expand Down Expand Up @@ -144,38 +133,5 @@ describe('set-rn-version', () => {
expect(updateTemplatePackageMock).toHaveBeenCalledWith({
'react-native': version,
});
expect(execMock.mock.calls[0][0]).toBe(
`diff -r ./rn-set-version/ . | grep '^[>]' | grep -c ${version} `,
);
});

it('should fail validation', () => {
catMock.mockReturnValue('{}');

execMock.mockReturnValueOnce({stdout: 'line1\nline2\n'});
sedMock.mockReturnValueOnce({code: 0});
const filesToValidate = [
'packages/react-native/package.json',
'packages/react-native/template/package.json',
];

const version = '0.81.0';
setReactNativeVersion(version, null, 'release');

expect(echoMock).toHaveBeenNthCalledWith(
1,
'The tmp versioning folder is ./rn-set-version/',
);

expect(echoMock).toHaveBeenNthCalledWith(2, 'WARNING:');

expect(echoMock.mock.calls[2][0]).toBe(
`Failed to update all the files: [${filesToValidate.join(
', ',
)}] must have versions in them`,
);
expect(echoMock.mock.calls[3][0]).toBe(
`These files already had version ${version} set.`,
);
});
});
44 changes: 1 addition & 43 deletions scripts/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
'use strict';

const fs = require('fs');
const os = require('os');
const path = require('path');
const {cat, echo, exec, exit, sed} = require('shelljs');
const {cat, echo, exit, sed} = require('shelljs');
const yargs = require('yargs');
const {parseVersion, validateBuildType} = require('./version-utils');
const {saveFiles} = require('./scm-utils');
const updateTemplatePackage = require('./update-template-package');
const {applyPackageVersions} = require('./npm-utils');

Expand Down Expand Up @@ -152,23 +149,6 @@ function setReactNativeVersion(argVersion, dependencyVersions, buildType) {

const version = parseVersion(argVersion, buildType);

// Create tmp folder for copies of files to verify files have changed
const filesToValidate = [
'packages/react-native/package.json',
'packages/react-native/template/package.json',
];
const tmpVersioningFolder = fs.mkdtempSync(
path.join(os.tmpdir(), 'rn-set-version'),
);
echo(`The tmp versioning folder is ${tmpVersioningFolder}`);
saveFiles(
[
'packages/react-native/package.json',
'packages/react-native/template/package.json',
],
tmpVersioningFolder,
);

setSource(version);
setPackage(version, dependencyVersions);

Expand All @@ -179,28 +159,6 @@ function setReactNativeVersion(argVersion, dependencyVersions, buildType) {
updateTemplatePackage(templateDependencyVersions);

setGradle(version);

// Validate changes
// We just do a git diff and check how many times version is added across files
const numberOfChangedLinesWithNewVersion = exec(
`diff -r ${tmpVersioningFolder} . | grep '^[>]' | grep -c ${version.version} `,
{silent: true},
).stdout.trim();

if (+numberOfChangedLinesWithNewVersion !== filesToValidate.length) {
// TODO: the logic that checks whether all the changes have been applied
// is missing several files. For example, it is not checking Ruby version nor that
// the Objecive-C files, the codegen and other files are properly updated.
// We are going to work on this in another PR.
echo('WARNING:');
echo(
`Failed to update all the files: [${filesToValidate.join(
', ',
)}] must have versions in them`,
);
echo(`These files already had version ${version.version} set.`);
}

return;
}

Expand Down

0 comments on commit be34852

Please sign in to comment.