Skip to content

Commit

Permalink
chore(releases): improve bump oss script to allow less human errors (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
kelset authored and facebook-github-bot committed Aug 9, 2023
1 parent baa2714 commit c956a1b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 178 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"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"
"bump-all-updated-packages": "node ./scripts/monorepo/bump-all-updated-packages",
"trigger-react-native-release": "node ./scripts/trigger-react-native-release.js"
},
"workspaces": [
"packages/*"
Expand Down
150 changes: 0 additions & 150 deletions scripts/bump-oss-version.js

This file was deleted.

49 changes: 49 additions & 0 deletions scripts/monorepo/bump-all-updated-packages/bump-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

const chalk = require('chalk');
const {echo, exec} = require('shelljs');

const detectPackageUnreleasedChanges = (
packageRelativePathFromRoot,
packageName,
ROOT_LOCATION,
) => {
const hashOfLastCommitInsidePackage = exec(
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
{cwd: ROOT_LOCATION, silent: true},
).stdout.trim();

const hashOfLastCommitThatChangedVersion = exec(
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
{cwd: ROOT_LOCATION, silent: true},
).stdout.trim();

if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
echo(
`\uD83D\uDD0E No changes for package ${chalk.green(
packageName,
)} since last version bump`,
);
return false;
} else {
echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
exec(
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
{
cwd: ROOT_LOCATION,
},
);
echo();

return true;
}
};

module.exports = detectPackageUnreleasedChanges;
34 changes: 8 additions & 26 deletions scripts/monorepo/bump-all-updated-packages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
const forEachPackage = require('../for-each-package');
const checkForGitChanges = require('../check-for-git-changes');
const bumpPackageVersion = require('./bump-package-version');
const detectPackageUnreleasedChanges = require('./bump-utils');

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

Expand Down Expand Up @@ -62,35 +63,16 @@ const buildExecutor =
return;
}

const hashOfLastCommitInsidePackage = exec(
`git log -n 1 --format=format:%H -- ${packageRelativePathFromRoot}`,
{cwd: ROOT_LOCATION, silent: true},
).stdout.trim();

const hashOfLastCommitThatChangedVersion = exec(
`git log -G\\"version\\": --format=format:%H -n 1 -- ${packageRelativePathFromRoot}/package.json`,
{cwd: ROOT_LOCATION, silent: true},
).stdout.trim();

if (hashOfLastCommitInsidePackage === hashOfLastCommitThatChangedVersion) {
echo(
`\uD83D\uDD0E No changes for package ${chalk.green(
packageName,
)} since last version bump`,
);

if (
!detectPackageUnreleasedChanges(
packageRelativePathFromRoot,
packageName,
ROOT_LOCATION,
)
) {
return;
}

echo(`\uD83D\uDCA1 Found changes for ${chalk.yellow(packageName)}:`);
exec(
`git log --pretty=oneline ${hashOfLastCommitThatChangedVersion}..${hashOfLastCommitInsidePackage} ${packageRelativePathFromRoot}`,
{
cwd: ROOT_LOCATION,
},
);
echo();

await inquirer
.prompt([
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getNpmInfo(buildType) {
);

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

0 comments on commit c956a1b

Please sign in to comment.