changes suggest by mr mash

This commit is contained in:
TomPallister 2017-03-11 09:13:50 +00:00
parent 490de4c45d
commit efec217cab
2 changed files with 67 additions and 95 deletions

View File

@ -7,20 +7,22 @@
// compile // compile
var compileConfig = Argument("configuration", "Release"); var compileConfig = Argument("configuration", "Release");
var projectJson = "./src/Ocelot/project.json"; var slnFile = "./Ocelot.sln";
// build artifacts // build artifacts
var artifactsDir = Directory("artifacts"); var artifactsDir = Directory("artifacts");
// unit testing // unit testing
var artifactsForUnitTestsDir = artifactsDir + Directory("UnitTests"); var artifactsForUnitTestsDir = artifactsDir + Directory("UnitTests");
var unitTestAssemblies = @"./test/Ocelot.UnitTests"; var unitTestAssemblies = @"./test/Ocelot.UnitTests/Ocelot.UnitTests.csproj";
// acceptance testing // acceptance testing
var artifactsForAcceptanceTestsDir = artifactsDir + Directory("AcceptanceTests"); var artifactsForAcceptanceTestsDir = artifactsDir + Directory("AcceptanceTests");
var acceptanceTestAssemblies = @"./test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj";
// integration testing // integration testing
var artifactsForIntegrationTestsDir = artifactsDir + Directory("IntegrationTests"); var artifactsForIntegrationTestsDir = artifactsDir + Directory("IntegrationTests");
var integrationTestAssemblies = @"./test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj";
// benchmark testing // benchmark testing
var artifactsForBenchmarkTestsDir = artifactsDir + Directory("BenchmarkTests"); var artifactsForBenchmarkTestsDir = artifactsDir + Directory("BenchmarkTests");
@ -81,13 +83,12 @@ Task("Version")
{ {
versioning = GetNuGetVersionForCommit(); versioning = GetNuGetVersionForCommit();
var nugetVersion = versioning.NuGetVersion; var nugetVersion = versioning.NuGetVersion;
Information("SemVer version number: " + nugetVersion); Information("SemVer version number: " + nugetVersion);
if (AppVeyor.IsRunningOnAppVeyor) if (AppVeyor.IsRunningOnAppVeyor)
{ {
Information("Persisting version number..."); Information("Persisting version number...");
PersistVersion(committedVersion, nugetVersion); PersistVersion(nugetVersion);
buildVersion = nugetVersion; buildVersion = nugetVersion;
} }
else else
@ -101,102 +102,76 @@ Task("Restore")
.IsDependentOn("Version") .IsDependentOn("Version")
.Does(() => .Does(() =>
{ {
DotNetCoreRestore("./src"); DotNetCoreRestore(slnFile);
DotNetCoreRestore("./test");
}); });
Task("RunUnitTests") Task("Compile")
.IsDependentOn("Restore") .IsDependentOn("Restore")
.Does(() => .Does(() =>
{ {
var buildSettings = new DotNetCoreTestSettings var settings = new DotNetCoreBuildSettings
{
Configuration = compileConfig,
};
DotNetCoreBuild(slnFile, settings);
});
Task("RunUnitTests")
.IsDependentOn("Compile")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{ {
Configuration = compileConfig, Configuration = compileConfig,
}; };
EnsureDirectoryExists(artifactsForUnitTestsDir); EnsureDirectoryExists(artifactsForUnitTestsDir);
DotNetCoreTest(unitTestAssemblies, buildSettings); DotNetCoreTest(unitTestAssemblies, settings);
}); });
Task("RunAcceptanceTests") Task("RunAcceptanceTests")
.IsDependentOn("Restore") .IsDependentOn("Compile")
.Does(() => .Does(() =>
{ {
var buildSettings = new DotNetCoreTestSettings var settings = new DotNetCoreTestSettings
{
Configuration = "Debug", //acceptance test config is hard-coded for debug
};
EnsureDirectoryExists(artifactsForAcceptanceTestsDir);
DoInDirectory("test/Ocelot.AcceptanceTests", () =>
{
DotNetCoreTest(".", buildSettings);
});
});
Task("RunIntegrationTests")
.IsDependentOn("Restore")
.Does(() =>
{
var buildSettings = new DotNetCoreTestSettings
{
Configuration = "Debug", //int test config is hard-coded for debug
};
EnsureDirectoryExists(artifactsForIntegrationTestsDir);
DoInDirectory("test/Ocelot.IntegrationTests", () =>
{
DotNetCoreTest(".", buildSettings);
});
});
Task("RunBenchmarkTests")
.IsDependentOn("Restore")
.Does(() =>
{
var buildSettings = new DotNetCoreRunSettings
{ {
Configuration = compileConfig, Configuration = compileConfig,
}; };
EnsureDirectoryExists(artifactsForBenchmarkTestsDir); EnsureDirectoryExists(artifactsForAcceptanceTestsDir);
DotNetCoreTest(acceptanceTestAssemblies, settings);
DoInDirectory(benchmarkTestAssemblies, () =>
{
DotNetCoreRun(".", "", buildSettings);
}); });
Task("RunIntegrationTests")
.IsDependentOn("Compile")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = compileConfig,
};
EnsureDirectoryExists(artifactsForIntegrationTestsDir);
DotNetCoreTest(integrationTestAssemblies, settings);
}); });
Task("RunTests") Task("RunTests")
.IsDependentOn("RunUnitTests") .IsDependentOn("RunUnitTests")
.IsDependentOn("RunAcceptanceTests") .IsDependentOn("RunAcceptanceTests")
.IsDependentOn("RunIntegrationTests") .IsDependentOn("RunIntegrationTests");
.Does(() =>
{
});
Task("CreatePackages") Task("CreatePackages")
.IsDependentOn("Compile")
.Does(() => .Does(() =>
{ {
EnsureDirectoryExists(packagesDir); EnsureDirectoryExists(packagesDir);
CopyFiles("./src/**/Ocelot.*.nupkg", packagesDir);
GenerateReleaseNotes(releaseNotesFile); GenerateReleaseNotes();
var settings = new DotNetCorePackSettings
{
OutputDirectory = packagesDir,
NoBuild = true
};
DotNetCorePack(projectJson, settings);
System.IO.File.WriteAllLines(artifactsFile, new[]{ System.IO.File.WriteAllLines(artifactsFile, new[]{
"nuget:Ocelot." + buildVersion + ".nupkg", "nuget:Ocelot." + buildVersion + ".nupkg",
"nugetSymbols:Ocelot." + buildVersion + ".symbols.nupkg",
"releaseNotes:releasenotes.md" "releaseNotes:releasenotes.md"
}); });
@ -215,9 +190,9 @@ Task("ReleasePackagesToUnstableFeed")
.IsDependentOn("CreatePackages") .IsDependentOn("CreatePackages")
.Does(() => .Does(() =>
{ {
if (ShouldPublishToUnstableFeed(nugetFeedUnstableBranchFilter, versioning.BranchName)) if (ShouldPublishToUnstableFeed())
{ {
PublishPackages(packagesDir, artifactsFile, nugetFeedUnstableKey, nugetFeedUnstableUploadUrl, nugetFeedUnstableSymbolsUploadUrl); PublishPackages(nugetFeedUnstableKey, nugetFeedUnstableUploadUrl, nugetFeedUnstableSymbolsUploadUrl);
} }
}); });
@ -270,7 +245,7 @@ Task("ReleasePackagesToStableFeed")
.IsDependentOn("DownloadGitHubReleaseArtifacts") .IsDependentOn("DownloadGitHubReleaseArtifacts")
.Does(() => .Does(() =>
{ {
PublishPackages(packagesDir, artifactsFile, nugetFeedStableKey, nugetFeedStableUploadUrl, nugetFeedStableSymbolsUploadUrl); PublishPackages(nugetFeedStableKey, nugetFeedStableUploadUrl, nugetFeedStableSymbolsUploadUrl);
}); });
Task("Release") Task("Release")
@ -290,43 +265,37 @@ private GitVersion GetNuGetVersionForCommit()
} }
/// Updates project version in all of our projects /// Updates project version in all of our projects
private void PersistVersion(string committedVersion, string newVersion) private void PersistVersion(string version)
{ {
Information(string.Format("We'll search all project.json files for {0} and replace with {1}...", committedVersion, newVersion)); Information(string.Format("We'll search all csproj files for {0} and replace with {1}...", committedVersion, version));
var projectJsonFiles = GetFiles("./**/project.json"); var projectFiles = GetFiles("./**/*.csproj");
foreach(var projectJsonFile in projectJsonFiles) foreach(var projectFile in projectFiles)
{ {
var file = projectJsonFile.ToString(); var file = projectFile.ToString();
Information(string.Format("Updating {0}...", file)); Information(string.Format("Updating {0}...", file));
var updatedProjectJson = System.IO.File.ReadAllText(file) var updatedProjectFile = System.IO.File.ReadAllText(file)
.Replace(committedVersion, newVersion); .Replace(committedVersion, version);
System.IO.File.WriteAllText(file, updatedProjectJson); System.IO.File.WriteAllText(file, updatedProjectFile);
} }
} }
/// generates release notes based on issues closed in GitHub since the last release /// generates release notes based on issues closed in GitHub since the last release
private void GenerateReleaseNotes(ConvertableFilePath file) private void GenerateReleaseNotes()
{ {
if (!IsRunningOnWindows()) Information("Generating release notes at " + releaseNotesFile);
{
Warning("We can't generate release notes as we're not running on Windows.");
return;
}
Information("Generating release notes at " + file);
var releaseNotesExitCode = StartProcess( var releaseNotesExitCode = StartProcess(
@"tools/GitReleaseNotes/tools/gitreleasenotes.exe", @"tools/GitReleaseNotes/tools/gitreleasenotes.exe",
new ProcessSettings { Arguments = ". /o " + file }); new ProcessSettings { Arguments = ". /o " + releaseNotesFile });
if (string.IsNullOrEmpty(System.IO.File.ReadAllText(file))) if (string.IsNullOrEmpty(System.IO.File.ReadAllText(releaseNotesFile)))
{ {
System.IO.File.WriteAllText(file, "No issues closed since last release"); System.IO.File.WriteAllText(releaseNotesFile, "No issues closed since last release");
} }
if (releaseNotesExitCode != 0) if (releaseNotesExitCode != 0)
@ -336,7 +305,7 @@ private void GenerateReleaseNotes(ConvertableFilePath file)
} }
/// Publishes code and symbols packages to nuget feed, based on contents of artifacts file /// Publishes code and symbols packages to nuget feed, based on contents of artifacts file
private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFilePath artifactsFile, string feedApiKey, string codeFeedUrl, string symbolFeedUrl) private void PublishPackages(string feedApiKey, string codeFeedUrl, string symbolFeedUrl)
{ {
var artifacts = System.IO.File var artifacts = System.IO.File
.ReadAllLines(artifactsFile) .ReadAllLines(artifactsFile)
@ -345,7 +314,6 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi
var codePackage = packagesDir + File(artifacts["nuget"]); var codePackage = packagesDir + File(artifacts["nuget"]);
Information("Pushing package " + codePackage);
NuGetPush( NuGetPush(
codePackage, codePackage,
new NuGetPushSettings { new NuGetPushSettings {
@ -372,17 +340,17 @@ private string GetResource(string url)
} }
} }
private bool ShouldPublishToUnstableFeed(string filter, string branchName) private bool ShouldPublishToUnstableFeed()
{ {
var regex = new System.Text.RegularExpressions.Regex(filter); var regex = new System.Text.RegularExpressions.Regex(nugetFeedUnstableBranchFilter);
var publish = regex.IsMatch(branchName); var publish = regex.IsMatch(versioning.BranchName);
if (publish) if (publish)
{ {
Information("Branch " + branchName + " will be published to the unstable feed"); Information("Branch " + versioning.BranchName + " will be published to the unstable feed");
} }
else else
{ {
Information("Branch " + branchName + " will not be published to the unstable feed"); Information("Branch " + versioning.BranchName + " will not be published to the unstable feed");
} }
return publish; return publish;
} }

View File

@ -5,15 +5,19 @@
<AssemblyTitle>Ocelot</AssemblyTitle> <AssemblyTitle>Ocelot</AssemblyTitle>
<VersionPrefix>0.0.0-dev</VersionPrefix> <VersionPrefix>0.0.0-dev</VersionPrefix>
<TargetFramework>netcoreapp1.1</TargetFramework> <TargetFramework>netcoreapp1.1</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<AssemblyName>Ocelot</AssemblyName> <AssemblyName>Ocelot</AssemblyName>
<PackageId>Ocelot</PackageId> <PackageId>Ocelot</PackageId>
<PackageTags>API Gateway;.NET core</PackageTags> <PackageTags>API Gateway;.NET core</PackageTags>
<PackageProjectUrl>https://github.com/TomPallister/Ocelot</PackageProjectUrl>
<PackageProjectUrl>https://github.com/TomPallister/Ocelot</PackageProjectUrl> <PackageProjectUrl>https://github.com/TomPallister/Ocelot</PackageProjectUrl>
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64</RuntimeIdentifiers> <RuntimeIdentifiers>win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64</RuntimeIdentifiers>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion> <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Authors>Tom Pallister</Authors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>