-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[ci] updates update-release-info to support batch release
#10958
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
base: main
Are you sure you want to change the base?
Changes from all commits
ce06eaa
29a7d7b
1a079bd
1108ddf
892b9cc
8a56d35
a44d965
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,15 @@ class UpdateReleaseInfoCommand extends PackageLoopingCommand { | |
|
|
||
| @override | ||
| Future<PackageResult> runForPackage(RepositoryPackage package) async { | ||
| String nextVersionString; | ||
| final Version? version = package.parsePubspec().version; | ||
| final bool isBatchRelease = | ||
| package.parseCIConfig()?.isBatchRelease ?? false; | ||
| if (isBatchRelease && (version?.isPreRelease ?? false)) { | ||
| return PackageResult.fail(<String>[ | ||
| 'This command does not support batch releases packages with pre-release versions.', | ||
| 'Pre-release version: $version', | ||
| ]); | ||
| } | ||
|
|
||
| _VersionIncrementType? versionChange = _versionChange; | ||
|
|
||
|
|
@@ -144,36 +152,14 @@ class UpdateReleaseInfoCommand extends PackageLoopingCommand { | |
| } | ||
| } | ||
|
|
||
| if (versionChange != null) { | ||
| final Version? updatedVersion = _updatePubspecVersion( | ||
| if (isBatchRelease) { | ||
| return _createPendingBatchChangelog( | ||
| package, | ||
| versionChange, | ||
| versionChange: versionChange, | ||
| ); | ||
| if (updatedVersion == null) { | ||
| return PackageResult.fail(<String>[ | ||
| 'Could not determine current version.', | ||
| ]); | ||
| } | ||
| nextVersionString = updatedVersion.toString(); | ||
| print('${indentation}Incremented version to $nextVersionString.'); | ||
| } else { | ||
| nextVersionString = 'NEXT'; | ||
| } | ||
|
|
||
| final _ChangelogUpdateOutcome updateOutcome = _updateChangelog( | ||
| package, | ||
| nextVersionString, | ||
| ); | ||
| switch (updateOutcome) { | ||
| case _ChangelogUpdateOutcome.addedSection: | ||
| print('${indentation}Added a $nextVersionString section.'); | ||
| case _ChangelogUpdateOutcome.updatedSection: | ||
| print('${indentation}Updated NEXT section.'); | ||
| case _ChangelogUpdateOutcome.failed: | ||
| return PackageResult.fail(<String>['Could not update CHANGELOG.md.']); | ||
| } | ||
|
|
||
| return PackageResult.success(); | ||
| return _updatePubspecAndChangelog(package, versionChange: versionChange); | ||
| } | ||
|
|
||
| _ChangelogUpdateOutcome _updateChangelog( | ||
|
|
@@ -314,4 +300,90 @@ class UpdateReleaseInfoCommand extends PackageLoopingCommand { | |
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Updates the `pubspec.yaml` and `CHANGELOG.md` files directly. | ||
| /// | ||
| /// This is used for standard releases, where changes will be released | ||
| /// immediately. | ||
| Future<PackageResult> _updatePubspecAndChangelog( | ||
| RepositoryPackage package, { | ||
| _VersionIncrementType? versionChange, | ||
| }) async { | ||
| String nextVersionString; | ||
| if (versionChange != null) { | ||
| final Version? updatedVersion = _updatePubspecVersion( | ||
| package, | ||
| versionChange, | ||
| ); | ||
| if (updatedVersion == null) { | ||
| return PackageResult.fail(<String>[ | ||
| 'Could not determine current version.', | ||
| ]); | ||
| } | ||
| nextVersionString = updatedVersion.toString(); | ||
| print('${indentation}Incremented version to $nextVersionString.'); | ||
| } else { | ||
| nextVersionString = 'NEXT'; | ||
| } | ||
|
|
||
| final _ChangelogUpdateOutcome updateOutcome = _updateChangelog( | ||
| package, | ||
| nextVersionString, | ||
| ); | ||
| switch (updateOutcome) { | ||
| case _ChangelogUpdateOutcome.addedSection: | ||
| print('${indentation}Added a $nextVersionString section.'); | ||
| case _ChangelogUpdateOutcome.updatedSection: | ||
| print('${indentation}Updated NEXT section.'); | ||
| case _ChangelogUpdateOutcome.failed: | ||
| return PackageResult.fail(<String>['Could not update CHANGELOG.md.']); | ||
| } | ||
|
|
||
| return PackageResult.success(); | ||
| } | ||
|
|
||
| /// Creates a pending changelog entry in the package's `pending_changelogs` | ||
| /// directory. | ||
| /// | ||
| /// This is used for batch releases, where changes are accumulated in | ||
| /// individual files before being merged into the main CHANGELOG.md and | ||
| /// pubspec.yaml during the release process. | ||
| Future<PackageResult> _createPendingBatchChangelog( | ||
| RepositoryPackage package, { | ||
| _VersionIncrementType? versionChange, | ||
| }) async { | ||
| final Directory pendingDirectory = package.pendingChangelogsDirectory; | ||
| if (!pendingDirectory.existsSync()) { | ||
| return PackageResult.fail(<String>[ | ||
| 'Could not create pending changelog entry. Pending changelog directory does not exist.', | ||
| ]); | ||
| } | ||
|
|
||
| final VersionChange type; | ||
| switch (versionChange) { | ||
| case _VersionIncrementType.minor: | ||
| type = VersionChange.minor; | ||
| case _VersionIncrementType.bugfix: | ||
| type = VersionChange.patch; | ||
| case _VersionIncrementType.build: | ||
| throw UnimplementedError( | ||
| 'Build version changes should not happen in batch mode. Please file an issue if you see this.', | ||
| ); | ||
| case null: | ||
| type = VersionChange.skip; | ||
| } | ||
|
|
||
| final String changelogEntry = getStringArg(_changelogFlag); | ||
| final content = | ||
| ''' | ||
| changelog: | | ||
| ${changelogEntry.split('\n').map((line) => ' - $line').join('\n')} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is text block after a |
||
| version: ${type.name} | ||
| '''; | ||
| final filename = 'change_${DateTime.now().millisecondsSinceEpoch}.yaml'; | ||
| final File file = pendingDirectory.childFile(filename); | ||
| file.writeAsStringSync(content); | ||
| print('${indentation}Created pending changelog entry: $filename'); | ||
| return PackageResult.success(); | ||
| } | ||
| } | ||
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.
It's not clear to me what this instruction means. If it's not supposed to happen, why should the person file an issue? What would that issue say/request?
If you mean that it's not supported, then it should say that it's not currently supported and that if that's an issue they should file an issue requesting support for build versions in batch changes.
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.
It can't logically happen because otherwise the tool should have throw UsageError in the earlier stage. If this line is reached, that mean something is wrong with the code