Skip to content

Commit

Permalink
Use MinVer for versioning
Browse files Browse the repository at this point in the history
- Switch to MinVer from GitVersion to make tag-based versioning simpler and reduce the build complexity.
- Fix incorrect condition for publishing to GitHub Packages for tags.
- Refactor the build script to reduce repetition.
- README tidy-up.
  • Loading branch information
martincostello committed Jun 13, 2023
1 parent bde632e commit 53e01a8
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 205 deletions.
6 changes: 0 additions & 6 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"commands": [
"dotnet-cake"
]
},
"GitVersion.Tool": {
"version": "5.12.0",
"commands": [
"dotnet-gitversion"
]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
if: |
github.event.repository.fork == false &&
(github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
startsWith(github.ref, 'refs/tags/v'))
startsWith(github.ref, 'refs/tags/'))
steps:

- name: Download packages
Expand Down
4 changes: 0 additions & 4 deletions GitVersion.yml

This file was deleted.

187 changes: 94 additions & 93 deletions README.md

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions Version.props

This file was deleted.

100 changes: 12 additions & 88 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ var configuration = Argument<string>("configuration", "Release");
//////////////////////////////////////////////////////////////////////

#addin nuget:?package=Cake.FileHelpers&version=6.0.0
#addin nuget:?package=Cake.Yaml&version=6.0.0
#addin nuget:?package=Newtonsoft.Json&version=13.0.2
#addin nuget:?package=YamlDotNet&version=12.3.1

///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
Expand All @@ -37,28 +35,10 @@ var testResultsDir = System.IO.Path.Combine(artifactsDir, Directory("test-result
// NuGet
var nupkgDestDir = System.IO.Path.Combine(artifactsDir, Directory("nuget-packages"));

// GitVersion
var gitVersionPath = ToolsExePath("GitVersion.exe");
var gitVersionConfigFilePath = "./GitVersion.yml";
Dictionary<string, object> gitVersionOutput;

// Versioning
string nugetVersion;
string assemblyVersion;
string assemblyFileVersion;

// Stryker / Mutation Testing
var strykerConfig = File("./eng/stryker-config.json");
var strykerOutput = Directory("StrykerOutput");

///////////////////////////////////////////////////////////////////////////////
// INNER CLASSES
///////////////////////////////////////////////////////////////////////////////
class GitVersionConfigYaml
{
public string NextVersion { get; set; }
}

///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -120,57 +100,6 @@ Task("__RestoreNuGetPackages")
}
});

Task("__UpdateAssemblyVersionInformation")
.Does(() =>
{
var gitVersionSettings = new ProcessSettings()
.SetRedirectStandardOutput(true)
.WithArguments(args => args.Append("gitversion"));

try
{
IEnumerable<string> outputLines;
StartProcess("dotnet", gitVersionSettings, out outputLines);

var output = string.Join("\n", outputLines);
gitVersionOutput = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(output);
}
catch
{
Information("Error reading git version information. Build may be running outside of a git repo. Falling back to version specified in " + gitVersionConfigFilePath);

string gitVersionYamlString = System.IO.File.ReadAllText(gitVersionConfigFilePath);
GitVersionConfigYaml deserialized = DeserializeYaml<GitVersionConfigYaml>(gitVersionYamlString.Replace("next-version", "NextVersion"));
string gitVersionConfig = deserialized.NextVersion;

gitVersionOutput = new Dictionary<string, object>
{
{ "NuGetVersion", gitVersionConfig + "-NotFromGitRepo" },
{ "FullSemVer", gitVersionConfig },
{ "AssemblySemVer", gitVersionConfig },
{ "Major", gitVersionConfig.Split('.')[0] },
};
}

Information("");
Information("Obtained raw version info for package versioning:");
Information("NuGetVersion -> {0}", gitVersionOutput["NuGetVersion"]);
Information("FullSemVer -> {0}", gitVersionOutput["FullSemVer"]);
Information("AssemblySemVer -> {0}", gitVersionOutput["AssemblySemVer"]);
Information("MajorMinorPatch -> {0}", gitVersionOutput["MajorMinorPatch"]);
Information("CommitsSinceVersionSource -> {0}", gitVersionOutput["CommitsSinceVersionSource"]);

nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0";
assemblyFileVersion = gitVersionOutput["MajorMinorPatch"].ToString() + "." + gitVersionOutput["CommitsSinceVersionSource"].ToString();

Information("");
Information("Mapping versioning information to:");
Information("NuGet package version -> {0}", nugetVersion);
Information("AssemblyVersion -> {0}", assemblyVersion);
Information("AssemblyFileVersion -> {0}", assemblyFileVersion);
});

