Do not depend on an ENV variable when publishing and setting the RN version (#34746)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34746 The changes made in https://github.com/facebook/react-native/pull/34694 introduced the need to have the env variable TMP_PUBLISH_DIR for the publishing and set-rn-version scripts to work. This break any usage of set-rn-version when the env variable is not set upfront. With this change, we are creating a temp folder in the scope that requires it (e.g. set-rn-version.js) and then passing the path to the save/revert functions. ## Changelog [Internal] [Added] - Do not depend on an ENV variable when publishing and setting the RN version. Reviewed By: cipolleschi Differential Revision: D39683565 fbshipit-source-id: 21d85d1c16c4cb7324636ceb5eba626ff8cbb775
This commit is contained in:
Родитель
34db2d4e93
Коммит
10e47b891a
|
@ -11,7 +11,6 @@ const {isTaggedLatest, saveFiles, revertFiles} = require('../scm-utils');
|
||||||
|
|
||||||
let execResult = null;
|
let execResult = null;
|
||||||
const cpMock = jest.fn();
|
const cpMock = jest.fn();
|
||||||
// const existsSyncMock = jest.fn();
|
|
||||||
const mkdirpSyncMock = jest.fn();
|
const mkdirpSyncMock = jest.fn();
|
||||||
jest
|
jest
|
||||||
.mock('shelljs', () => ({
|
.mock('shelljs', () => ({
|
||||||
|
@ -63,9 +62,9 @@ describe('scm-utils', () => {
|
||||||
|
|
||||||
describe('saveFiles', () => {
|
describe('saveFiles', () => {
|
||||||
it('it should save files in the temp folder', () => {
|
it('it should save files in the temp folder', () => {
|
||||||
process.env.TMP_PUBLISH_DIR = '/tmp';
|
const tmpFolder = '/tmp';
|
||||||
saveFiles('package.json', 'android/package.json');
|
saveFiles(['package.json', 'android/package.json'], tmpFolder);
|
||||||
expect(mkdirpSyncMock).toHaveBeenCalledWith(`/tmp/android`);
|
expect(mkdirpSyncMock).toHaveBeenCalledWith(`${tmpFolder}/android`);
|
||||||
expect(cpMock).toHaveBeenNthCalledWith(
|
expect(cpMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'package.json',
|
'package.json',
|
||||||
|
@ -74,27 +73,25 @@ describe('scm-utils', () => {
|
||||||
expect(cpMock).toHaveBeenNthCalledWith(
|
expect(cpMock).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
'android/package.json',
|
'android/package.json',
|
||||||
'/tmp/android/package.json',
|
`${tmpFolder}/android/package.json`,
|
||||||
);
|
);
|
||||||
process.env.TMP_PUBLISH_DIR = '';
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('revertFiles', () => {
|
describe('revertFiles', () => {
|
||||||
it('it should revert files from the temp folder', () => {
|
it('it should revert files from the temp folder', () => {
|
||||||
process.env.TMP_PUBLISH_DIR = '/tmp';
|
const tmpFolder = '/tmp';
|
||||||
revertFiles('package.json', 'android/package.json');
|
revertFiles(['package.json', 'android/package.json'], tmpFolder);
|
||||||
expect(cpMock).toHaveBeenNthCalledWith(
|
expect(cpMock).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
'/tmp/package.json',
|
`${tmpFolder}/package.json`,
|
||||||
'package.json',
|
'package.json',
|
||||||
);
|
);
|
||||||
expect(cpMock).toHaveBeenNthCalledWith(
|
expect(cpMock).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
'/tmp/android/package.json',
|
`${tmpFolder}/android/package.json`,
|
||||||
'android/package.json',
|
'android/package.json',
|
||||||
);
|
);
|
||||||
process.env.TMP_PUBLISH_DIR = '';
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,10 +47,10 @@ const yargs = require('yargs');
|
||||||
|
|
||||||
const buildTag = process.env.CIRCLE_TAG;
|
const buildTag = process.env.CIRCLE_TAG;
|
||||||
const otp = process.env.NPM_CONFIG_OTP;
|
const otp = process.env.NPM_CONFIG_OTP;
|
||||||
process.env.TMP_PUBLISH_DIR = fs.mkdtempSync(
|
const tmpPublishingFolder = fs.mkdtempSync(
|
||||||
path.join(os.tmpdir(), 'rn-publish-'),
|
path.join(os.tmpdir(), 'rn-publish-'),
|
||||||
);
|
);
|
||||||
echo(`The temp folder is ${process.env.TMP_PUBLISH_DIR}`);
|
echo(`The temp publishing folder is ${tmpPublishingFolder}`);
|
||||||
|
|
||||||
const argv = yargs
|
const argv = yargs
|
||||||
.option('n', {
|
.option('n', {
|
||||||
|
@ -88,7 +88,7 @@ const filesToSaveAndRestore = [
|
||||||
'ReactCommon/cxxreact/ReactNativeVersion.h',
|
'ReactCommon/cxxreact/ReactNativeVersion.h',
|
||||||
];
|
];
|
||||||
|
|
||||||
saveFiles(...filesToSaveAndRestore);
|
saveFiles(filesToSaveAndRestore, tmpPublishingFolder);
|
||||||
|
|
||||||
if (includeHermes) {
|
if (includeHermes) {
|
||||||
const HERMES_INSTALL_LOCATION = 'sdks';
|
const HERMES_INSTALL_LOCATION = 'sdks';
|
||||||
|
@ -210,7 +210,7 @@ if (exec('./gradlew :ReactAndroid:hermes-engine:installArchives').code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// undo uncommenting javadoc setting
|
// undo uncommenting javadoc setting
|
||||||
revertFiles('ReactAndroid/gradle.properties');
|
revertFiles(['ReactAndroid/gradle.properties'], tmpPublishingFolder);
|
||||||
|
|
||||||
echo('Generated artifacts for Maven');
|
echo('Generated artifacts for Maven');
|
||||||
|
|
||||||
|
|
|
@ -60,20 +60,20 @@ function getCurrentCommit() {
|
||||||
: 'TEMP';
|
: 'TEMP';
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFiles(...filePaths) {
|
function saveFiles(filePaths, tmpFolder) {
|
||||||
for (const filePath of filePaths) {
|
for (const filePath of filePaths) {
|
||||||
const dirName = path.dirname(filePath);
|
const dirName = path.dirname(filePath);
|
||||||
if (dirName !== '.') {
|
if (dirName !== '.') {
|
||||||
const destFolder = `${process.env.TMP_PUBLISH_DIR}/${dirName}`;
|
const destFolder = `${tmpFolder}/${dirName}`;
|
||||||
mkdirp.sync(destFolder);
|
mkdirp.sync(destFolder);
|
||||||
}
|
}
|
||||||
cp(filePath, `${process.env.TMP_PUBLISH_DIR}/${filePath}`);
|
cp(filePath, `${tmpFolder}/${filePath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function revertFiles(...filePaths) {
|
function revertFiles(filePaths, tmpFolder) {
|
||||||
for (const filePath of filePaths) {
|
for (const filePath of filePaths) {
|
||||||
const absoluteTmpPath = `${process.env.TMP_PUBLISH_DIR}/${filePath}`;
|
const absoluteTmpPath = `${tmpFolder}/${filePath}`;
|
||||||
if (fs.existsSync(absoluteTmpPath)) {
|
if (fs.existsSync(absoluteTmpPath)) {
|
||||||
cp(absoluteTmpPath, filePath);
|
cp(absoluteTmpPath, filePath);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,11 +17,18 @@
|
||||||
* * Creates a gemfile
|
* * Creates a gemfile
|
||||||
*/
|
*/
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
const {cat, echo, exec, exit, sed} = require('shelljs');
|
const {cat, echo, exec, exit, sed} = require('shelljs');
|
||||||
const yargs = require('yargs');
|
const yargs = require('yargs');
|
||||||
const {parseVersion} = require('./version-utils');
|
const {parseVersion} = require('./version-utils');
|
||||||
const {saveFiles} = require('./scm-utils');
|
const {saveFiles} = require('./scm-utils');
|
||||||
|
|
||||||
|
const tmpVersioningFolder = fs.mkdtempSync(
|
||||||
|
path.join(os.tmpdir(), 'rn-set-version'),
|
||||||
|
);
|
||||||
|
echo(`The temp versioning folder is ${tmpVersioningFolder}`);
|
||||||
|
|
||||||
let argv = yargs.option('v', {
|
let argv = yargs.option('v', {
|
||||||
alias: 'to-version',
|
alias: 'to-version',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -45,7 +52,7 @@ try {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFiles('package.json', 'template/package.json');
|
saveFiles(['package.json', 'template/package.json'], tmpVersioningFolder);
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
|
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
|
||||||
|
@ -119,7 +126,7 @@ packageJson.dependencies = {
|
||||||
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8');
|
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8');
|
||||||
|
|
||||||
// Change ReactAndroid/gradle.properties
|
// Change ReactAndroid/gradle.properties
|
||||||
saveFiles('ReactAndroid/gradle.properties');
|
saveFiles(['ReactAndroid/gradle.properties'], tmpVersioningFolder);
|
||||||
if (
|
if (
|
||||||
sed(
|
sed(
|
||||||
'-i',
|
'-i',
|
||||||
|
@ -149,7 +156,7 @@ const filesToValidate = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const numberOfChangedLinesWithNewVersion = exec(
|
const numberOfChangedLinesWithNewVersion = exec(
|
||||||
`diff -r ${process.env.TMP_PUBLISH_DIR} . | grep '^[>]' | grep -c ${version} `,
|
`diff -r ${tmpVersioningFolder} . | grep '^[>]' | grep -c ${version} `,
|
||||||
{silent: true},
|
{silent: true},
|
||||||
).stdout.trim();
|
).stdout.trim();
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче