[tool] Support pre-1.0 versions in batch releases#12257
Conversation
Adds support for Dart's semver convention of shifting the conceptual meaning of versions by one place for pre-1.0 package when determining batch release versions. For example, a batch release with a "major" changelog entry would go from 0.x.y to 0.x+1.0.
There was a problem hiding this comment.
Code Review
This pull request adds support for batch releasing pre-1.0 packages by removing the version restriction and implementing Dart semantic versioning rules for pre-1.0 version bumps. Corresponding unit tests have been added and updated. Feedback on the changes includes correcting a typo in the changelog and addressing an unsafe cast to int on the first build identifier of oldVersion.build, which could throw a runtime TypeError if the identifier is a string.
|
|
||
| Version? _newVersionFollowingDartSemVer(Version oldVersion, VersionChange change) { | ||
| if (oldVersion.major == 0) { | ||
| final oldBuildNumber = oldVersion.build.isEmpty ? 0 : oldVersion.build.first as int; |
There was a problem hiding this comment.
Casting oldVersion.build.first as int is unsafe because build metadata identifiers in pub_semver can be either integers or strings (e.g., 0.1.0+alpha or 0.1.0+1.2). If the first build identifier is a string, this cast will throw a runtime TypeError.
It is safer to check the type and parse it if necessary.
final Object? firstBuild = oldVersion.build.isEmpty ? null : oldVersion.build.first;
final int oldBuildNumber = firstBuild is int ? firstBuild : (int.tryParse(firstBuild?.toString() ?? '') ?? 0);There was a problem hiding this comment.
We don't usually do x.y.z+a.b releases in flutter/packages, correct? So maybe this is a non-issue?
There was a problem hiding this comment.
Right, we only do +N.
| return switch (change) { | ||
| VersionChange.skip => null, | ||
| VersionChange.major => Version(0, oldVersion.minor + 1, 0), | ||
| VersionChange.minor => Version(0, oldVersion.minor, oldVersion.patch + 1), | ||
| VersionChange.patch => Version( | ||
| 0, | ||
| oldVersion.minor, | ||
| oldVersion.patch, | ||
| build: '${oldBuildNumber + 1}', | ||
| ), | ||
| }; |
There was a problem hiding this comment.
I didn't realize this affects the version bump differently from a post-v1 release. I made my release a patch release assuming that would bump it to 0.0.2:
Should I land a quick PR that changes that to minor?
Also, does this mean that we can't release 1.0.0 via the batch release process, we'll have to do it manually?
There was a problem hiding this comment.
Also, does this mean that we can't release 1.0.0 via the batch release process, we'll have to do it manually?
Ugh, I hadn't considered that. I was just thinking of this the same way the update-release-info command works, but for that we just don't handle 0.x->1.0 because it can trivially be done manually.
Maybe the bettor option here is just to turn off batch releasing for now, and do continuous releases with publish_to:none between releases, until you are ready for 1.0?
There was a problem hiding this comment.
Or we could land this, and then figure out how to special case the 1.0 release sometime before you want to do the 1.0 release. Which would you prefer?
There was a problem hiding this comment.
Hmm, maybe to uncomplicate the 1.0, we should just not use batch release for this and use the regular release process through CI for this one? @justinmc WDYT?
There was a problem hiding this comment.
Sounds good either way, but given the current code:
packages/script/tool/lib/src/branches_for_batch_release_command.dart
Lines 81 to 86 in 796e5b1
Regardless of whether or not we land this PR, we won't be able to use the batch release process for 1.0.0, right? So if I'm understanding correctly, I say we should land this PR and use the batch release process (triggered manually) to publish the prerelease. Then we'll have to figure something out for 1.0.0 either way.
There was a problem hiding this comment.
Then we'll have to figure something out for 1.0.0 either way.
Well, I was thinking that if you went off of batched releases you would stay off of them until you'd done the 1.0 release. But I'll land this and then think about how we could do 1.0 without having to change process. Maybe just a new special change type keyword.
There was a problem hiding this comment.
Sounds good, thanks for looking into it. A new keyword would work for me.
By landing this PR as-is, at least we'll get some verification that the batch release process works before we need everyone to follow it post-1.0.0.
Piinks
left a comment
There was a problem hiding this comment.
I concur with G on the typo. Otherwise LGTM. Thank you!
|
|
||
| Version? _newVersionFollowingDartSemVer(Version oldVersion, VersionChange change) { | ||
| if (oldVersion.major == 0) { | ||
| final oldBuildNumber = oldVersion.build.isEmpty ? 0 : oldVersion.build.first as int; |
There was a problem hiding this comment.
We don't usually do x.y.z+a.b releases in flutter/packages, correct? So maybe this is a non-issue?
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
See #12257 (comment). This PR shouldn't land unless that one does.
Gets material_ui ready for 0.0.2 to be published. Follows the same pattern as cupertino_ui in #12251. Unlike that PR, I set the change to `minor` instead of `patch`. See #12257 (comment). Plus, changes the dependency on cupertino_ui to reference the published 0.0.2 prerelease. That isn't published yet, so this commit should fail CI until it is published. ~~Depends on #12253
Adds support for Dart's semver convention of shifting the conceptual meaning of versions by one place for pre-1.0 package when determining batch release versions.
For example, a batch release with a "major" changelog entry would go from 0.x.y to 0.x+1.0.