Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
v3.0.0: Reference Polly v7.1.0; rationalise solution layout; modernis…
Browse files Browse the repository at this point in the history
…e build; add SourceLink.
  • Loading branch information
reisenberger committed Mar 31, 2019
1 parent 34936cf commit 69fd292
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 416 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.0.0
- Version compatible with ASPNET Core 3.0 and Polly v7.1.0
- Add SourceLink support
- Rationalise solution layout

## 2.0.1
- Version 2 RTM, for integration to ASPNET Core 2.1 IHttpClientFactory

Expand Down
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 2.0.1
next-version: 3.0.0
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test: off

artifacts:
- path: artifacts\nuget-package\*.nupkg
- path: artifacts\nuget-package\*.snupkg

environment:
# Skip dotnet package caching on build servers
Expand Down
141 changes: 56 additions & 85 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,51 @@ var configuration = Argument<string>("configuration", "Release");

#Tool "xunit.runner.console"
#Tool "GitVersion.CommandLine"
#Tool "Brutal.Dev.StrongNameSigner"

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET LIBRARIES
//////////////////////////////////////////////////////////////////////

#addin "Cake.FileHelpers"
#addin "System.Text.Json"
#addin nuget:?package=Cake.Yaml
#addin nuget:?package=YamlDotNet&version=5.2.1
using System.Text.Json;

///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////

var projectName = "Polly.Extensions.Http";
var keyName = "Polly.snk";

var solutions = GetFiles("./**/*.sln");
var solutionPaths = solutions.Select(solution => solution.GetDirectory());

var srcDir = Directory("./src");
var buildDir = Directory("./build");
var artifactsDir = Directory("./artifacts");
var testResultsDir = artifactsDir + Directory("test-results");

// NuGet
var nuspecExtension = ".nuspec";
var nuspecFolder = "nuget-package";
var nuspecSrcFile = srcDir + File(projectName + nuspecExtension);
var nuspecDestFile = buildDir + File(projectName + nuspecExtension);
var nupkgDestDir = artifactsDir + Directory(nuspecFolder);
var snkFile = srcDir + File(keyName);

var projectToNugetFolderMap = new Dictionary<string, string[]>() {
{ "NetStandard11", new [] {"netstandard1.1"} },
{ "NetStandard20", new [] {"netstandard2.0"} },
};
var nupkgDestDir = artifactsDir + Directory("nuget-package");

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

// Versioning
string nugetVersion;
string appveyorBuildNumber;
string assemblyVersion;
string assemblySemver;

// StrongNameSigner
var strongNameSignerPath = ToolsExePath("StrongNameSigner.Console.exe");

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

///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
Expand Down Expand Up @@ -91,7 +85,6 @@ Task("__Clean")
.Does(() =>
{
DirectoryPath[] cleanDirectories = new DirectoryPath[] {
buildDir,
testResultsDir,
nupkgDestDir,
artifactsDir
Expand All @@ -104,8 +97,7 @@ Task("__Clean")
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
DotNetCoreClean(path.ToString());
}
});

Expand All @@ -115,7 +107,7 @@ Task("__RestoreNugetPackages")
foreach(var solution in solutions)
{
Information("Restoring NuGet Packages for {0}", solution);
NuGetRestore(solution);
DotNetCoreRestore(solution.ToString());
}
});

Expand All @@ -125,13 +117,29 @@ Task("__UpdateAssemblyVersionInformation")
var gitVersionSettings = new ProcessSettings()
.SetRedirectStandardOutput(true);

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

var output = string.Join("\n", outputLines);
gitVersionOutput = new JsonParser().Parse<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;

var output = string.Join("\n", outputLines);
gitVersionOutput = new JsonParser().Parse<Dictionary<string, object>>(output);
gitVersionOutput = new Dictionary<string, object>{
{ "NuGetVersion", gitVersionConfig + "-NotFromGitRepo" },
{ "FullSemVer", gitVersionConfig },
{ "AssemblySemVer", gitVersionConfig },
{ "Major", gitVersionConfig.Split('.')[0] },
};

Information("Updated GlobalAssemblyInfo");
}

Information("");
Information("Obtained raw version info for package versioning:");
Expand Down Expand Up @@ -160,24 +168,22 @@ Task("__UpdateDotNetStandardAssemblyVersionNumber")

var attributeToValueMap = new Dictionary<string, string>() {
{ "AssemblyVersion", assemblyVersion },
{ "AssemblyFileVersion", assemblySemver },
{ "AssemblyInformationalVersion", assemblySemver },
{ "FileVersion", assemblySemver },
{ "InformationalVersion", assemblySemver },
{ "Version", nugetVersion },
{ "PackageVersion", nugetVersion },
};

