mirror of
https://github.com/flutter/packages.git
synced 2025-06-18 04:33:52 +08:00
[tool] Allow importing packages with NEXT (#3215)
Fixes an issue that showed up in the trial repo merge PR; if a pacakge is new to the repository (i.e., has no git history in the parent commit), it was being treated as a version bump, which caused failures if NEXT was present. This adds a new state so that we can allow NEXT during import.
This commit is contained in:
@ -47,6 +47,9 @@ enum _CurrentVersionState {
|
|||||||
/// The version has changed, and the transition is invalid.
|
/// The version has changed, and the transition is invalid.
|
||||||
invalidChange,
|
invalidChange,
|
||||||
|
|
||||||
|
/// The package is new.
|
||||||
|
newPackage,
|
||||||
|
|
||||||
/// There was an error determining the version state.
|
/// There was an error determining the version state.
|
||||||
unknown,
|
unknown,
|
||||||
}
|
}
|
||||||
@ -216,6 +219,7 @@ class VersionCheckCommand extends PackageLoopingCommand {
|
|||||||
break;
|
break;
|
||||||
case _CurrentVersionState.validIncrease:
|
case _CurrentVersionState.validIncrease:
|
||||||
case _CurrentVersionState.validRevert:
|
case _CurrentVersionState.validRevert:
|
||||||
|
case _CurrentVersionState.newPackage:
|
||||||
versionChanged = true;
|
versionChanged = true;
|
||||||
break;
|
break;
|
||||||
case _CurrentVersionState.invalidChange:
|
case _CurrentVersionState.invalidChange:
|
||||||
@ -318,7 +322,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
|
|||||||
'${getBoolArg(_againstPubFlag) ? 'on pub server' : 'at git base'}.');
|
'${getBoolArg(_againstPubFlag) ? 'on pub server' : 'at git base'}.');
|
||||||
logWarning(
|
logWarning(
|
||||||
'${indentation}If this package is not new, something has gone wrong.');
|
'${indentation}If this package is not new, something has gone wrong.');
|
||||||
return _CurrentVersionState.validIncrease; // Assume new, thus valid.
|
return _CurrentVersionState.newPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousVersion == currentVersion) {
|
if (previousVersion == currentVersion) {
|
||||||
|
@ -525,6 +525,9 @@ void main() {
|
|||||||
const String version = '1.0.1';
|
const String version = '1.0.1';
|
||||||
final RepositoryPackage plugin =
|
final RepositoryPackage plugin =
|
||||||
createFakePlugin('plugin', packagesDir, version: version);
|
createFakePlugin('plugin', packagesDir, version: version);
|
||||||
|
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
|
||||||
|
MockProcess(stdout: 'version: 1.0.0'),
|
||||||
|
];
|
||||||
|
|
||||||
const String changelog = '''
|
const String changelog = '''
|
||||||
## NEXT
|
## NEXT
|
||||||
@ -538,7 +541,7 @@ void main() {
|
|||||||
|
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
final List<String> output = await runCapturingPrint(
|
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) {
|
errorHandler: (Error e) {
|
||||||
expect(e, isA<ToolExit>());
|
expect(e, isA<ToolExit>());
|
||||||
hasError = true;
|
hasError = true;
|
||||||
@ -559,6 +562,9 @@ void main() {
|
|||||||
test('fails if the version increases without replacing NEXT', () async {
|
test('fails if the version increases without replacing NEXT', () async {
|
||||||
final RepositoryPackage plugin =
|
final RepositoryPackage plugin =
|
||||||
createFakePlugin('plugin', packagesDir, version: '1.0.1');
|
createFakePlugin('plugin', packagesDir, version: '1.0.1');
|
||||||
|
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
|
||||||
|
MockProcess(stdout: 'version: 1.0.0'),
|
||||||
|
];
|
||||||
|
|
||||||
const String changelog = '''
|
const String changelog = '''
|
||||||
## NEXT
|
## NEXT
|
||||||
@ -570,7 +576,7 @@ void main() {
|
|||||||
|
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
final List<String> output = await runCapturingPrint(
|
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) {
|
errorHandler: (Error e) {
|
||||||
expect(e, isA<ToolExit>());
|
expect(e, isA<ToolExit>());
|
||||||
hasError = true;
|
hasError = true;
|
||||||
@ -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(
|
test(
|
||||||
'fails gracefully if the version headers are not found due to using the wrong style',
|
'fails gracefully if the version headers are not found due to using the wrong style',
|
||||||
() async {
|
() async {
|
||||||
|
Reference in New Issue
Block a user