Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN [refactor]: bump and realign package versions by running a single … #36573

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -40,8 +40,7 @@
"test-ios": "./scripts/objc-test.sh test",
"test-typescript": "dtslint packages/react-native/types",
"test-typescript-offline": "dtslint --localTs node_modules/typescript/lib packages/react-native/types",
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages",
"align-package-versions": "node ./scripts/monorepo/align-package-versions.js"
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages"
},
"workspaces": [
"packages/*"
Expand Down
27 changes: 1 addition & 26 deletions scripts/monorepo/align-package-versions.js
Expand Up @@ -7,11 +7,9 @@
* @format
*/

const {spawnSync} = require('child_process');
const {writeFileSync, readFileSync} = require('fs');
const path = require('path');

const checkForGitChanges = require('./check-for-git-changes');
const forEachPackage = require('./for-each-package');

const ROOT_LOCATION = path.join(__dirname, '..', '..');
Expand Down Expand Up @@ -95,14 +93,6 @@ const checkIfShouldUpdateDependencyPackageVersion = (
};

const alignPackageVersions = () => {
if (checkForGitChanges()) {
console.log(
'\u274c Found uncommitted changes. Please commit or stash them before running this script',
);

process.exit(1);
}

forEachPackage((_, __, packageManifest) => {
checkIfShouldUpdateDependencyPackageVersion(
ROOT_LOCATION,
Expand All @@ -126,21 +116,6 @@ const alignPackageVersions = () => {
{includeReactNative: true},
);
});

if (!checkForGitChanges()) {
console.log(
'\u2705 There were no changes. Every consumer package uses the actual version of dependency package.',
);
return;
}

console.log('Running yarn to update lock file...');
spawnSync('yarn', ['install'], {
cwd: ROOT_LOCATION,
shell: true,
stdio: 'inherit',
encoding: 'utf-8',
});
};

alignPackageVersions();
module.exports = alignPackageVersions;
141 changes: 73 additions & 68 deletions scripts/monorepo/bump-all-updated-packages/index.js
Expand Up @@ -14,6 +14,7 @@ const path = require('path');
const {echo, exec, exit} = require('shelljs');
const yargs = require('yargs');

const alignPackageVersions = require('../align-package-versions');
const {
PUBLISH_PACKAGES_TAG,
GENERIC_COMMIT_MESSAGE,
Expand Down Expand Up @@ -157,76 +158,80 @@ const main = async () => {
.then(() => echo());
}

if (checkForGitChanges()) {
await inquirer
.prompt([
{
type: 'list',
name: 'commitChoice',
message: 'Do you want to submit a commit with these changes?',
choices: [
{
name: 'Yes, with generic message',
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
},
{
name: 'Yes, with custom message',
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
},
{
name: 'No',
value: NO_COMMIT_CHOICE,
},
],
},
])
.then(({commitChoice}) => {
switch (commitChoice) {
case NO_COMMIT_CHOICE: {
echo('Not submitting a commit, but keeping all changes');

break;
}

case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
cwd: ROOT_LOCATION,
silent: true,
});

break;
}

case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
// exec from shelljs currently does not support interactive input
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});

const enteredCommitMessage = exec(
'git log -n 1 --format=format:%B',
{
cwd: ROOT_LOCATION,
silent: true,
},
).stdout.trim();
const commitMessageWithTag =
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;

exec(`git commit --amend -m "${commitMessageWithTag}"`, {
cwd: ROOT_LOCATION,
silent: true,
});

break;
}

default:
throw new Error('');
}
})
.then(() => echo());
if (!checkForGitChanges()) {
echo('No changes have been made. Finishing the process...');
exit(0);
}

echo('Aligning new versions across monorepo...');
alignPackageVersions();
echo(chalk.green('Done!\n'));

await inquirer
.prompt([
{
type: 'list',
name: 'commitChoice',
message: 'Do you want to submit a commit with these changes?',
choices: [
{
name: 'Yes, with generic message',
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
},
{
name: 'Yes, with custom message',
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
},
{
name: 'No',
value: NO_COMMIT_CHOICE,
},
],
},
])
.then(({commitChoice}) => {
switch (commitChoice) {
case NO_COMMIT_CHOICE: {
echo('Not submitting a commit, but keeping all changes');

break;
}

case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
cwd: ROOT_LOCATION,
silent: true,
});

break;
}

case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
// exec from shelljs currently does not support interactive input
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});

const enteredCommitMessage = exec('git log -n 1 --format=format:%B', {
cwd: ROOT_LOCATION,
silent: true,
}).stdout.trim();
const commitMessageWithTag =
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;

exec(`git commit --amend -m "${commitMessageWithTag}"`, {
cwd: ROOT_LOCATION,
silent: true,
});

break;
}

default:
throw new Error('');
}
})
.then(() => echo());

echo(chalk.green('Successfully finished the process of bumping packages'));
exit(0);
};
Expand Down