-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cleanup and SDK update * Build fixes
- Loading branch information
Showing
19 changed files
with
395 additions
and
422 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,8 @@ jobs: | |
uses: actions/[email protected] | ||
with: | ||
dotnet-version: | | ||
5.0.x | ||
6.0.x | ||
8.0.x | ||
- name: .NET info | ||
run: dotnet --info | ||
- name: Install dependencies | ||
|
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,9 +1,8 @@ | ||
namespace TurnerSoftware.BuildVersioning.Tool | ||
namespace TurnerSoftware.BuildVersioning.Tool; | ||
|
||
public record BuildVersion | ||
{ | ||
public record BuildVersion | ||
{ | ||
public string FullVersion { get; init; } | ||
public string FileVersion { get; init; } | ||
public string AssemblyVersion { get; init; } | ||
} | ||
public string FullVersion { get; init; } | ||
public string FileVersion { get; init; } | ||
public string AssemblyVersion { get; init; } | ||
} |
116 changes: 54 additions & 62 deletions
116
src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs
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,82 +1,74 @@ | ||
namespace TurnerSoftware.BuildVersioning.Tool | ||
namespace TurnerSoftware.BuildVersioning.Tool; | ||
|
||
internal class BuildVersioner(IVersionDetailsProvider versionDetailsProvider) | ||
{ | ||
internal class BuildVersioner | ||
public BuildVersion GetBuildVersion(BuildVersioningOptions options) | ||
{ | ||
private IVersionDetailsProvider VersionDetailsProvider { get; } | ||
|
||
public BuildVersioner(IVersionDetailsProvider versionDetailsProvider) | ||
var versionDetails = versionDetailsProvider.GetVersionDetails(); | ||
if (versionDetails is null) | ||
{ | ||
VersionDetailsProvider = versionDetailsProvider; | ||
return null; | ||
} | ||
|
||
public BuildVersion GetBuildVersion(BuildVersioningOptions options) | ||
if (!versionDetails.IsTaggedRelease && versionDetails.PreRelease is null && options.PreReleaseFormat?.Length > 0) | ||
{ | ||
var versionDetails = VersionDetailsProvider.GetVersionDetails(); | ||
if (versionDetails is null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!versionDetails.IsTaggedRelease && versionDetails.PreRelease is null && options.PreReleaseFormat?.Length > 0) | ||
{ | ||
versionDetails = versionDetails with | ||
{ | ||
PreRelease = options.PreReleaseFormat | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
}; | ||
} | ||
|
||
if (options.BuildMetadataFormat?.Length > 0) | ||
versionDetails = versionDetails with | ||
{ | ||
versionDetails = versionDetails with | ||
{ | ||
BuildMetadata = options.BuildMetadataFormat | ||
.Replace("{CommitHash}", versionDetails.CommitHash) | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
}; | ||
} | ||
|
||
var fullVersion = FormatFullVersion(options.FullVersionFormat, versionDetails); | ||
var fileVersion = FormatVersion(options.FileVersionFormat, versionDetails); | ||
var assemblyVersion = FormatVersion(options.AssemblyVersionFormat, versionDetails); | ||
PreRelease = options.PreReleaseFormat | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
}; | ||
} | ||
|
||
return new BuildVersion | ||
if (options.BuildMetadataFormat?.Length > 0) | ||
{ | ||
versionDetails = versionDetails with | ||
{ | ||
FullVersion = fullVersion, | ||
FileVersion = fileVersion, | ||
AssemblyVersion = assemblyVersion | ||
BuildMetadata = options.BuildMetadataFormat | ||
.Replace("{CommitHash}", versionDetails.CommitHash) | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
}; | ||
} | ||
|
||
private static string FormatFullVersion(string format, VersionDetails versionDetails) | ||
var fullVersion = FormatFullVersion(options.FullVersionFormat, versionDetails); | ||
var fileVersion = FormatVersion(options.FileVersionFormat, versionDetails); | ||
var assemblyVersion = FormatVersion(options.AssemblyVersionFormat, versionDetails); | ||
|
||
return new BuildVersion | ||
{ | ||
if (string.IsNullOrEmpty(format)) | ||
{ | ||
return format; | ||
} | ||
FullVersion = fullVersion, | ||
FileVersion = fileVersion, | ||
AssemblyVersion = assemblyVersion | ||
}; | ||
} | ||
|
||
return FormatVersion(format, versionDetails) | ||
.Replace("{PreRelease}", versionDetails.PreRelease is null ? default : $"-{versionDetails.PreRelease}") | ||
.Replace("{BuildMetadata}", versionDetails.BuildMetadata is null ? default : $"+{versionDetails.BuildMetadata}"); | ||
private static string FormatFullVersion(string format, VersionDetails versionDetails) | ||
{ | ||
if (string.IsNullOrEmpty(format)) | ||
{ | ||
return format; | ||
} | ||
|
||
private static string FormatVersion(string format, VersionDetails versionDetails) | ||
{ | ||
if (string.IsNullOrEmpty(format)) | ||
{ | ||
return format; | ||
} | ||
return FormatVersion(format, versionDetails) | ||
.Replace("{PreRelease}", versionDetails.PreRelease is null ? default : $"-{versionDetails.PreRelease}") | ||
.Replace("{BuildMetadata}", versionDetails.BuildMetadata is null ? default : $"+{versionDetails.BuildMetadata}"); | ||
} | ||
|
||
var autoIncrement = versionDetails.IsTaggedRelease ? 0 : 1; | ||
return format | ||
.Replace("{Major}", versionDetails.MajorVersion.ToString()) | ||
.Replace("{Major++}", (versionDetails.MajorVersion + autoIncrement).ToString()) | ||
.Replace("{Minor}", versionDetails.MinorVersion.ToString()) | ||
.Replace("{Minor++}", (versionDetails.MinorVersion + autoIncrement).ToString()) | ||
.Replace("{Patch}", versionDetails.PatchVersion.ToString()) | ||
.Replace("{Patch++}", (versionDetails.PatchVersion + autoIncrement).ToString()) | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
.Replace("{CommitHash}", versionDetails.CommitHash ?? "NOCANDO"); | ||
private static string FormatVersion(string format, VersionDetails versionDetails) | ||
{ | ||
if (string.IsNullOrEmpty(format)) | ||
{ | ||
return format; | ||
} | ||
|
||
var autoIncrement = versionDetails.IsTaggedRelease ? 0 : 1; | ||
return format | ||
.Replace("{Major}", versionDetails.MajorVersion.ToString()) | ||
.Replace("{Major++}", (versionDetails.MajorVersion + autoIncrement).ToString()) | ||
.Replace("{Minor}", versionDetails.MinorVersion.ToString()) | ||
.Replace("{Minor++}", (versionDetails.MinorVersion + autoIncrement).ToString()) | ||
.Replace("{Patch}", versionDetails.PatchVersion.ToString()) | ||
.Replace("{Patch++}", (versionDetails.PatchVersion + autoIncrement).ToString()) | ||
.Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) | ||
.Replace("{CommitHash}", versionDetails.CommitHash ?? "NOCANDO"); | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
src/TurnerSoftware.BuildVersioning.Tool/BuildVersioningOptions.cs
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,11 +1,10 @@ | ||
namespace TurnerSoftware.BuildVersioning.Tool | ||
namespace TurnerSoftware.BuildVersioning.Tool; | ||
|
||
public record BuildVersioningOptions | ||
{ | ||
public record BuildVersioningOptions | ||
{ | ||
public string FullVersionFormat { get; init; } | ||
public string FileVersionFormat { get; init; } | ||
public string AssemblyVersionFormat { get; init; } | ||
public string PreReleaseFormat { get; init; } | ||
public string BuildMetadataFormat { get; init; } | ||
} | ||
public string FullVersionFormat { get; init; } | ||
public string FileVersionFormat { get; init; } | ||
public string AssemblyVersionFormat { get; init; } | ||
public string PreReleaseFormat { get; init; } | ||
public string BuildMetadataFormat { get; init; } | ||
} |
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
23 changes: 11 additions & 12 deletions
23
src/TurnerSoftware.BuildVersioning.Tool/IGitCommandRunner.cs
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,14 +1,13 @@ | ||
namespace TurnerSoftware.BuildVersioning.Tool | ||
namespace TurnerSoftware.BuildVersioning.Tool; | ||
|
||
public interface IGitCommandRunner | ||
{ | ||
public interface IGitCommandRunner | ||
{ | ||
/// <summary> | ||
/// Returns a result from `git describe` containing the tag name, number of commits from the tag (commit height) and a 7-character commit hash. | ||
/// </summary> | ||
/// <remarks> | ||
/// Format with tag: {tag}-{commitHeight}-{commitHash}<br /> | ||
/// Format without tag: {commitHash} | ||
/// </remarks> | ||
string GitDescribe(); | ||
} | ||
/// <summary> | ||
/// Returns a result from `git describe` containing the tag name, number of commits from the tag (commit height) and a 7-character commit hash. | ||
/// </summary> | ||
/// <remarks> | ||
/// Format with tag: {tag}-{commitHeight}-{commitHash}<br /> | ||
/// Format without tag: {commitHash} | ||
/// </remarks> | ||
string GitDescribe(); | ||
} |
9 changes: 4 additions & 5 deletions
9
src/TurnerSoftware.BuildVersioning.Tool/IVersionDetailsProvider.cs
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,6 @@ | ||
namespace TurnerSoftware.BuildVersioning.Tool | ||
namespace TurnerSoftware.BuildVersioning.Tool; | ||
|
||
public interface IVersionDetailsProvider | ||
{ | ||
public interface IVersionDetailsProvider | ||
{ | ||
VersionDetails GetVersionDetails(); | ||
} | ||
VersionDetails GetVersionDetails(); | ||
} |
Oops, something went wrong.