Skip to content

Commit

Permalink
- Update Polly dependency to latest.
Browse files Browse the repository at this point in the history
- Consolidate solution and modernise build.
- Add SourceLink support.
- Add NetStandard 2.1 target (for .NET Core3.0 consumption)
- Add test runs in netcoreapp3.0; .NET Framework 4.6.1; and .NET Framework 4.7.2
- Update FluentAssertions and xUnit dependencies
- Remove duplicated test cases
  • Loading branch information
reisenberger committed Nov 13, 2019
1 parent 00a9202 commit ed8e03a
Show file tree
Hide file tree
Showing 43 changed files with 250 additions and 520 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Polly.Caching.Distributed change log

## 3.0.1
- No functional changes
- Updated Polly dependency to latest, v7.1.1
- Consolidated solution and fixed build
- Add SourceLink support
- Added NetStandard 2.1 target (for .NET Core3.0 consumption)
- Added test runs in netcoreapp3.0; .NET Framework 4.6.1; and .NET Framework 4.7.2
- Updated FluentAssertions and xUnit dependencies

## 3.0.0
- Allow caching of `default(TResult)`
- Compatible with Polly >= v7
Expand Down
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 3.0.0
next-version: 3.0.1
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Polly.Caching.Distributed

This repo contains the `Microsoft.Extensions.Caching.Distributed.IDistributedCache` provider for the [Polly](https://github.com/App-vNext/Polly) [Cache policy](https://github.com/App-vNext/Polly/wiki/Cache). The current version targets .NET Standard 1.1 and .NET Standard 2.0.
This repo contains the `Microsoft.Extensions.Caching.Distributed.IDistributedCache` provider for the [Polly](https://github.com/App-vNext/Polly) [Cache policy](https://github.com/App-vNext/Polly/wiki/Cache). The current version targets .NET Standard 1.1, .NET Standard 2.0 and .NET Standard 2.1.

[![NuGet version](https://badge.fury.io/nu/Polly.Caching.Distributed.svg)](https://badge.fury.io/nu/Polly.Caching.Distributed) [![Build status](https://ci.appveyor.com/api/projects/status/pgd89nfdr9u4ig8m?svg=true)](https://ci.appveyor.com/project/joelhulen/polly-caching-Distributed) [![Slack Status](http://www.pollytalk.org/badge.svg)](http://www.pollytalk.org)

## What is Polly?

[Polly](https://github.com/App-vNext/Polly) is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner. Polly targets .NET Standard 1.1 and .NET Standard 2.0.
[Polly](https://github.com/App-vNext/Polly) is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, Cache aside and Fallback in a fluent and thread-safe manner.

Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/about).

Expand All @@ -24,24 +24,27 @@ This project, Polly.Caching.Distributed, allows you to use Polly's `CachePolicy`

# Supported targets

Polly.Caching.Distributed supports .NET Standard 1.1 and .NET Standard 2.0.
Polly.Caching.Distributed >= v3.0.1 supports .NET Standard 1.1, .NET Standard 2.0 and .NET Standard 2.1.

## Versions and Dependencies
Polly.Caching.Distributed < v3.0.1 supports .NET Standard 1.1 and .NET Standard 2.0.

Polly.Caching.Distributed >=v3.0 requires:
## Dependency compatibility with Polly

Polly.Caching.Distributed >=v3.0.1 requires:

+ [Polly](https://nuget.org/packages/polly) >= v7.1.1.

Polly.Caching.Distributed v3.0.0 requires:

+ [Polly](https://nuget.org/packages/polly) >= v7.0.0.
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.

Polly.Caching.Distributed >=v2.0 and <v3 requires:

+ [Polly](https://nuget.org/packages/polly) >= v6.0.1 and <v7.
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v2.0.2 or above.

Polly.Caching.IDistributedCache <v2.0 requires:

+ [Polly](https://nuget.org/packages/polly) v5.4.0 or above.
+ [Microsoft.Extensions.Caching.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Caching.Abstractions/) v1.1.2 or above.


# How to use the Polly.Caching.Distributed plugin
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
os: Visual Studio 2017
image: Visual Studio 2019

# Build script
build_script:
Expand All @@ -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
151 changes: 60 additions & 91 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,61 @@ var configuration = Argument<string>("configuration", "Release");

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

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

#addin "Cake.FileHelpers"
#addin nuget:?package=Cake.Yaml
#addin nuget:?package=YamlDotNet&version=5.2.1

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

var projectName = "Polly.Caching.Distributed";
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
///////////////////////////////////////////////////////////////////////////////

Setup(_ =>
{
// ASCII art via: http://patorjk.com/software/taag/?#p=display&f=Graceful&t=Polly.Caching.Distributed%0A
Information("");
Information(@"");
Information(@" ____ __ __ __ _ _ ___ __ ___ _ _ __ __ _ ___ ____ __ ____ ____ ____ __ ____ _ _ ____ ____ ____ ");
Information(@"( _ \ / \ ( ) ( ) ( \/ ) / __) / _\ / __)/ )( \( )( ( \ / __) ( \( )/ ___)(_ _)( _ \( )( _ \/ )( \(_ _)( __)( \");
Information(@" ) __/( O )/ (_/\/ (_/\ ) /_( (__ / \( (__ ) __ ( )( / /( (_ \ _ ) D ( )( \___ \ )( ) / )( ) _ () \/ ( )( ) _) ) D (");
Information(@"(__) \__/ \____/\____/(__/(_)\___)\_/\_/ \___)\_)(_/(__)\_)__) \___/(_)(____/(__)(____/ (__) (__\_)(__)(____/\____/ (__) (____)(____/");
Information("----------------------------------------");
Information("Starting the cake build script");
Information("Building: " + projectName);
Information("----------------------------------------");
Information("");
});

Expand All @@ -90,7 +82,6 @@ Task("__Clean")
.Does(() =>
{
DirectoryPath[] cleanDirectories = new DirectoryPath[] {
buildDir,
testResultsDir,
nupkgDestDir,
artifactsDir
Expand All @@ -103,8 +94,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 @@ -114,7 +104,7 @@ Task("__RestoreNugetPackages")
foreach(var solution in solutions)
{
Information("Restoring NuGet Packages for {0}", solution);
NuGetRestore(solution);
DotNetCoreRestore(solution.ToString());
}
});

Expand All @@ -124,13 +114,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 = 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;

var output = string.Join("\n", outputLines);
gitVersionOutput = Newtonsoft.Json.JsonConvert.DeserializeObject<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 @@ -159,24 +165,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 @@ -196,13 +200,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 @@ -217,54 +222,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 @@ -279,8 +250,6 @@ Task("Build")
.IsDependentOn("__UpdateAppVeyorBuildNumber")
.IsDependentOn("__BuildSolutions")
.IsDependentOn("__RunTests")
.IsDependentOn("__CopyOutputToNugetFolder")
.IsDependentOn("__StronglySignAssemblies")
.IsDependentOn("__CreateSignedNugetPackage");

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -301,6 +270,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;
}
7 changes: 7 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\Polly.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
</Project>
12 changes: 0 additions & 12 deletions src/GlobalAssemblyInfo.cs

This file was deleted.

Loading

0 comments on commit ed8e03a

Please sign in to comment.