Skip to content

Commit 68cd44b

Browse files
authored
Merge pull request facebook#36573 from hoxyq/hoxyq/cherry-pick-ci-scripts-changes-to-0.72-stable
RN [refactor]: bump and realign package versions by running a single …
2 parents c5f18de + a469927 commit 68cd44b

File tree

3 files changed

+75
-96
lines changed

3 files changed

+75
-96
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"test-ios": "./scripts/objc-test.sh test",
4141
"test-typescript": "dtslint packages/react-native/types",
4242
"test-typescript-offline": "dtslint --localTs node_modules/typescript/lib packages/react-native/types",
43-
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages",
44-
"align-package-versions": "node ./scripts/monorepo/align-package-versions.js"
43+
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages"
4544
},
4645
"workspaces": [
4746
"packages/*"

scripts/monorepo/align-package-versions.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
* @format
88
*/
99

10-
const {spawnSync} = require('child_process');
1110
const {writeFileSync, readFileSync} = require('fs');
1211
const path = require('path');
1312

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

1715
const ROOT_LOCATION = path.join(__dirname, '..', '..');
@@ -95,14 +93,6 @@ const checkIfShouldUpdateDependencyPackageVersion = (
9593
};
9694

9795
const alignPackageVersions = () => {
98-
if (checkForGitChanges()) {
99-
console.log(
100-
'\u274c Found uncommitted changes. Please commit or stash them before running this script',
101-
);
102-
103-
process.exit(1);
104-
}
105-
10696
forEachPackage((_, __, packageManifest) => {
10797
checkIfShouldUpdateDependencyPackageVersion(
10898
ROOT_LOCATION,
@@ -126,21 +116,6 @@ const alignPackageVersions = () => {
126116
{includeReactNative: true},
127117
);
128118
});
129-
130-
if (!checkForGitChanges()) {
131-
console.log(
132-
'\u2705 There were no changes. Every consumer package uses the actual version of dependency package.',
133-
);
134-
return;
135-
}
136-
137-
console.log('Running yarn to update lock file...');
138-
spawnSync('yarn', ['install'], {
139-
cwd: ROOT_LOCATION,
140-
shell: true,
141-
stdio: 'inherit',
142-
encoding: 'utf-8',
143-
});
144119
};
145120

146-
alignPackageVersions();
121+
module.exports = alignPackageVersions;

scripts/monorepo/bump-all-updated-packages/index.js

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const path = require('path');
1414
const {echo, exec, exit} = require('shelljs');
1515
const yargs = require('yargs');
1616

17+
const alignPackageVersions = require('../align-package-versions');
1718
const {
1819
PUBLISH_PACKAGES_TAG,
1920
GENERIC_COMMIT_MESSAGE,
@@ -157,76 +158,80 @@ const main = async () => {
157158
.then(() => echo());
158159
}
159160

160-
if (checkForGitChanges()) {
161-
await inquirer
162-
.prompt([
163-
{
164-
type: 'list',
165-
name: 'commitChoice',
166-
message: 'Do you want to submit a commit with these changes?',
167-
choices: [
168-
{
169-
name: 'Yes, with generic message',
170-
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
171-
},
172-
{
173-
name: 'Yes, with custom message',
174-
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
175-
},
176-
{
177-
name: 'No',
178-
value: NO_COMMIT_CHOICE,
179-
},
180-
],
181-
},
182-
])
183-
.then(({commitChoice}) => {
184-
switch (commitChoice) {
185-
case NO_COMMIT_CHOICE: {
186-
echo('Not submitting a commit, but keeping all changes');
187-
188-
break;
189-
}
190-
191-
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
192-
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
193-
cwd: ROOT_LOCATION,
194-
silent: true,
195-
});
196-
197-
break;
198-
}
199-
200-
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
201-
// exec from shelljs currently does not support interactive input
202-
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
203-
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
204-
205-
const enteredCommitMessage = exec(
206-
'git log -n 1 --format=format:%B',
207-
{
208-
cwd: ROOT_LOCATION,
209-
silent: true,
210-
},
211-
).stdout.trim();
212-
const commitMessageWithTag =
213-
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
214-
215-
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
216-
cwd: ROOT_LOCATION,
217-
silent: true,
218-
});
219-
220-
break;
221-
}
222-
223-
default:
224-
throw new Error('');
225-
}
226-
})
227-
.then(() => echo());
161+
if (!checkForGitChanges()) {
162+
echo('No changes have been made. Finishing the process...');
163+
exit(0);
228164
}
229165

166+
echo('Aligning new versions across monorepo...');
167+
alignPackageVersions();
168+
echo(chalk.green('Done!\n'));
169+
170+
await inquirer
171+
.prompt([
172+
{
173+
type: 'list',
174+
name: 'commitChoice',
175+
message: 'Do you want to submit a commit with these changes?',
176+
choices: [
177+
{
178+
name: 'Yes, with generic message',
179+
value: COMMIT_WITH_GENERIC_MESSAGE_CHOICE,
180+
},
181+
{
182+
name: 'Yes, with custom message',
183+
value: COMMIT_WITH_CUSTOM_MESSAGE_CHOICE,
184+
},
185+
{
186+
name: 'No',
187+
value: NO_COMMIT_CHOICE,
188+
},
189+
],
190+
},
191+
])
192+
.then(({commitChoice}) => {
193+
switch (commitChoice) {
194+
case NO_COMMIT_CHOICE: {
195+
echo('Not submitting a commit, but keeping all changes');
196+
197+
break;
198+
}
199+
200+
case COMMIT_WITH_GENERIC_MESSAGE_CHOICE: {
201+
exec(`git commit -am "${GENERIC_COMMIT_MESSAGE}"`, {
202+
cwd: ROOT_LOCATION,
203+
silent: true,
204+
});
205+
206+
break;
207+
}
208+
209+
case COMMIT_WITH_CUSTOM_MESSAGE_CHOICE: {
210+
// exec from shelljs currently does not support interactive input
211+
// https://github.com/shelljs/shelljs/wiki/FAQ#running-interactive-programs-with-exec
212+
execSync('git commit -a', {cwd: ROOT_LOCATION, stdio: 'inherit'});
213+
214+
const enteredCommitMessage = exec('git log -n 1 --format=format:%B', {
215+
cwd: ROOT_LOCATION,
216+
silent: true,
217+
}).stdout.trim();
218+
const commitMessageWithTag =
219+
enteredCommitMessage + `\n\n${PUBLISH_PACKAGES_TAG}`;
220+
221+
exec(`git commit --amend -m "${commitMessageWithTag}"`, {
222+
cwd: ROOT_LOCATION,
223+
silent: true,
224+
});
225+
226+
break;
227+
}
228+
229+
default:
230+
throw new Error('');
231+
}
232+
})
233+
.then(() => echo());
234+
230235
echo(chalk.green('Successfully finished the process of bumping packages'));
231236
exit(0);
232237
};

0 commit comments

Comments
 (0)