Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions script/tool/lib/src/branches_for_batch_release_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class BranchesForBatchReleaseCommand extends PackageCommand {
versionIndex = math.min(versionIndex, entry.version.index);
}
final VersionChange effectiveVersionChange = VersionChange.values[versionIndex];
if (effectiveVersionChange == VersionChange.promote && oldVersion.major != 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have ci to guard against pr that try to use promote when the package already post 1.0.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; could you file a team-ecosystem issue with the p: tooling label?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will put up a pr shortly

printError('"promote" is only valid for pre-1.0 packages.');
throw ToolExit(_kExitPackageMalformed);
}

final Version? newVersion = _newVersionFollowingDartSemVer(oldVersion, effectiveVersionChange);
return _ReleaseInfo(newVersion, changelogs);
Expand All @@ -138,6 +142,7 @@ class BranchesForBatchReleaseCommand extends PackageCommand {
final oldBuildNumber = oldVersion.build.isEmpty ? 0 : oldVersion.build.first as int;
return switch (change) {
VersionChange.skip => null,
VersionChange.promote => Version(1, 0, 0),
VersionChange.major => Version(0, oldVersion.minor + 1, 0),
VersionChange.minor => Version(0, oldVersion.minor, oldVersion.patch + 1),
VersionChange.patch => Version(
Expand All @@ -150,6 +155,7 @@ class BranchesForBatchReleaseCommand extends PackageCommand {
} else {
return switch (change) {
VersionChange.skip => null,
VersionChange.promote => throw ArgumentError('promote is only valid for pre-1.0 packages.'),
VersionChange.major => Version(oldVersion.major + 1, 0, 0),
VersionChange.minor => Version(oldVersion.major, oldVersion.minor + 1, 0),
VersionChange.patch => Version(oldVersion.major, oldVersion.minor, oldVersion.patch + 1),
Expand Down
5 changes: 5 additions & 0 deletions script/tool/lib/src/common/pending_changelog_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import 'package:yaml/yaml.dart';
/// take priority when multiple version changes are specified. The top most value
/// (the samller the index) has the highest priority.
enum VersionChange {
/// A major version change from 0.x.y to 1.0.0.
///
/// This can only be used for a package with a 0.x version.
promote,

/// A major version change (e.g., 1.2.3 -> 2.0.0).
major,

Expand Down
49 changes: 49 additions & 0 deletions script/tool/test/branches_for_batch_release_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,35 @@ version: patch
expect(changelogContent, contains('A new feature'));
expect(gitProcessRunner.recordedCalls, orderedEquals(getExpectedGitCalls('1.0.1')));
});

test('bumps major version when promoting to 1.0', () async {
final RepositoryPackage package = createTestPackage(version: '0.1.0');
addTearDown(() {
package.directory.deleteSync(recursive: true);
});
createPendingChangelogFile(package, 'a.yaml', '''
changelog: The big release
version: promote
''');

final List<String> output = await runBatchCommand();

expect(
output,
containsAllInOrder(<String>[
'Parsing package "a_package"...',
' Creating new branch "release-branch"...',
' Pushing branch release-branch to remote origin...',
]),
);

expect(package.pubspecFile.readAsStringSync(), contains('version: 1.0.0'));
final String changelogContent = package.changelogFile.readAsStringSync();
expect(changelogContent, startsWith('## 1.0.0'));
expect(changelogContent, contains('The big release'));
expect(gitProcessRunner.recordedCalls, orderedEquals(getExpectedGitCalls('1.0.0')));
});

test('bumps "patch" version for minor pre-1.0', () async {
final RepositoryPackage package = createTestPackage(version: '0.1.0');
addTearDown(() {
Expand Down Expand Up @@ -678,5 +707,25 @@ version: major

expect(output.last, contains('Failed to push to release-a_package-2.0.0: error'));
});

test('throws for "promote" when version >= 1.0.0', () async {
final RepositoryPackage package = createTestPackage();
addTearDown(() {
package.directory.deleteSync(recursive: true);
});
createPendingChangelogFile(package, 'a.yaml', '''
changelog: Try to release 1.0 again
version: promote
''');

final List<String> output = await runBatchCommand(
errorHandler: (Error e) {
expect(e, isA<ToolExit>());
expect((e as ToolExit).exitCode, 3);
},
);

expect(output.last, contains('"promote" is only valid for pre-1.0 packages.'));
});
});
}
Loading