Support hotfix version numbers (#28672)
This commit is contained in:
committed by
Jonah Williams
parent
024eaa3fb4
commit
a07c9a12bd
@@ -539,11 +539,12 @@ String _shortGitRevision(String revision) {
|
||||
}
|
||||
|
||||
class GitTagVersion {
|
||||
const GitTagVersion(this.x, this.y, this.z, this.commits, this.hash);
|
||||
const GitTagVersion(this.x, this.y, this.z, this.hotfix, this.commits, this.hash);
|
||||
const GitTagVersion.unknown()
|
||||
: x = null,
|
||||
y = null,
|
||||
z = null,
|
||||
hotfix = null,
|
||||
commits = 0,
|
||||
hash = '';
|
||||
|
||||
@@ -556,6 +557,9 @@ class GitTagVersion {
|
||||
/// The Z in vX.Y.Z.
|
||||
final int z;
|
||||
|
||||
/// the F in vX.Y.Z-hotfix.F
|
||||
final int hotfix;
|
||||
|
||||
/// Number of commits since the vX.Y.Z tag.
|
||||
final int commits;
|
||||
|
||||
@@ -563,22 +567,30 @@ class GitTagVersion {
|
||||
final String hash;
|
||||
|
||||
static GitTagVersion determine() {
|
||||
final String version = _runGit('git describe --match v*.*.* --first-parent --long --tags');
|
||||
final RegExp versionPattern = RegExp('^v([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)-g([a-f0-9]+)\$');
|
||||
final List<String> parts = versionPattern.matchAsPrefix(version)?.groups(<int>[1, 2, 3, 4, 5]);
|
||||
return parse(_runGit('git describe --match v*.*.* --first-parent --long --tags'));
|
||||
}
|
||||
|
||||
static GitTagVersion parse(String version) {
|
||||
final RegExp versionPattern = RegExp(r'^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-hotfix\.([0-9]+))?-([0-9]+)-g([a-f0-9]+)$');
|
||||
final List<String> parts = versionPattern.matchAsPrefix(version)?.groups(<int>[1, 2, 3, 4, 5, 6]);
|
||||
if (parts == null) {
|
||||
printTrace('Could not interpret results of "git describe": $version');
|
||||
return const GitTagVersion.unknown();
|
||||
}
|
||||
final List<int> parsedParts = parts.take(4).map<int>(int.tryParse).toList();
|
||||
return GitTagVersion(parsedParts[0], parsedParts[1], parsedParts[2], parsedParts[3], parts[4]);
|
||||
final List<int> parsedParts = parts.take(5).map<int>((String source) => source == null ? null : int.tryParse(source)).toList();
|
||||
return GitTagVersion(parsedParts[0], parsedParts[1], parsedParts[2], parsedParts[3], parsedParts[4], parts[5]);
|
||||
}
|
||||
|
||||
String frameworkVersionFor(String revision) {
|
||||
if (x == null || y == null || z == null || !revision.startsWith(hash))
|
||||
return '0.0.0-unknown';
|
||||
if (commits == 0)
|
||||
if (commits == 0) {
|
||||
if (hotfix != null)
|
||||
return '$x.$y.$z-hotfix.$hotfix';
|
||||
return '$x.$y.$z';
|
||||
}
|
||||
if (hotfix != null)
|
||||
return '$x.$y.$z-hotfix.${hotfix + 1}-pre.$commits';
|
||||
return '$x.$y.${z + 1}-pre.$commits';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user