Skip to content

Commit c956a1b

Browse files
kelsetfacebook-github-bot
authored andcommitted
chore(releases): improve bump oss script to allow less human errors (#38666)
Summary: One of the limitations of the existing flow for the release crew is that they need to manually remember to publish all the other packages in the monorepo ahead of a new patch release - this PR modifies the logic for the bump-oss-version script (and makes it available via yarn) so that it will not run if: * there are git changes lying around * if some of the packages need a new release it required a bit of refactoring to extract some portions of the logic from the bump-all-package-versions script, but I think the end result is pretty decent. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [CHANGED] - improve bump oss script to allow less human errors Pull Request resolved: #38666 Test Plan: * checkout this branch * comment L54 of bump-oss-version.js (to remove the check on the branch name) * run `yarn bump-all-updated-packages`, verify that it works and that it detects that some packages have unreleased code * run `yarn bump-oss-version -t asd -v asd` (the "fake" parameters are needed to pass the yargs check), verify that it will throw an error because it finds a package that has unreleased code Reviewed By: mdvacca Differential Revision: D48156963 Pulled By: cortinico fbshipit-source-id: 2473ad5a84578c5236c905fd9aa9a88113fe8d22
1 parent baa2714 commit c956a1b

File tree

5 files changed

+60
-178
lines changed

5 files changed

+60
-178
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"test-ios": "./scripts/objc-test.sh test",
3535
"test-typescript": "dtslint packages/react-native/types",
3636
"test-typescript-offline": "dtslint --localTs node_modules/typescript/lib packages/react-native/types",
37-
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages"
37+
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages",
38+
"trigger-react-native-release": "node ./scripts/trigger-react-native-release.js"
3839
},
3940
"workspaces": [
4041
"packages/*"

scripts/bump-oss-version.js

Lines changed: 0 additions & 150 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
const chalk = require('chalk');
11+
const {echo, exec} = require('shelljs');
12+
13+
const detectPackageUnreleasedChanges = (
14+
packageRelativePathFromRoot,
15+
packageName,
16+
ROOT_LOCATION,
17+
) => {
18+
const hashOfLastCommitInsidePackage = exec(
19+
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
20+
{cwd: ROOT_LOCATION, silent: true},
21+
).stdout.trim();
22+
23+
const hashOfLastCommitThatChangedVersion = exec(
24+
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
25+
{cwd: ROOT_LOCATION, silent: true},
26+
).stdout.trim();
27+
28+
if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
29+
echo(
30+
`\uD83D\uDD0E No changes for package ${chalk.green(
31+
packageName,
32+
)} since last version bump`,
33+
);
34+
return false;
35+
} else {
36+
echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
37+
exec(
38+
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
39+
{
40+
cwd: ROOT_LOCATION,
41+
},
42+
);
43+
echo();
44+
45+
return true;
46+
}
47+
};
48+
49+
module.exports = detectPackageUnreleasedChanges;

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

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
const forEachPackage = require('../for-each-package');
2626
const checkForGitChanges = require('../check-for-git-changes');
2727
const bumpPackageVersion = require('./bump-package-version');
28+
const detectPackageUnreleasedChanges = require('./bump-utils');
2829

2930
const ROOT_LOCATION = path.join(__dirname, '..', '..', '..');
3031

@@ -62,35 +63,16 @@ const buildExecutor =
6263
return;
6364
}
6465

65-
const hashOfLastCommitInsidePackage = exec(
66-
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
67-
{cwd: ROOT_LOCATION, silent: true},
68-
).stdout.trim();
69-
70-
const hashOfLastCommitThatChangedVersion = exec(
71-
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
72-
{cwd: ROOT_LOCATION, silent: true},
73-
).stdout.trim();
74-
75-
if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
76-
echo(
77-
`\uD83D\uDD0E No changes for package ${chalk.green(
78-
packageName,
79-
)} since last version bump`,
80-
);
81-
66+
if (
67+
!detectPackageUnreleasedChanges(
68+
packageRelativePathFromRoot,
69+
packageName,
70+
ROOT_LOCATION,
71+
)
72+
) {
8273
return;
8374
}
8475

85-
echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
86-
exec(
87-
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
88-
{
89-
cwd: ROOT_LOCATION,
90-
},
91-
);
92-
echo();
93-
9476
await inquirer
9577
.prompt([
9678
{

scripts/publish-npm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function getNpmInfo(buildType) {
113113
);
114114

115115
// See if releaser indicated that this version should be tagged "latest"
116-
// Set in `bump-oss-version`
116+
// Set in `trigger-react-native-release`
117117
const isLatest = exitIfNotOnGit(
118118
() => isTaggedLatest(currentCommit),
119119
'Not in git. We do not want to publish anything',

0 commit comments

Comments
 (0)