From 51afa0127d0f01ffcae8bd08ada91535568518c0 Mon Sep 17 00:00:00 2001 From: Marko Zorec Date: Sat, 21 Dec 2019 03:35:29 +0100 Subject: [PATCH] Adds Flubu build script (#421) --- .flubu | 2 + .travis.yml | 7 ++-- CAP.sln | 13 ++++++ appveyor.yml | 8 ++-- build/BuildScript.Util.cs | 15 +++++++ build/BuildScript.Version.cs | 57 ++++++++++++++++++++++++++ build/BuildScript.cs | 77 ++++++++++++++++++++++++++++++++++++ build/BuildScript.csproj | 12 ++++++ build/BuildVersion.cs | 42 ++++++++++++++++++++ 9 files changed, 226 insertions(+), 7 deletions(-) create mode 100644 .flubu create mode 100644 build/BuildScript.Util.cs create mode 100644 build/BuildScript.Version.cs create mode 100644 build/BuildScript.cs create mode 100644 build/BuildScript.csproj create mode 100644 build/BuildVersion.cs diff --git a/.flubu b/.flubu new file mode 100644 index 000000000..8fe3f5674 --- /dev/null +++ b/.flubu @@ -0,0 +1,2 @@ + +build/BuildScript.csproj diff --git a/.travis.yml b/.travis.yml index a18810c35..9f4209bd9 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 453b459a2..fac3565fa 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 627f1dac8..07857b00b 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 000000000..28842c396 --- /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 000000000..77cbf073d --- /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 000000000..a3c54d71f --- /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 000000000..75c20a0f1 --- /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 000000000..3ec26b3c1 --- /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}"); + } + } +}