Task("__BuildSolutions")
.Does(() =>
{
Expand All @@ -185,10 +114,7 @@ Task("__BuildSolutions")
NoRestore = true,
MSBuildSettings = new DotNetMSBuildSettings
{
AssemblyVersion = assemblyVersion,
FileVersion = assemblyFileVersion,
TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error,
Version = nugetVersion,
},
};

Expand Down Expand Up @@ -278,25 +204,24 @@ Task("__CreateNuGetPackages")
OutputDirectory = nupkgDestDir,
MSBuildSettings = new DotNetMSBuildSettings
{
AssemblyVersion = assemblyVersion,
FileVersion = assemblyFileVersion,
TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error,
PackageVersion = nugetVersion,
Version = nugetVersion,
},
};

Information("Building Polly.Core.{0}.nupkg", nugetVersion);
DotNetPack(System.IO.Path.Combine(srcDir, "Polly.Core", "Polly.Core.csproj"), dotNetPackSettings);

Information("Building Polly.{0}.nupkg", nugetVersion);
DotNetPack(System.IO.Path.Combine(srcDir, "Polly", "Polly.csproj"), dotNetPackSettings);
var packages = new[]
{
System.IO.Path.Combine(srcDir, "Polly.Core", "Polly.Core.csproj"),
System.IO.Path.Combine(srcDir, "Polly", "Polly.csproj"),
System.IO.Path.Combine(srcDir, "Polly.RateLimiting", "Polly.RateLimiting.csproj"),
System.IO.Path.Combine(srcDir, "Polly.Extensions", "Polly.Extensions.csproj"),
};

Information("Building Polly.RateLimiting.{0}.nupkg", nugetVersion);
DotNetPack(System.IO.Path.Combine(srcDir, "Polly.RateLimiting", "Polly.RateLimiting.csproj"), dotNetPackSettings);
Information("Building NuGet packages");

Information("Building Polly.Extensions.{0}.nupkg", nugetVersion);
DotNetPack(System.IO.Path.Combine(srcDir, "Polly.Extensions", "Polly.Extensions.csproj"), dotNetPackSettings);
foreach (string project in packages)
{
DotNetPack(project, dotNetPackSettings);
}
});

//////////////////////////////////////////////////////////////////////
Expand All @@ -306,7 +231,6 @@ Task("__CreateNuGetPackages")
Task("Build")
.IsDependentOn("__Clean")
.IsDependentOn("__RestoreNuGetPackages")
.IsDependentOn("__UpdateAssemblyVersionInformation")
.IsDependentOn("__BuildSolutions")
.IsDependentOn("__RunTests")
.IsDependentOn("__RunMutationTests")
Expand Down
2 changes: 0 additions & 2 deletions eng/Benchmark.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Project>

<Import Project="..\Version.props" />

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>
Expand Down
18 changes: 17 additions & 1 deletion eng/Library.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project>
<Import Project="..\Version.props" />

<PropertyGroup>
<Company>App vNext</Company>
Expand Down Expand Up @@ -59,4 +58,21 @@
<InternalsVisibleTo Include="%(InternalsVisibleToTest.Identity)$(PollyPublicKeySuffix)" />
</ItemGroup>
</Target>

<ItemGroup Label="MinVer">
<PackageReference Include="MinVer" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Label="MinVer">
<MinVerMinimumMajorMinor>8.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<Target Name="CustomizeVersions" AfterTargets="MinVer" Condition="'$(GITHUB_ACTIONS)' == 'true'">
<PropertyGroup>
<FileVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).$(GITHUB_RUN_NUMBER)</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="$(GITHUB_REF.StartsWith(`refs/pull/`))">
<PackageVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch)-pr.$(GITHUB_REF_NAME.Replace(`/merge`, ``)).$(GITHUB_RUN_NUMBER)</PackageVersion>
</PropertyGroup>
</Target>
</Project>
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="ReportGenerator" Version="5.1.22" />
Expand All @@ -38,4 +39,4 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
</ItemGroup>
</Project>
</Project>

0 comments on commit 53e01a8

Please sign in to comment.