-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add version check to reported output #164
Merged
+208
โ90
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5949ccf
Add version check to reported output
mosuem 8f87784
removes Colorize from VersionCheckResult.explanation
devmil 529739f
Merge branch 'main' into versionCheckToOutput
devmil de4f4bf
add CHANGELOG entry
devmil 82b1801
fix cache path resolution
devmil 3293aa4
fix Version in JSON report
devmil 2a17f82
fix CHANGELOG
devmil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:colorize/colorize.dart'; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
|
||
import '../../../api_tool.dart'; | ||
|
||
class VersionCheckResult { | ||
final bool success; | ||
final Version oldVersion; | ||
final Version newVersion; | ||
final Version? neededVersion; | ||
final String explanation; | ||
|
||
VersionCheckResult.success({ | ||
required this.oldVersion, | ||
required this.newVersion, | ||
Version? neededVersion, | ||
required this.explanation, | ||
}) : success = true, | ||
neededVersion = neededVersion ?? newVersion; | ||
|
||
VersionCheckResult.failure({ | ||
required this.oldVersion, | ||
required this.newVersion, | ||
required this.neededVersion, | ||
required this.explanation, | ||
}) : success = false; | ||
} | ||
|
||
/// helper class to check if the version change matches the changes | ||
abstract class VersionCheck { | ||
/// checks if the version change between [oldPackageApi] and [newPackageApi] matches the changes in [diffResult] | ||
static bool versionChangeMatchesChanges({ | ||
static VersionCheckResult check({ | ||
required PackageApiDiffResult diffResult, | ||
required PackageApi oldPackageApi, | ||
required PackageApi newPackageApi, | ||
required bool ignorePrerelease, | ||
required VersionCheckMode versionCheckMode, | ||
}) { | ||
stdout.writeln(''); | ||
stdout.writeln('Checking Package version'); | ||
stdout.writeln(''); | ||
if (oldPackageApi.packageVersion == null) { | ||
throw PackageApiDiffError( | ||
message: 'Old package doesn\'t contain a version]'); | ||
|
@@ -36,14 +56,21 @@ abstract class VersionCheck { | |
diffResult.apiChanges.any((change) => !change.type.requiresMinorBump); | ||
|
||
if (versionCheckMode == VersionCheckMode.none) { | ||
stdout.writeln('Skipping version check completely'); | ||
return true; | ||
return VersionCheckResult.success( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
explanation: | ||
'Skipping version check completely as the version check mode is $versionCheckMode', | ||
); | ||
} | ||
if (versionCheckMode == VersionCheckMode.onlyBreakingChanges && | ||
!containsBreakingChanges) { | ||
stdout.writeln( | ||
'Skipping version check because there are no breaking changes'); | ||
return true; | ||
return VersionCheckResult.success( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
explanation: | ||
'Skipping version check because there are no breaking changes', | ||
); | ||
} | ||
|
||
if (ignorePrerelease) { | ||
|
@@ -57,28 +84,35 @@ abstract class VersionCheck { | |
final oldVersionWithoutPreRelease = Version.parse(oldVersion.toString()); | ||
oldVersionWithoutPreRelease.preRelease.clear(); | ||
if (oldVersionWithoutPreRelease <= newVersion) { | ||
stdout.writeln( | ||
'Skipping version check because the old version is a pre-release and the new version is the same or higher without the pre-release part'); | ||
return true; | ||
return VersionCheckResult.success( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
explanation: | ||
'Skipping version check because the old version is a pre-release and the new version is the same or higher without the pre-release part', | ||
); | ||
} | ||
} | ||
|
||
if (newVersion.isPreRelease) { | ||
// pre-release. We don't look at differentiation between breaking and non-breaking changes | ||
stdout.writeln( | ||
'We got a pre release. We only check if there are any changes'); | ||
final prefix = | ||
'We got a pre release. We only check if there are any changes.'; | ||
if (containsAnyChanges && oldVersion >= newVersion) { | ||
stdout.writeln( | ||
'Got "${Colorize(newVersion.toString()).bold()}" expected > "${Colorize(oldVersion.toString()).bold()}" (pre-release but changes)'); | ||
return false; | ||
return VersionCheckResult.failure( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
neededVersion: null, | ||
explanation: | ||
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. Happy to change the explanations to anything you like better. |
||
'$prefix Got "$newVersion" expected > "$oldVersion" (pre-release but changes)', | ||
); | ||
} | ||
stdout.writeln(Colorize('New version is OK!').green()); | ||
final explaination = containsAnyChanges | ||
? 'which is > "${Colorize(oldVersion.toString()).bold()}" (pre-release but changes)' | ||
final explanation = containsAnyChanges | ||
? 'which is > "$oldVersion" (pre-release but changes)' | ||
: 'and no changes'; | ||
stdout.writeln( | ||
'Got "${Colorize(newVersion.toString()).bold()}" $explaination'); | ||
return true; | ||
return VersionCheckResult.success( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
explanation: '$prefix Got "$newVersion" $explanation'); | ||
} | ||
|
||
Version expectedMinVersion = | ||
|
@@ -99,19 +133,22 @@ abstract class VersionCheck { | |
} | ||
} | ||
|
||
stdout.writeln('Old version: "$oldVersion"'); | ||
stdout.writeln( | ||
'Expecting minimum version: "$expectedMinVersion" ($versionExplanation)'); | ||
if (newVersion < expectedMinVersion) { | ||
stdout.writeln(Colorize('New Version is too low!').red()); | ||
stdout.writeln( | ||
'Got "${Colorize(newVersion.toString()).bold()}" expected >= "${Colorize(expectedMinVersion.toString()).bold()}"'); | ||
return false; | ||
return VersionCheckResult.failure( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
neededVersion: expectedMinVersion, | ||
explanation: | ||
'Got "$newVersion" expected >= "$expectedMinVersion" ($versionExplanation)', | ||
); | ||
} else { | ||
stdout.writeln(Colorize('New version is OK!').green()); | ||
stdout.writeln( | ||
'Got "${Colorize(newVersion.toString()).bold()}" which is >= "${Colorize(expectedMinVersion.toString()).bold()}"'); | ||
return true; | ||
return VersionCheckResult.success( | ||
oldVersion: oldVersion, | ||
newVersion: newVersion, | ||
neededVersion: expectedMinVersion, | ||
explanation: | ||
'Got "$newVersion" which is >= "$expectedMinVersion" ($versionExplanation)', | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import 'package:dart_apitool/src/cli/commands/version_check.dart'; | ||
|
||
import '../../../api_tool.dart'; | ||
|
||
abstract class DiffReporter { | ||
String get reporterName; | ||
|
||
Future<void> generateReport(PackageApiDiffResult diffResult); | ||
Future<void> generateReport( | ||
PackageApiDiffResult diffResult, | ||
VersionCheckResult? versionCheckResult, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't know what you want to still
stdout
here.