feat(build): Create helpers and TagCommit step
- adjust the BaseSourceLocation to be absolute - refactor getting the PowershellModule version to Helpers.cs
This commit is contained in:
parent
69e0f824de
commit
1a8bdec589
5 changed files with 103 additions and 38 deletions
42
build/Helpers.cs
Normal file
42
build/Helpers.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Build;
|
||||
|
||||
public class Helpers
|
||||
{
|
||||
public static string GetPowershellModuleVersion(string powershelModuleOutputLocation)
|
||||
{
|
||||
var moduleVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(powershelModuleOutputLocation, "PowershellModule.dll"));
|
||||
|
||||
// It's (almost) impossible to not have a product version tag here. There is a reason why the implementation
|
||||
// returns a string? but I can't find it and I don't really care too much. If we have null return an empty string
|
||||
// and append no version to the archive bundle.
|
||||
if (moduleVersionInfo.ProductVersion == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var versionRegex = new Regex(@"(\d+\.\d+\.\d+)(?:\-?([\w\-]+)\+?(\w+)?)?");
|
||||
var match = versionRegex.Match(moduleVersionInfo.ProductVersion);
|
||||
if (match.Success)
|
||||
{
|
||||
// If we have 4 groups, we've got a version number, suffix, and commit hash, so we return the first 2 as is
|
||||
// and the commit has capped to 8 characters
|
||||
if (match.Groups.Count == 4)
|
||||
{
|
||||
return $"{match.Groups[1]}-{match.Groups[2]}+{match.Groups[3].Value.Substring(0, 8)}";
|
||||
}
|
||||
|
||||
if (match.Groups.Count == 3)
|
||||
{
|
||||
return $"{match.Groups[1]}-{match.Groups[2]}";
|
||||
}
|
||||
|
||||
return $"{match.Groups[1]}";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue