Skip to content

Commit

Permalink
+semver: breaking - #10 - Upgrade to support Elasticsearch v6 (#11)
Browse files Browse the repository at this point in the history
* #10
Updates library to latest elasticsearch v6 NEST libraries and upgrades supported frameworks to: net461 and netstandard2.0
  • Loading branch information
Philo authored Sep 26, 2019
1 parent 2eedaf4 commit 6644049
Show file tree
Hide file tree
Showing 37 changed files with 1,619 additions and 345 deletions.
20 changes: 20 additions & 0 deletions .cake/Artifacts-ARM.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Task("Artifacts:Copy:ARM")
.WithCriteria<Configuration>((ctx, config) => ctx.DirectoryExists("./src/arm") && ctx.GetSubDirectories("./src/arm").Any())
.IsDependentOn("Build")
.IsDependeeOf("Publish")
.Does<Configuration>(config =>
{
var artifacts = $"{config.Artifacts.Root}/arm";
EnsureDirectoryExists(artifacts);
foreach(var directory in GetSubDirectories("./src/arm"))
{
if(DirectoryExists(directory)) {
var copyFrom = directory;
var copyTo = $"{artifacts}/{directory.GetDirectoryName()}";
Information("{0} -> {1}", copyFrom, copyTo);
EnsureDirectoryExists(copyTo);
CopyDirectory(directory, copyTo);
config.Artifacts.Add(ArtifactTypeOption.Other, directory.GetDirectoryName(), directory.FullPath);
}
}
});
58 changes: 58 additions & 0 deletions .cake/Artifacts-Copy.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#load "Configuration.cake"

public static Configuration IncludeArtifactCopyTarget(this Configuration configuration, DirectoryPath sourceDirectory)
{
var copyList = new HashSet<DirectoryPath>();
if(configuration.TaskParameters.TryGetValue("Artifacts:Copy__Items", out object value) && value is HashSet<DirectoryPath>)
{
copyList = value as HashSet<DirectoryPath>;
}
else
{
configuration.TaskParameters.Add("Artifacts:Copy__Items", copyList);
}

copyList.Add(sourceDirectory);

return configuration;
}

public static bool HasArtifactCopyTargets(this Configuration configuration)
{
var copyList = new HashSet<DirectoryPath>();
if(configuration.TaskParameters.TryGetValue("Artifacts:Copy__Items", out object value) && value is HashSet<DirectoryPath>)
{
copyList = value as HashSet<DirectoryPath>;
}

return copyList.Any();
}

public static IEnumerable<DirectoryPath> GetArtifactCopyTargets(this Configuration configuration)
{
var copyList = new HashSet<DirectoryPath>();
if(configuration.TaskParameters.TryGetValue("Artifacts:Copy__Items", out object value) && value is HashSet<DirectoryPath>)
{
copyList = value as HashSet<DirectoryPath>;
}
return copyList;
}

Task("Artifacts:Copy")
.WithCriteria<Configuration>((ctx, config) => config.HasArtifactCopyTargets())
.IsDependentOn("Build")
.IsDependeeOf("Publish")
.Does<Configuration>(config =>
{
var artifacts = $"{config.Artifacts.Root}";
EnsureDirectoryExists(artifacts);
foreach(var directory in config.GetArtifactCopyTargets())
{
var copyFrom = directory;
var copyTo = $"{artifacts}/{directory.GetDirectoryName()}";
Information("{0} -> {1}", copyFrom, copyTo);
EnsureDirectoryExists(copyTo);
CopyDirectory(directory, copyTo);
config.Artifacts.Add(ArtifactTypeOption.Other, directory.GetDirectoryName(), directory.FullPath);
}
});
163 changes: 163 additions & 0 deletions .cake/Artifacts-DotNetCore-Ef.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#load "Configuration.cake"
#addin nuget:?package=Newtonsoft.Json&version=12.0.1
using Newtonsoft.Json;

public class EfMigration
{
public string Id { get; set; }
public string Name { get; set; }
public string SafeName { get; set; }
}

public class EfContext
{
public string FullName { get; set; }
public string SafeName { get; set; }
public string Name { get; set; }
public string AssemblyQualifiedName { get; set; }
}

IEnumerable<EfContext> GetAllDbContexts(DirectoryPath workingDirectory, string configuration)
{
var settings = new ProcessSettings()
{
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true
};

settings.Arguments = string.Format("ef dbcontext list --configuration {0} --json --prefix-output", configuration);
var list = Enumerable.Empty<EfContext>();

using(var process = StartAndReturnProcess("dotnet", settings))
{
process.WaitForExit();
if(process.GetExitCode() == 0)
{
try
{
var outputAsJson = string.Join(Environment.NewLine, process.GetStandardOutput().Where(l => l.StartsWith("data:")).Select(l => l.Replace("data:", "")));
list = JsonConvert.DeserializeObject<List<EfContext>>(outputAsJson);
Verbose("Found {0} Db contexts", list.Count());
}
catch(Exception exception)
{
Error("Unable to determine db context's for {0} : {1}", workingDirectory, exception.Message);
}
}
}
return list.ToList();
}

