diff --git a/.flubu b/.flubu new file mode 100644 index 0000000..8fe3f56 --- /dev/null +++ b/.flubu @@ -0,0 +1,2 @@ + +build/BuildScript.csproj diff --git a/.travis.yml b/.travis.yml index a18810c..9f4209b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,7 @@ mono: none # osx_image: xcode8.3 # macOS 10.12 # Run the build script + script: - - dotnet --info - - dotnet restore CAP.sln - - dotnet build CAP.sln - - dotnet test test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj \ No newline at end of file + - dotnet tool install --global FlubuCore.GlobalTool --version 4.2.8 + - flubu build test \ No newline at end of file diff --git a/CAP.sln b/CAP.sln index 453b459..fac3565 100644 --- a/CAP.sln +++ b/CAP.sln @@ -66,6 +66,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RabbitMQ.SqlServer", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka.PostgreSql", "samples\Sample.Kafka.PostgreSql\Sample.Kafka.PostgreSql.csproj", "{F1EF1D26-8A6B-403E-85B0-250DF44A4A7C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildScript", "build\BuildScript.csproj", "{F8EF381A-FE83-40B3-A63D-09D83851B0FB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -123,6 +125,14 @@ Global {58B6E829-C6C8-457C-9DD0-C600650254DF}.Debug|Any CPU.Build.0 = Debug|Any CPU {58B6E829-C6C8-457C-9DD0-C600650254DF}.Release|Any CPU.ActiveCfg = Release|Any CPU {58B6E829-C6C8-457C-9DD0-C600650254DF}.Release|Any CPU.Build.0 = Release|Any CPU + {1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Release|Any CPU.Build.0 = Release|Any CPU + {F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Release|Any CPU.Build.0 = Release|Any CPU {56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -157,10 +167,13 @@ Global {4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F} = {3A6B6931-A123-477A-9469-8B468B5385AF} {63B2A464-FBEA-42FB-8EFA-98AFA39FC920} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} {58B6E829-C6C8-457C-9DD0-C600650254DF} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} + {1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8} = {3A6B6931-A123-477A-9469-8B468B5385AF} + {F8EF381A-FE83-40B3-A63D-09D83851B0FB} = {10C0818D-9160-4B80-BB86-DDE925B64D43} {56FB261C-67AF-4715-9A46-4FA4FAB91B2C} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4} {1B0371D6-36A4-4C78-A727-8ED732FDBA1D} = {3A6B6931-A123-477A-9469-8B468B5385AF} {F6C5C676-AF05-46D5-A45D-442137B31898} = {3A6B6931-A123-477A-9469-8B468B5385AF} {F1EF1D26-8A6B-403E-85B0-250DF44A4A7C} = {3A6B6931-A123-477A-9469-8B468B5385AF} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2E70565D-94CF-40B4-BFE1-AC18D5F736AB} diff --git a/appveyor.yml b/appveyor.yml index 627f1da..07857b0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,11 +6,13 @@ environment: Cap_MySql_ConnectionStringTemplate: Server=localhost;Database={0};Uid=root;Pwd=Password12!;Allow User Variables=True;SslMode=none services: - mysql +before_build: + - ps: dotnet tool install --global FlubuCore.GlobalTool --version 4.2.8 build_script: -- ps: ./build.ps1 + - ps: flubu test: off artifacts: -- path: artifacts/packages/*.nupkg +- path: artifacts/*.nupkg deploy: provider: NuGet on: @@ -18,4 +20,4 @@ deploy: api_key: secure: PZXRBOGLyhYLP7ulHfrh6MnkqB8CstuitgbLcJr3cZkLJLLzPH0ahvuTtmhWxtR2 skip_symbols: true - artifact: /artifacts\/packages\/.+\.nupkg/ + artifact: /artifacts\/.+\.nupkg/ diff --git a/build/BuildScript.Util.cs b/build/BuildScript.Util.cs new file mode 100644 index 0000000..28842c3 --- /dev/null +++ b/build/BuildScript.Util.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BuildScript +{ + public partial class BuildScript + { + public string CreateStamp() + { + var seconds = (long)(DateTime.UtcNow - new DateTime(2017, 1, 1)).TotalSeconds; + return seconds.ToString(); + } + } +} diff --git a/build/BuildScript.Version.cs b/build/BuildScript.Version.cs new file mode 100644 index 0000000..77cbf07 --- /dev/null +++ b/build/BuildScript.Version.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using FlubuCore.Context; +using FlubuCore.Scripting.Attributes; + +namespace BuildScript +{ + [Reference("System.Xml.XmlDocument, System.Xml, Version=4.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089")] + public partial class BuildScript + { + public BuildVersion FetchBuildVersion(ITaskContext context) + { + var content = System.IO.File.ReadAllText("./build/version.props"); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(content); + + var versionMajor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMajor").InnerText; + var versionMinor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMinor").InnerText; + var versionPatch = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionPatch").InnerText; + var versionQuality = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionQuality").InnerText; + versionQuality = string.IsNullOrWhiteSpace(versionQuality) ? null : versionQuality; + + var suffix = versionQuality; + + bool isCi = false; + bool isTagged = false; + if (!context.BuildSystems().IsLocalBuild) + { + isCi = true; + //// todo use flubu build system when available. + var appveyortag = context.GetEnvironmentVariable("APPVEYOR_REPO_TAG"); + bool isTagAppveyor = !string.IsNullOrEmpty(appveyortag) && appveyortag.Equals("true", StringComparison.OrdinalIgnoreCase); + + if ((context.BuildSystems().RunningOn == BuildSystemType.AppVeyor && isTagAppveyor) || + (context.BuildSystems().RunningOn == BuildSystemType.TravisCI && string.IsNullOrWhiteSpace(context.BuildSystems().Travis().TagName))) + { + isTagged = true; + } + } + + + if (!isTagged) + { + suffix += (isCi ? "preview-" : "dv-") + CreateStamp(); + } + suffix = string.IsNullOrWhiteSpace(suffix) ? null : suffix; + + var version = new BuildVersion(int.Parse(versionMajor), int.Parse(versionMinor), int.Parse(versionPatch), versionQuality); + version.Suffix = suffix; + + return version; + } + } +} diff --git a/build/BuildScript.cs b/build/BuildScript.cs new file mode 100644 index 0000000..a3c54d7 --- /dev/null +++ b/build/BuildScript.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FlubuCore.Context; +using FlubuCore.Scripting; +using FlubuCore.Scripting.Attributes; +using GlobExpressions; + +namespace BuildScript +{ + [Include("./build/BuildVersion.cs")] + public partial class BuildScript : DefaultBuildScript + { + private const string ArtifactsDir = "./artifacts"; + + [FromArg("c|configuration")] + public string Configuration { get; set; } + + protected BuildVersion BuildVersion { get; set; } + + protected List ProjectFiles { get; set; } + + protected List TestProjectFiles { get; set; } + + protected override void ConfigureBuildProperties(IBuildPropertiesContext context) + { + context.Properties.Set(BuildProps.ProductId, "CAP"); + context.Properties.Set(BuildProps.SolutionFileName, "CAP.sln"); + context.Properties.Set(BuildProps.BuildConfiguration, string.IsNullOrEmpty(Configuration) ? "Release" : Configuration); + //// todo remove casting when new version of flubu is available + BuildVersion = FetchBuildVersion(context as ITaskContext); + Console.WriteLine(BuildVersion.Version()); + TestProjectFiles = Glob.Files("./test", "*/*.csproj", GlobOptions.MatchFullPath).Select(x => $"./test/{x}").ToList(); + ProjectFiles = Glob.Files("./src", "*/*.csproj").Select(x => $"./src/{x}").ToList(); + } + + protected override void ConfigureTargets(ITaskContext context) + { + var clean = context.CreateTarget("Clean") + .AddCoreTask(x => x.Clean() + .AddDirectoryToClean(ArtifactsDir, true)); + + var restore = context.CreateTarget("Restore") + .DependsOn(clean) + .AddCoreTask(x => x.Restore()); + + var build = context.CreateTarget("Build") + .DependsOn(restore) + .AddCoreTask(x => x.Build() + .InformationalVersion(BuildVersion.VersionWithSuffix())); + + var tests = context.CreateTarget("Tests") + .ForEach(TestProjectFiles, + (projectFile, target) => + { + target.AddCoreTask(x => x.Test() + .Project(projectFile) + .NoBuild()); + }); + + var pack = context.CreateTarget("Pack") + .ForEach(ProjectFiles, (projectFile, target) => + { + target.AddCoreTask(x => x.Pack() + .NoBuild() + .Project(projectFile) + .IncludeSymbols() + .VersionSufix(BuildVersion.Suffix) + .OutputDirectory(ArtifactsDir)); + }); + + context.CreateTarget("Default") + .SetAsDefault() + .DependsOn(clean, restore, build, tests, pack); + } + } +} diff --git a/build/BuildScript.csproj b/build/BuildScript.csproj new file mode 100644 index 0000000..75c20a0 --- /dev/null +++ b/build/BuildScript.csproj @@ -0,0 +1,12 @@ + + + + netstandard2.0 + + + + + + + + diff --git a/build/BuildVersion.cs b/build/BuildVersion.cs new file mode 100644 index 0000000..3ec26b3 --- /dev/null +++ b/build/BuildVersion.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BuildScript +{ + public class BuildVersion + { + public BuildVersion(int major, int minor, int patch, string quality) + { + Major = major; + Minor = minor; + Patch = patch; + Quality = quality; + } + + public int Major { get; set; } + + public int Minor { get; set; } + + public int Patch { get; set; } + + public string Quality { get; set; } + + public string Suffix { get; set; } + + public string VersionWithoutQuality() + { + return $"{Major}.{Minor}.{Patch}"; + } + + public string Version() + { + return VersionWithoutQuality() + (Quality == null ? string.Empty : $"-{Quality}"); + } + + public string VersionWithSuffix() + { + return Version() + (Suffix == null ? string.Empty : $"-{Suffix}"); + } + } +}