-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
feat(react-native-github): a script to automate patch version bumping of packages #35767
Conversation
This pull request was exported from Phabricator. Differential Revision: D42295344 |
Demo: Screen.Recording.2022-12-30.at.13.36.28.mov |
Base commit: 88a1b8e |
Base commit: 292268e |
PR build artifact for aa26c5c is ready. |
PR build artifact for aa26c5c is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leaving a couple comments so that we can discuss them further, overall LGTM but one improvement I think is very important
} | ||
}; | ||
|
||
const bumpPackageVersion = (packageAbsolutePath, packageManifest) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method seems "comprehensive" enough that should work also on -stable branches, but just to be sure, could you create a separate branch on top of 0.71 with the same script and verify that it works fine in there too? (usual difference of root package not being workspace, and repo-config's package.json and root package.json having different content VS when they are on main)
AFAIK it should just work fine but worth double checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just utility function, I've extracted it to avoid keeping one file with 300+ lines. This is not supposed to work from cli (node ./scripts/monorepo/...
)
If you find it useful, I could make it available through cli and make a separate PR against 0.71-stable branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point here is that I want to make sure that the overall script works fine even in a 0.XX-stable branch without us having to reach the point of cutting 0.72-stable and finding out only then if it works proper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point here is that I want to make sure that the overall script works fine even in a 0.XX-stable branch without us having to reach the point of cutting 0.72-stable and finding out only then if it works proper.
I've just tested it on 0.71-stable branch. Works as expected, except for yarn
: root level package.json
does not contain workspaces
, so running yarn install
fails after version bump, because packages with updated version is not yet published
I can remove this step at all (running yarn
), what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except for yarn: root level package.json does not contain workspaces, so running yarn install fails after version bump, because packages with updated version is not yet published
that actually raises a good point! Will CI be fault-resistant enough to be able to get to the step of doing the npm publish for these new versions if root yarn install fail? I'm concerned CI will fail on like, one of the early steps of setting up the CI VMs because yarn install fails, so it will never get to publishing the new versions.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except for yarn: root level package.json does not contain workspaces, so running yarn install fails after version bump, because packages with updated version is not yet published
that actually raises a good point! Will CI be fault-resistant enough to be able to get to the step of doing the npm publish for these new versions if root yarn install fail? I'm concerned CI will fail on like, one of the early steps of setting up the CI VMs because yarn install fails, so it will never get to publishing the new versions.
What do you think?
Yes, it will fail. I can remove all external depedencies (like chalk
and shelljs
) from find-and-publish-all-bumped-packages
script. After this, we can remove run_yarn
step from CircleCI job.
We will lose fancy output, but this the only option I see if we want to make it work on *-stable
branches.
Also there should be other CircleCI jobs for *-stable
branches, which will require running yarn and will eventually fail. Should we skip these jobs for such bump commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there should be other CircleCI jobs for *-stable branches, which will require running yarn and will eventually fail. Should we skip these jobs for such bump commits?
I'm starting to think that splitting the steps 1-2 from 3->5 is probably even more important than expected; we need to update the yarn.lock after the new releases in all cases. So I am not sure "forcing" it all to happen in one go by skipping other jobs will make things ok since then we'll still have to do one more commit with the yarn.lock update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see. I can work on splitting this.
I am proposing this flow:
- User runs script, which bumps all relevant packages and creates a commit with a specific message.
- User creates PR with this commit and at some point this commit is merged.
- We have automated CircleCI workflow, which runs on
main
and*-stable
branches, which does the following:
3.1. publish each bumped package to npm
3.2 commit version bumps for each consumer packages, open PR against target branch of original commit (on top of which workflow was executed)
Do we have an examples of an automated processes where bot creates a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about the proposed flow: I think step 2 is optional in a way, user could also just directly commit (if they are a Meta engineer and doing it in the internal monorepo, or a person with write access on a -stable branch); about step 3.2 are you thinking of 1 PR per each bumped package (ex. if I bumped @react-native/codegen and @react-native/gradle-plugin, will it open 1 or 2 PRs)?
Do we have an examples of an automated processes where bot creates a PR?
There are many like https://github.com/dependabot, if I'm understanding your question (so probably https://github.com/dependabot/dependabot-core is what you want to look into)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you thinking of 1 PR per each bumped package (ex. if I bumped @react-native/codegen and @react-native/gradle-plugin, will it open 1 or 2 PRs)?
No, I am thinking about opening a PR which contains updated versions for each of the packages, which were bumped in previous commit and then published
I will research about dependabot, but I think we might need something more simple, just to create PR with bumped versions
This pull request was exported from Phabricator. Differential Revision: D42295344 |
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version for each package: check if this package is used and update its version run yarn if required commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: c6f17cdd480984d31fdbcad1b4379cfae915fd35
aa26c5c
to
bf7af96
Compare
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version for each package: check if this package is used and update its version run yarn if required commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 326b1b28f20f21252154bf9f3ebf42d71de9112b
bf7af96
to
fca5d04
Compare
This pull request was exported from Phabricator. Differential Revision: D42295344 |
throw new Error( | ||
`Package ${packageManifest.name} was updated, but not through CI script`, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great error 👏
scripts/monorepo/bump-all-updated-packages/bump-package-version.js
Outdated
Show resolved
Hide resolved
Current demo: Screen.Recording.2023-01-05.at.16.35.21.movI am now working on splitting this into two distinct scipts: one for version bumps (which will be used to publish packages to npm) and other to bump version in consumer packages. Will update demo after that |
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` --- Also adding a separate script `align-package-versions.js`, which can be used to update versions of packages inside consumer packages ``` check that no git changes are present for each package x: for each package y: if y has x as dependency: validate that y uses the latest version of x if some changes were made: run yarn ``` --- Q: Why `run_yarn` step was removed from CircleCI flow? A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update `react-native/assets-registry` to the next version, we won't be able to run `yarn` for react-native root package, because updated version is not yet published to npm To avoid this, we first need publish new versions and then update them in consumer packages --- The final flow: 1. Developer uses `node ./scripts/bump-all-updated-packages` to bump versions of all updated packages. 2. Commit created from step 1 being merged or directly pushed to `main` or `*-stable` branches 3. A workflow from CircleCI publishes all updated versions to npm 4. Developer can use `align-package-versions.js` script to create required changes to align all packages versions Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 1a4bbe33a996a93af37a6642ed4a11341066e6ee
This pull request was exported from Phabricator. Differential Revision: D42295344 |
fca5d04
to
104a05f
Compare
Screen.Recording.2023-01-10.at.16.12.35.mov
Screen.Recording.2023-01-10.at.16.14.03.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think now this is ready to
packageManifest.version, | ||
), | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a super big fan of this double forEach which feels a bit like brute forcing checking everything against everything but honestly hey at least we'll make sure that everything is correctly aligned!
And I think this will work out of the box with -stable branches too so 👍
one last thing: can you add the two new scripts to root |
Sure, I will add this. I will also update our new wiki page with relevant information |
This pull request has been merged in ec28c5b. |
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` --- Also adding a separate script `align-package-versions.js`, which can be used to update versions of packages inside consumer packages ``` check that no git changes are present for each package x: for each package y: if y has x as dependency: validate that y uses the latest version of x if some changes were made: run yarn ``` --- Q: Why `run_yarn` step was removed from CircleCI flow? A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update `react-native/assets-registry` to the next version, we won't be able to run `yarn` for react-native root package, because updated version is not yet published to npm To avoid this, we first need publish new versions and then update them in consumer packages --- The final flow: 1. Developer uses `node ./scripts/bump-all-updated-packages` to bump versions of all updated packages. 2. Commit created from step 1 being merged or directly pushed to `main` or `*-stable` branches 3. A workflow from CircleCI publishes all updated versions to npm 4. Developer can use `align-package-versions.js` script to create required changes to align all packages versions Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 54b667adb3ee5f28d19ee9c7991570451549aac2
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` --- Also adding a separate script `align-package-versions.js`, which can be used to update versions of packages inside consumer packages ``` check that no git changes are present for each package x: for each package y: if y has x as dependency: validate that y uses the latest version of x if some changes were made: run yarn ``` --- Q: Why `run_yarn` step was removed from CircleCI flow? A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update `react-native/assets-registry` to the next version, we won't be able to run `yarn` for react-native root package, because updated version is not yet published to npm To avoid this, we first need publish new versions and then update them in consumer packages --- The final flow: 1. Developer uses `node ./scripts/bump-all-updated-packages` to bump versions of all updated packages. 2. Commit created from step 1 being merged or directly pushed to `main` or `*-stable` branches 3. A workflow from CircleCI publishes all updated versions to npm 4. Developer can use `align-package-versions.js` script to create required changes to align all packages versions Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 54b667adb3ee5f28d19ee9c7991570451549aac2
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` --- Also adding a separate script `align-package-versions.js`, which can be used to update versions of packages inside consumer packages ``` check that no git changes are present for each package x: for each package y: if y has x as dependency: validate that y uses the latest version of x if some changes were made: run yarn ``` --- Q: Why `run_yarn` step was removed from CircleCI flow? A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update `react-native/assets-registry` to the next version, we won't be able to run `yarn` for react-native root package, because updated version is not yet published to npm To avoid this, we first need publish new versions and then update them in consumer packages --- The final flow: 1. Developer uses `node ./scripts/bump-all-updated-packages` to bump versions of all updated packages. 2. Commit created from step 1 being merged or directly pushed to `main` or `*-stable` branches 3. A workflow from CircleCI publishes all updated versions to npm 4. Developer can use `align-package-versions.js` script to create required changes to align all packages versions Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 54b667adb3ee5f28d19ee9c7991570451549aac2
… of packages (facebook#35767) Summary: Pull Request resolved: facebook#35767 Changelog: [Internal] Introducing a script, which can be used to identify all packages inside `/packages`, which contain any changes after the last time its version was changed How it works step by step: ``` check that no git changes are present for each package: if package is private -> skip grep id of the last commit that changed package grep id of the last commit that changed version of the package if these ids are different: bump package patch version commit changes if required ``` Can be executed only in git environment and by running: `node ./scripts/bump-all-updated-packages` --- Also adding a separate script `align-package-versions.js`, which can be used to update versions of packages inside consumer packages ``` check that no git changes are present for each package x: for each package y: if y has x as dependency: validate that y uses the latest version of x if some changes were made: run yarn ``` --- Q: Why `run_yarn` step was removed from CircleCI flow? A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update `react-native/assets-registry` to the next version, we won't be able to run `yarn` for react-native root package, because updated version is not yet published to npm To avoid this, we first need publish new versions and then update them in consumer packages --- The final flow: 1. Developer uses `node ./scripts/bump-all-updated-packages` to bump versions of all updated packages. 2. Commit created from step 1 being merged or directly pushed to `main` or `*-stable` branches 3. A workflow from CircleCI publishes all updated versions to npm 4. Developer can use `align-package-versions.js` script to create required changes to align all packages versions Reviewed By: cortinico Differential Revision: D42295344 fbshipit-source-id: 54b667adb3ee5f28d19ee9c7991570451549aac2
Summary:
Changelog: [Internal]
Introducing a script, which can be used to identify all packages inside
/packages
, which contain any changes after the last time its version was changedHow it works step by step:
Can be executed only in git environment and by running:
node ./scripts/bump-all-updated-packages
Also adding a separate script
align-package-versions.js
, which can be used to update versions of packages inside consumer packagesQ: Why
run_yarn
step was removed from CircleCI flow?A: For *-stable branches, there are no yarn workspaces and all packages are specified as direct dependencies, so if we update
@react-native/assets-registry
to the next version, we won't be able to runyarn
for react-native root package, because updated version is not yet published to npmTo avoid this, we first need publish new versions and then update them in consumer packages
The final flow:
node ./scripts/bump-all-updated-packages
to bump versions of all updated packages.main
or*-stable
branchesalign-package-versions.js
script to create required changes to align all packages versionsDifferential Revision: D42295344