var assemblyInfosToUpdate = GetFiles("./src/**/Properties/AssemblyInfo.cs")
.Select(f => f.FullPath)
.Where(f => !f.Contains("Specs"));
var csproj = File("./src/" + projectName + "/" + projectName + ".csproj");

foreach(var attributeMap in attributeToValueMap) {
var attribute = attributeMap.Key;
var value = attributeMap.Value;

foreach(var assemblyInfo in assemblyInfosToUpdate) {
var replacedFiles = ReplaceRegexInFiles(assemblyInfo, attribute + "[(]\".*\"[)]", attribute + "(\"" + value +"\")");
if (!replacedFiles.Any())
{
throw new Exception($"{attribute} attribute could not be updated in {assemblyInfo}.");
}
var replacedFiles = ReplaceRegexInFiles(csproj, $@"\<{attribute}\>[^\<]*\</{attribute}\>", $@"<{attribute}>{value}</{attribute}>");
if (!replacedFiles.Any())
{
throw new Exception($"{attribute} version could not be updated in {csproj}.");
}
}

Expand All @@ -197,13 +203,14 @@ Task("__BuildSolutions")
{
Information("Building {0}", solution);

MSBuild(solution, settings =>
settings
.SetConfiguration(configuration)
.WithProperty("TreatWarningsAsErrors", "true")
.UseToolVersion(MSBuildToolVersion.VS2017)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false));
var dotNetCoreBuildSettings = new DotNetCoreBuildSettings {
Configuration = configuration,
Verbosity = DotNetCoreVerbosity.Minimal,
NoRestore = true,
MSBuildSettings = new DotNetCoreMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error }
};

DotNetCoreBuild(solution.ToString(), dotNetCoreBuildSettings);
}
});

Expand All @@ -218,54 +225,20 @@ Task("__RunTests")
}
});

Task("__CopyOutputToNugetFolder")
.Does(() =>
{
foreach(var project in projectToNugetFolderMap.Keys) {
var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration);

foreach(var targetFolder in projectToNugetFolderMap[project]) {
var destDir = buildDir + Directory("lib");

Information("Copying {0} -> {1}.", sourceDir, destDir);
CopyDirectory(sourceDir, destDir);
}
}

CopyFile(nuspecSrcFile, nuspecDestFile);
});

Task("__StronglySignAssemblies")
.Does(() =>
{
//see: https://github.com/brutaldev/StrongNameSigner
var strongNameSignerSettings = new ProcessSettings()
.WithArguments(args => args
.Append("-in")
.AppendQuoted(buildDir)
.Append("-k")
.AppendQuoted(snkFile)
.Append("-l")
.AppendQuoted("Changes"));

StartProcess(strongNameSignerPath, strongNameSignerSettings);
});

Task("__CreateSignedNugetPackage")
.Does(() =>
{
var packageName = projectName;

Information("Building {0}.{1}.nupkg", packageName, nugetVersion);

var nuGetPackSettings = new NuGetPackSettings {
Id = packageName,
Title = packageName,
Version = nugetVersion,
var dotNetCorePackSettings = new DotNetCorePackSettings {
Configuration = configuration,
NoBuild = true,
OutputDirectory = nupkgDestDir
};

NuGetPack(nuspecDestFile, nuGetPackSettings);
DotNetCorePack($@"{srcDir}\{projectName}.sln", dotNetCorePackSettings);
});

//////////////////////////////////////////////////////////////////////
Expand All @@ -280,8 +253,6 @@ Task("Build")
.IsDependentOn("__UpdateAppVeyorBuildNumber")
.IsDependentOn("__BuildSolutions")
.IsDependentOn("__RunTests")
.IsDependentOn("__CopyOutputToNugetFolder")
.IsDependentOn("__StronglySignAssemblies")
.IsDependentOn("__CreateSignedNugetPackage");

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -302,6 +273,6 @@ RunTarget(target);
//////////////////////////////////////////////////////////////////////

string ToolsExePath(string exeFileName) {
var exePath = System.IO.Directory.GetFiles(@".\Tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
var exePath = System.IO.Directory.GetFiles(@"./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
return exePath;
}
12 changes: 0 additions & 12 deletions src/GlobalAssemblyInfo.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions src/Polly.Extensions.Http.NetStandard11/Properties/AssemblyInfo.cs

This file was deleted.

Loading

0 comments on commit 69fd292

Please sign in to comment.