IEnumerable<EfMigration> GetMigrationsForContext(string dbContext, DirectoryPath workingDirectory, string configuration)
{
var settings = new ProcessSettings()
{
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true
};

settings.Arguments = string.Format("ef migrations list --configuration {0} --context {1} --json --prefix-output", configuration, dbContext);

var list = Enumerable.Empty<EfMigration>();
using(var process = StartAndReturnProcess("dotnet", settings))
{
process.WaitForExit();
if(process.GetExitCode() == 0)
{
try
{
var outputAsJson = string.Join(Environment.NewLine, process.GetStandardOutput().Where(l => l.StartsWith("data:")).Select(l => l.Replace("data:", "")));
list = JsonConvert.DeserializeObject<List<EfMigration>>(outputAsJson);
}
catch(Exception exception)
{
Error("Unable to determine db migration list for {0} : {1}", dbContext, exception.Message);
}
}
}
return list;
}

public static Configuration IncludeAsEfDbContext(this Configuration configuration, Func<CustomProjectParserResult, bool> includeAsEFDbContext)
{
var projects = new HashSet<CustomProjectParserResult>();
if(configuration.TaskParameters.TryGetValue("Artifacts:DotNetCore:Ef:Migration-Script", out object value) && value is HashSet<CustomProjectParserResult>)
{
projects = value as HashSet<CustomProjectParserResult>;
}
else
{
configuration.TaskParameters.Add("Artifacts:DotNetCore:Ef:Migration-Script", projects);
}

var projectsToInclude = configuration.Solution.Projects.Where(includeAsEFDbContext).ToList();

if(projectsToInclude != null && projectsToInclude.Any())
{
projects.UnionWith(projectsToInclude);
}

return configuration;
}

public static bool HasCustomEfDbContextTargets(this Configuration configuration)
{
var projectList = configuration.GetEfDbContextTargets();
return projectList?.Any() ?? false;
}

public static IEnumerable<CustomProjectParserResult> GetEfDbContextTargets(this Configuration configuration)
{
var projects = new HashSet<CustomProjectParserResult>();
if(configuration.TaskParameters.TryGetValue("Artifacts:DotNetCore:Ef:Migration-Script", out object value) && value is HashSet<CustomProjectParserResult>)
{
projects = value as HashSet<CustomProjectParserResult>;
}
return projects;
}

Task("Artifacts:DotNetCore:Ef:Migration-Script")
.IsDependentOn("Build")
.IsDependeeOf("Publish")
.Does<Configuration>(config =>
{
var efProjects = (config.HasCustomEfDbContextTargets() ? config.GetEfDbContextTargets() : config.Solution.Projects).ToList();

Information("Generating scripts for {0} projects", efProjects.Count());
foreach(var project in efProjects) {
var assemblyName = config.Solution.GetProjectName(project);
var workingDirectory = project.ProjectFilePath.GetDirectory();
var availableDbContexts = GetAllDbContexts(workingDirectory, config.Solution.BuildConfiguration).ToList();

if(availableDbContexts.Any())
{
Information("Generating scripts for {0} containing {1} contexts", assemblyName, availableDbContexts.Count);
foreach(var dbContext in availableDbContexts)
{
Information("Generating Sql Script for {0}", dbContext.SafeName);
var migrations = GetMigrationsForContext(dbContext.SafeName, workingDirectory, config.Solution.BuildConfiguration);

var sqlScript = MakeAbsolute(File($"{config.Artifacts.Root}/sql/{dbContext.SafeName}.sql"));
if(FileExists(sqlScript)) {
DeleteFile(sqlScript);
}

var settings = new ProcessSettings()
{
WorkingDirectory = workingDirectory
};

settings.Arguments = string.Format("ef migrations script -i -o {0} --configuration {1} --context {2}", sqlScript, config.Solution.BuildConfiguration, dbContext.SafeName);

using(var process = StartAndReturnProcess("dotnet", settings))
{
process.WaitForExit();
Verbose("Exit code: {0}", process.GetExitCode());
}

config.Artifacts.Add(ArtifactTypeOption.Other, sqlScript.GetFilename().ToString(), sqlScript);
}
}
}

});
16 changes: 16 additions & 0 deletions .cake/Build-DotNetCore.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#load "Configuration.cake"

