diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d802184 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Polly.Caching.Serialization.System.Text.Json change log + +## 1.0.0 +- Initial release \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..5982916 --- /dev/null +++ b/build.bat @@ -0,0 +1,5 @@ +@ECHO OFF +PUSHD %~dp0 +PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& './build.ps1'" + +IF %errorlevel% neq 0 PAUSE \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..b67f0f3 --- /dev/null +++ b/build.cake @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// ARGUMENTS +/////////////////////////////////////////////////////////////////////////////// + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); + +////////////////////////////////////////////////////////////////////// +// EXTERNAL NUGET TOOLS +////////////////////////////////////////////////////////////////////// + +#Tool "xunit.runner.console" +#Tool "GitVersion.CommandLine" + +////////////////////////////////////////////////////////////////////// +// 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.Serialization.System.Text.Json"; + +var solutions = GetFiles("./**/*.sln"); +var solutionPaths = solutions.Select(solution => solution.GetDirectory()); + +var srcDir = Directory("./src"); +var artifactsDir = Directory("./artifacts"); +var testResultsDir = artifactsDir + Directory("test-results"); + +// NuGet +var nupkgDestDir = artifactsDir + Directory("nuget-package"); + +// Gitversion +var gitVersionPath = ToolsExePath("GitVersion.exe"); +Dictionary gitVersionOutput; +var gitVersionConfigFilePath = "./GitVersionConfig.yaml"; + +// Versioning +string nugetVersion; +string appveyorBuildNumber; +string assemblyVersion; +string assemblySemver; + +/////////////////////////////////////////////////////////////////////////////// +// INNER CLASSES +/////////////////////////////////////////////////////////////////////////////// +class GitVersionConfigYaml +{ + public string NextVersion { get; set; } +} + +/////////////////////////////////////////////////////////////////////////////// +// SETUP / TEARDOWN +/////////////////////////////////////////////////////////////////////////////// + +Setup(_ => +{ + Information(""); + Information("----------------------------------------"); + Information("Starting the cake build script"); + Information("Building: " + projectName); + Information("----------------------------------------"); + Information(""); +}); + +Teardown(_ => +{ + Information("Finished running tasks."); +}); + +////////////////////////////////////////////////////////////////////// +// PRIVATE TASKS +////////////////////////////////////////////////////////////////////// + +Task("__Clean") + .Does(() => +{ + DirectoryPath[] cleanDirectories = new DirectoryPath[] { + testResultsDir, + nupkgDestDir, + artifactsDir + }; + + CleanDirectories(cleanDirectories); + + foreach(var path in cleanDirectories) { EnsureDirectoryExists(path); } + + foreach(var path in solutionPaths) + { + Information("Cleaning {0}", path); + DotNetCoreClean(path.ToString()); + } +}); + +Task("__RestoreNugetPackages") + .Does(() => +{ + foreach(var solution in solutions) + { + Information("Restoring NuGet Packages for {0}", solution); + DotNetCoreRestore(solution.ToString()); + } +}); + +Task("__UpdateAssemblyVersionInformation") + .Does(() => +{ + var gitVersionSettings = new ProcessSettings() + .SetRedirectStandardOutput(true); + + try { + IEnumerable outputLines; + StartProcess(gitVersionPath, gitVersionSettings, out outputLines); + + var output = string.Join("\n", outputLines); + gitVersionOutput = Newtonsoft.Json.JsonConvert.DeserializeObject>(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(gitVersionYamlString.Replace("next-version", "NextVersion")); + string gitVersionConfig = deserialized.NextVersion; + + gitVersionOutput = new Dictionary{ + { "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"]); + + appveyorBuildNumber = gitVersionOutput["BranchName"].ToString().Equals("master", StringComparison.OrdinalIgnoreCase) + ? gitVersionOutput["FullSemVer"].ToString() + : gitVersionOutput["InformationalVersion"].ToString(); + nugetVersion = gitVersionOutput["NuGetVersion"].ToString(); + assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0"; + assemblySemver = gitVersionOutput["AssemblySemVer"].ToString(); + + Information(""); + Information("Mapping versioning information to:"); + Information("Appveyor build number -> {0}", appveyorBuildNumber); + Information("Nuget package version -> {0}", nugetVersion); + Information("AssemblyVersion -> {0}", assemblyVersion); + Information("AssemblyFileVersion -> {0}", assemblySemver); + Information("AssemblyInformationalVersion -> {0}", assemblySemver); +}); + +Task("__UpdateDotNetStandardAssemblyVersionNumber") + .Does(() => +{ + Information("Updating Assembly Version Information"); + + var attributeToValueMap = new Dictionary() { + { "AssemblyVersion", assemblyVersion }, + { "FileVersion", assemblySemver }, + { "InformationalVersion", assemblySemver }, + { "Version", nugetVersion }, + { "PackageVersion", nugetVersion }, + }; + + var csproj = File("./src/" + projectName + "/" + projectName + ".csproj"); + + foreach(var attributeMap in attributeToValueMap) { + var attribute = attributeMap.Key; + var value = attributeMap.Value; + + var replacedFiles = ReplaceRegexInFiles(csproj, $@"\<{attribute}\>[^\<]*\", $@"<{attribute}>{value}"); + if (!replacedFiles.Any()) + { + throw new Exception($"{attribute} version could not be updated in {csproj}."); + } + } + +}); + +Task("__UpdateAppVeyorBuildNumber") + .WithCriteria(() => AppVeyor.IsRunningOnAppVeyor) + .Does(() => +{ + AppVeyor.UpdateBuildVersion(appveyorBuildNumber); +}); + +Task("__BuildSolutions") + .Does(() => +{ + foreach(var solution in solutions) + { + Information("Building {0}", solution); + + var dotNetCoreBuildSettings = new DotNetCoreBuildSettings { + Configuration = configuration, + Verbosity = DotNetCoreVerbosity.Minimal, + NoRestore = true, + MSBuildSettings = new DotNetCoreMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error } + }; + + DotNetCoreBuild(solution.ToString(), dotNetCoreBuildSettings); + } +}); + +Task("__RunTests") + .Does(() => +{ + foreach(var specsProj in GetFiles("./src/**/*.Specs.csproj")) { + DotNetCoreTest(specsProj.FullPath, new DotNetCoreTestSettings { + Configuration = configuration, + NoBuild = true + }); + } +}); + +Task("__CreateSignedNugetPackage") + .Does(() => +{ + var packageName = projectName; + + Information("Building {0}.{1}.nupkg", packageName, nugetVersion); + + var dotNetCorePackSettings = new DotNetCorePackSettings { + Configuration = configuration, + NoBuild = true, + OutputDirectory = nupkgDestDir + }; + + DotNetCorePack($@"{srcDir}\{projectName}.sln", dotNetCorePackSettings); +}); + +////////////////////////////////////////////////////////////////////// +// BUILD TASKS +////////////////////////////////////////////////////////////////////// + +Task("Build") + .IsDependentOn("__Clean") + .IsDependentOn("__RestoreNugetPackages") + .IsDependentOn("__UpdateAssemblyVersionInformation") + .IsDependentOn("__UpdateDotNetStandardAssemblyVersionNumber") + .IsDependentOn("__UpdateAppVeyorBuildNumber") + .IsDependentOn("__BuildSolutions") + .IsDependentOn("__RunTests") + .IsDependentOn("__CreateSignedNugetPackage"); + +/////////////////////////////////////////////////////////////////////////////// +// PRIMARY TARGETS +/////////////////////////////////////////////////////////////////////////////// + +Task("Default") + .IsDependentOn("Build"); + +/////////////////////////////////////////////////////////////////////////////// +// EXECUTION +/////////////////////////////////////////////////////////////////////////////// + +RunTarget(target); + +////////////////////////////////////////////////////////////////////// +// HELPER FUNCTIONS +////////////////////////////////////////////////////////////////////// + +string ToolsExePath(string exeFileName) { + var exePath = System.IO.Directory.GetFiles(@"./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault(); + return exePath; +} \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..68d786b --- /dev/null +++ b/build.ps1 @@ -0,0 +1,132 @@ +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. + +.LINK +http://cakebuild.net +#> + +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [switch]$Verbose +) + +Write-Host "Preparing to run build script..." + +# Should we show verbose messages? +if($Verbose.IsPresent) +{ + $VerbosePreference = "continue" +} + +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NUGET_EXE +} + +# Make sure NuGet exists where we expect it. +if (!(Test-Path $NUGET_EXE)) { + Throw "Could not find NuGet.exe" +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) +{ + # Restore tools from NuGet. + Push-Location + Set-Location $TOOLS_DIR + + Write-Verbose -Message "Restoring tools from NuGet..." + + # Restore packages + if (Test-Path $PACKAGES_CONFIG) + { + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion" + Write-Verbose ($NuGetOutput | Out-String) + } + # Install just Cake if missing config + else + { + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install Cake -Version 0.25.0 -ExcludeVersion" # Pin Cake version to 0.25.0; see https://github.com/App-vNext/Polly/issues/416 + Write-Verbose ($NuGetOutput | Out-String) + } + Pop-Location + if ($LASTEXITCODE -ne 0) + { + exit $LASTEXITCODE + } +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental" +exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..6ba174c --- /dev/null +++ b/build.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +########################################################################## +# This is the Cake bootstrapper script for Linux and OS X. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe +PACKAGES_CONFIG=$TOOLS_DIR/packages.config +PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum + +# Define md5sum or md5 depending on Linux/OSX +MD5_EXE= +if [[ "$(uname -s)" == "Darwin" ]]; then + MD5_EXE="md5 -r" +else + MD5_EXE="md5sum" +fi + +# Define default arguments. +SCRIPT="build.cake" +TARGET="Default" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SHOW_VERSION=false +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --version) SHOW_VERSION=true ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +# Make sure that packages.config exist. +if [ ! -f "$TOOLS_DIR/packages.config" ]; then + echo "Downloading packages.config..." + curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages + if [ $? -ne 0 ]; then + echo "An error occurred while downloading packages.config." + exit 1 + fi +fi + +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occurred while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd "$TOOLS_DIR" >/dev/null +if [ ! -f $PACKAGES_CONFIG_MD5 ] || [ "$( cat $PACKAGES_CONFIG_MD5 | sed 's/\r$//' )" != "$( $MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' )" ]; then + find . -type d ! -name . | xargs rm -rf +fi + +mono "$NUGET_EXE" install -ExcludeVersion +if [ $? -ne 0 ]; then + echo "Could not restore NuGet packages." + exit 1 +fi + +$MD5_EXE $PACKAGES_CONFIG | awk '{ print $1 }' >| $PACKAGES_CONFIG_MD5 + +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f "$CAKE_EXE" ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + exec mono "$CAKE_EXE" -version +else + exec mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" +fi \ No newline at end of file diff --git a/src/Polly.Caching.Serialization.System.Text.Json.Specs/Polly.Caching.Serialization.System.Text.Json.Specs.csproj b/src/Polly.Caching.Serialization.System.Text.Json.Specs/Polly.Caching.Serialization.System.Text.Json.Specs.csproj index d562205..9f217e6 100644 --- a/src/Polly.Caching.Serialization.System.Text.Json.Specs/Polly.Caching.Serialization.System.Text.Json.Specs.csproj +++ b/src/Polly.Caching.Serialization.System.Text.Json.Specs/Polly.Caching.Serialization.System.Text.Json.Specs.csproj @@ -2,7 +2,7 @@ false Library - netcoreapp2.0 + net6.0 library diff --git a/src/Polly.Caching.Serialization.System.Text.Json/Polly.Caching.Serialization.System.Text.Json.csproj b/src/Polly.Caching.Serialization.System.Text.Json/Polly.Caching.Serialization.System.Text.Json.csproj index 3feb084..9445e33 100644 --- a/src/Polly.Caching.Serialization.System.Text.Json/Polly.Caching.Serialization.System.Text.Json.csproj +++ b/src/Polly.Caching.Serialization.System.Text.Json/Polly.Caching.Serialization.System.Text.Json.csproj @@ -1,29 +1,53 @@  - - Polly.Caching.Serialization.System.Text.Json - ..\Polly.snk - TRACE;DEBUG;PORTABLE;NETCOREAPP3_0 - en-US - false - true - Polly.Caching.Serialization.System.Text.Json - netstandard2.0 - 2.0.0 - - - full - - - pdbonly - true - - - - False - - - - - - + + Polly.Caching.Serialization.System.Text.Json + ..\Polly.snk + TRACE;DEBUG;PORTABLE;NETCOREAPP3_0 + en-US + false + true + Polly.Caching.Serialization.System.Text.Json + netstandard2.0 + 1.0.0 + 1.0.0.0 + 1.0.0.0 + 1.0.0.0 + 1.0.0 + App vNext + Copyright (c) $([System.DateTime]::Now.ToString(yyyy)), App vNext + Polly.Caching.Serialization.System.Text.Json is a plug-in for the .NET OSS resilience library Polly, supporting serialization to and from Json using System.Text.Json + Bryan Hogan, App vNext + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + false + 2.0.0 + + + true + true + snupkg + + + + + + full + + + pdbonly + true + + + https://raw.github.com/App-vNext/Polly/master/Polly.png + en-US + Polly.Caching.Serialization.System.Text.Json + BSD-3-Clause + https://github.com/App-vNext/Polly.Caching.Serialization.System.Text.Json + Polly Cache Caching Cache-aside serialization Json + See https://github.com/App-vNext/Polly.Caching.Serialization.System.Text.Json/blob/master/CHANGELOG.md for details + + + + + \ No newline at end of file