Skip to content

Commit

Permalink
chore: build script with pre-release support (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco authored Aug 25, 2020
1 parent b7715ad commit b2501ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Version>7.1.0</Version>
<VersionPrefix>7.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>Mattias Kindborg</Authors>
<Company>FantasticFiasco</Company>
<Product>MVVM Dialogs</Product>
Expand Down
8 changes: 5 additions & 3 deletions build/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var version = GetAssemblyVersion("./../Directory.Build.props");
var versionPrefix = GetVersionPrefix("./../Directory.Build.props");
var versionSuffix = GetVersionSuffix("./../Directory.Build.props");
var isTag = EnvironmentVariable("APPVEYOR_REPO_TAG");

// Unless this is a tag, this is a pre-release
if (isTag != "true")
{
var sha = EnvironmentVariable("APPVEYOR_REPO_COMMIT");
version += $"-sha-{sha}";
versionSuffix = $"sha-{sha}";
}

NuGetPack(
"./../MvvmDialogs.nuspec",
new NuGetPackSettings
{
Version = version,
Version = versionPrefix,
Suffix = versionSuffix,
Symbols = true,
ArgumentCustomization = args => args.Append("-SymbolPackageFormat snupkg")
});
Expand Down
22 changes: 16 additions & 6 deletions build/utils.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

using System.Text.RegularExpressions;

public string GetAssemblyVersion(string filePath)
public string GetVersionPrefix(string filePath)
{
var versionNumbers = FindRegexMatchesGroupsInFile(
var matches = FindRegexMatchesGroupsInFile(
new FilePath(filePath),
"<Version>(\\d+).(\\d+).(\\d+)</Version>",
"<VersionPrefix>(\\d+).(\\d+).(\\d+)</VersionPrefix>",
RegexOptions.Multiline);

var major = versionNumbers[0][1];
var minor = versionNumbers[0][2];
var patch = versionNumbers[0][3];
var major = matches[0][1];
var minor = matches[0][2];
var patch = matches[0][3];

return $"{major}.{minor}.{patch}";
}

public string GetVersionSuffix(string filePath)
{
var matches = FindRegexMatchesGroupsInFile(
new FilePath(filePath),
"<VersionSuffix>(.*)</VersionSuffix>",
RegexOptions.Multiline);

return $"{matches[0][1]}";
}

0 comments on commit b2501ca

Please sign in to comment.