Skip to content

[tool] Allow importing packages with NEXT #3215

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

Merged
merged 2 commits into from
Feb 18, 2023
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: 5 additions & 1 deletion script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ enum _CurrentVersionState {
/// The version has changed, and the transition is invalid.
invalidChange,

/// The package is new.
newPackage,

/// There was an error determining the version state.
unknown,
}
Expand Down Expand Up @@ -216,6 +219,7 @@ class VersionCheckCommand extends PackageLoopingCommand {
break;
case _CurrentVersionState.validIncrease:
case _CurrentVersionState.validRevert:
case _CurrentVersionState.newPackage:
versionChanged = true;
break;
case _CurrentVersionState.invalidChange:
Expand Down Expand Up @@ -318,7 +322,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
'${getBoolArg(_againstPubFlag) ? 'on pub server' : 'at git base'}.');
logWarning(
'${indentation}If this package is not new, something has gone wrong.');
return _CurrentVersionState.validIncrease; // Assume new, thus valid.
return _CurrentVersionState.newPackage;
}

if (previousVersion == currentVersion) {
Expand Down
34 changes: 32 additions & 2 deletions script/tool/test/version_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ void main() {
const String version = '1.0.1';
final RepositoryPackage plugin =
createFakePlugin('plugin', packagesDir, version: version);
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
MockProcess(stdout: 'version: 1.0.0'),
];

const String changelog = '''
## NEXT
Expand All @@ -538,7 +541,7 @@ void main() {

bool hasError = false;
final List<String> output = await runCapturingPrint(
runner, <String>['version-check', '--base-sha=main', '--against-pub'],
runner, <String>['version-check', '--base-sha=main'],
errorHandler: (Error e) {
expect(e, isA<ToolExit>());
hasError = true;
Expand All @@ -559,6 +562,9 @@ void main() {
test('fails if the version increases without replacing NEXT', () async {
final RepositoryPackage plugin =
createFakePlugin('plugin', packagesDir, version: '1.0.1');
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
MockProcess(stdout: 'version: 1.0.0'),
];

const String changelog = '''
## NEXT
Expand All @@ -570,7 +576,7 @@ void main() {

bool hasError = false;
final List<String> output = await runCapturingPrint(
runner, <String>['version-check', '--base-sha=main', '--against-pub'],
runner, <String>['version-check', '--base-sha=main'],
errorHandler: (Error e) {
expect(e, isA<ToolExit>());
hasError = true;
Expand Down Expand Up @@ -613,6 +619,30 @@ void main() {
);
});

// This handles imports of a package with a NEXT section.
test('allows NEXT for a new package', () async {
final RepositoryPackage plugin =
createFakePackage('a_package', packagesDir, version: '1.0.0');

const String changelog = '''
## NEXT
* Some changes that should be listed in the next release.
## 1.0.0
* Some other changes.
''';
plugin.changelogFile.writeAsStringSync(changelog);

final List<String> output = await runCapturingPrint(
runner, <String>['version-check', '--base-sha=main']);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Unable to find previous version at git base'),
contains('Found NEXT; validating next version in the CHANGELOG'),
]),
);
});

test(
'fails gracefully if the version headers are not found due to using the wrong style',
() async {
Expand Down