Task("Build:DotNetCore")
.IsDependentOn("Restore")
.IsDependeeOf("Build")
.Does<Configuration>(config =>
{
var buildSettings = new DotNetCoreBuildSettings() {
NoRestore = true,
Configuration = config.Solution.BuildConfiguration,
NoIncremental = true,
Verbosity = DotNetCoreVerbosity.Minimal
};

DotNetCoreBuild(config.Solution.Path.ToString(), buildSettings);
});
15 changes: 15 additions & 0 deletions .cake/Build-MsBuild.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#load "Configuration.cake"

Task("Build:MsBuild")
.IsDependentOn("Restore")
.IsDependeeOf("Build")
.Does<Configuration>(config =>
{
MSBuild(config.Solution.Path.ToString(), c => c
.SetConfiguration(config.Solution.BuildConfiguration)
.SetVerbosity(Verbosity.Minimal)
.UseToolVersion(MSBuildToolVersion.VS2017)
.WithWarningsAsError()
.WithTarget("Build")
);
});
24 changes: 24 additions & 0 deletions .cake/CI-AppVeyor.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#load "Configuration.cake"

Task("CI:AppVeyor:UploadArtifacts")
.WithCriteria<Configuration>((ctx, config) => BuildSystem.IsRunningOnAppVeyor)
.IsDependentOn("Publish")
.IsDependeeOf("CI:UploadArtifacts")
.Does<Configuration>(config =>
{
foreach(var artifact in config.Artifacts) {
if(FileExists(artifact.Path)) {
BuildSystem.AppVeyor.UploadArtifact(artifact.Path, new AppVeyorUploadArtifactsSettings {
ArtifactType = artifact.Type == ArtifactTypeOption.WebDeploy ? AppVeyorUploadArtifactType.WebDeployPackage : AppVeyorUploadArtifactType.Auto
});
}
}
});

Task("CI:AppVeyor:UpdateBuildNumber")
.IsDependeeOf("CI:UpdateBuildNumber")
.WithCriteria<Configuration>((ctx, config) => AppVeyor.IsRunningOnAppVeyor)
.Does<Configuration>(config =>
{
AppVeyor.UpdateBuildVersion(config.Version.FullSemVersion +"." +AppVeyor.Environment.Build.Number);
});
34 changes: 34 additions & 0 deletions .cake/CI-Azure-DevOps.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#load "Configuration.cake"

Task("CI:VSTS:UploadArtifacts")
.WithCriteria<Configuration>((ctx, config) => BuildSystem.IsRunningOnAzurePipelinesHosted || TFBuild.IsRunningOnAzurePipelines)
.IsDependentOn("Publish")
.IsDependeeOf("CI:UploadArtifacts")
.Does<Configuration>(config =>
{
Information("Uploading artifacts from {0}", config.Artifacts.Root);
TFBuild.Commands.UploadArtifact("artifacts", config.Artifacts.Root.ToString(), "artifacts");
});

Task("CI:VSTS:UpdateBuildNumber")
.IsDependeeOf("CI:UpdateBuildNumber")
.WithCriteria<Configuration>((ctx, config) => BuildSystem.IsRunningOnAzurePipelinesHosted || TFBuild.IsRunningOnAzurePipelines)
.Does<Configuration>(config =>
{
Information(
@"Repository:
Branch: {0}
SourceVersion: {1}
Shelveset: {2}",
BuildSystem.TFBuild.Environment.Repository.Branch,
BuildSystem.TFBuild.Environment.Repository.SourceVersion,
BuildSystem.TFBuild.Environment.Repository.Shelveset
);

TFBuild.Commands.UpdateBuildNumber(config.Version.FullSemVersion);
TFBuild.Commands.SetVariable("GitVersion.Version", config.Version.Version);
TFBuild.Commands.SetVariable("GitVersion.SemVer", config.Version.SemVersion);
TFBuild.Commands.SetVariable("GitVersion.InformationalVersion", config.Version.InformationalVersion);
TFBuild.Commands.SetVariable("GitVersion.FullSemVer", config.Version.FullSemVersion);
TFBuild.Commands.SetVariable("Cake.Version", config.Version.CakeVersion);
});
14 changes: 14 additions & 0 deletions .cake/CI.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#load "CI-Azure-DevOps.cake"
#load "CI-AppVeyor.cake"

Task("CI")
.IsDependentOn("CI:UpdateBuildNumber")
.IsDependeeOf("Default")
.IsDependentOn("CI:UploadArtifacts");

Task("CI:UpdateBuildNumber")
.IsDependeeOf("CI").Does<Configuration>(config => Information("Build Number: {0}", config.Version.SemVersion));

Task("CI:UploadArtifacts")
.IsDependeeOf("CI")
.IsDependentOn("Publish");
Loading

0 comments on commit 6644049

Please sign in to comment.