Skip to content

Commit 51afa01

Browse files
mzorecyang-xiaodong
authored andcommitted
Adds Flubu build script (dotnetcore#421)
1 parent f528fa3 commit 51afa01

File tree

9 files changed

+226
-7
lines changed

9 files changed

+226
-7
lines changed

.flubu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
build/BuildScript.csproj

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ mono: none
1515
# osx_image: xcode8.3 # macOS 10.12
1616

1717
# Run the build script
18+
1819
script:
19-
- dotnet --info
20-
- dotnet restore CAP.sln
21-
- dotnet build CAP.sln
22-
- dotnet test test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj
20+
- dotnet tool install --global FlubuCore.GlobalTool --version 4.2.8
21+
- flubu build test

CAP.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RabbitMQ.SqlServer",
6666
EndProject
6767
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Kafka.PostgreSql", "samples\Sample.Kafka.PostgreSql\Sample.Kafka.PostgreSql.csproj", "{F1EF1D26-8A6B-403E-85B0-250DF44A4A7C}"
6868
EndProject
69+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuildScript", "build\BuildScript.csproj", "{F8EF381A-FE83-40B3-A63D-09D83851B0FB}"
70+
EndProject
6971
Global
7072
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7173
Debug|Any CPU = Debug|Any CPU
@@ -123,6 +125,14 @@ Global
123125
{58B6E829-C6C8-457C-9DD0-C600650254DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
124126
{58B6E829-C6C8-457C-9DD0-C600650254DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
125127
{58B6E829-C6C8-457C-9DD0-C600650254DF}.Release|Any CPU.Build.0 = Release|Any CPU
128+
{1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129+
{1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
130+
{1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{F8EF381A-FE83-40B3-A63D-09D83851B0FB}.Release|Any CPU.Build.0 = Release|Any CPU
126136
{56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127137
{56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
128138
{56FB261C-67AF-4715-9A46-4FA4FAB91B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -157,10 +167,13 @@ Global
157167
{4473DE19-E8D2-4B57-80A8-C8AAA2BFA20F} = {3A6B6931-A123-477A-9469-8B468B5385AF}
158168
{63B2A464-FBEA-42FB-8EFA-98AFA39FC920} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
159169
{58B6E829-C6C8-457C-9DD0-C600650254DF} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
170+
{1E1E959C-3D0E-45C3-ABCA-DAAACE68AAB8} = {3A6B6931-A123-477A-9469-8B468B5385AF}
171+
{F8EF381A-FE83-40B3-A63D-09D83851B0FB} = {10C0818D-9160-4B80-BB86-DDE925B64D43}
160172
{56FB261C-67AF-4715-9A46-4FA4FAB91B2C} = {9B2AE124-6636-4DE9-83A3-70360DABD0C4}
161173
{1B0371D6-36A4-4C78-A727-8ED732FDBA1D} = {3A6B6931-A123-477A-9469-8B468B5385AF}
162174
{F6C5C676-AF05-46D5-A45D-442137B31898} = {3A6B6931-A123-477A-9469-8B468B5385AF}
163175
{F1EF1D26-8A6B-403E-85B0-250DF44A4A7C} = {3A6B6931-A123-477A-9469-8B468B5385AF}
176+
164177
EndGlobalSection
165178
GlobalSection(ExtensibilityGlobals) = postSolution
166179
SolutionGuid = {2E70565D-94CF-40B4-BFE1-AC18D5F736AB}

appveyor.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ environment:
66
Cap_MySql_ConnectionStringTemplate: Server=localhost;Database={0};Uid=root;Pwd=Password12!;Allow User Variables=True;SslMode=none
77
services:
88
- mysql
9+
before_build:
10+
- ps: dotnet tool install --global FlubuCore.GlobalTool --version 4.2.8
911
build_script:
10-
- ps: ./build.ps1
12+
- ps: flubu
1113
test: off
1214
artifacts:
13-
- path: artifacts/packages/*.nupkg
15+
- path: artifacts/*.nupkg
1416
deploy:
1517
provider: NuGet
1618
on:
1719
appveyor_repo_tag: true
1820
api_key:
1921
secure: PZXRBOGLyhYLP7ulHfrh6MnkqB8CstuitgbLcJr3cZkLJLLzPH0ahvuTtmhWxtR2
2022
skip_symbols: true
21-
artifact: /artifacts\/packages\/.+\.nupkg/
23+
artifact: /artifacts\/.+\.nupkg/

build/BuildScript.Util.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace BuildScript
6+
{
7+
public partial class BuildScript
8+
{
9+
public string CreateStamp()
10+
{
11+
var seconds = (long)(DateTime.UtcNow - new DateTime(2017, 1, 1)).TotalSeconds;
12+
return seconds.ToString();
13+
}
14+
}
15+
}

build/BuildScript.Version.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Xml;
5+
using FlubuCore.Context;
6+
using FlubuCore.Scripting.Attributes;
7+
8+
namespace BuildScript
9+
{
10+
[Reference("System.Xml.XmlDocument, System.Xml, Version=4.0.0.0, Culture=neutral, publicKeyToken=b77a5c561934e089")]
11+
public partial class BuildScript
12+
{
13+
public BuildVersion FetchBuildVersion(ITaskContext context)
14+
{
15+
var content = System.IO.File.ReadAllText("./build/version.props");
16+
17+
XmlDocument doc = new XmlDocument();
18+
doc.LoadXml(content);
19+
20+
var versionMajor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMajor").InnerText;
21+
var versionMinor = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionMinor").InnerText;
22+
var versionPatch = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionPatch").InnerText;
23+
var versionQuality = doc.DocumentElement.SelectSingleNode("/Project/PropertyGroup/VersionQuality").InnerText;
24+
versionQuality = string.IsNullOrWhiteSpace(versionQuality) ? null : versionQuality;
25+
26+
var suffix = versionQuality;
27+
28+
bool isCi = false;
29+
bool isTagged = false;
30+
if (!context.BuildSystems().IsLocalBuild)
31+
{
32+
isCi = true;
33+
//// todo use flubu build system when available.
34+
var appveyortag = context.GetEnvironmentVariable("APPVEYOR_REPO_TAG");
35+
bool isTagAppveyor = !string.IsNullOrEmpty(appveyortag) && appveyortag.Equals("true", StringComparison.OrdinalIgnoreCase);
36+
37+
if ((context.BuildSystems().RunningOn == BuildSystemType.AppVeyor && isTagAppveyor) ||
38+
(context.BuildSystems().RunningOn == BuildSystemType.TravisCI && string.IsNullOrWhiteSpace(context.BuildSystems().Travis().TagName)))
39+
{
40+
isTagged = true;
41+
}
42+
}
43+
44+
45+
if (!isTagged)
46+
{
47+
suffix += (isCi ? "preview-" : "dv-") + CreateStamp();
48+
}
49+
suffix = string.IsNullOrWhiteSpace(suffix) ? null : suffix;
50+
51+
var version = new BuildVersion(int.Parse(versionMajor), int.Parse(versionMinor), int.Parse(versionPatch), versionQuality);
52+
version.Suffix = suffix;
53+
54+
return version;
55+
}
56+
}
57+
}

build/BuildScript.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using FlubuCore.Context;
5+
using FlubuCore.Scripting;
6+
using FlubuCore.Scripting.Attributes;
7+
using GlobExpressions;
8+
9+
namespace BuildScript
10+
{
11+
[Include("./build/BuildVersion.cs")]
12+
public partial class BuildScript : DefaultBuildScript
13+
{
14+
private const string ArtifactsDir = "./artifacts";
15+
16+
[FromArg("c|configuration")]
17+
public string Configuration { get; set; }
18+
19+
protected BuildVersion BuildVersion { get; set; }
20+
21+
protected List<string> ProjectFiles { get; set; }
22+
23+
protected List<string> TestProjectFiles { get; set; }
24+
25+
protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
26+
{
27+
context.Properties.Set(BuildProps.ProductId, "CAP");
28+
context.Properties.Set(BuildProps.SolutionFileName, "CAP.sln");
29+
context.Properties.Set(BuildProps.BuildConfiguration, string.IsNullOrEmpty(Configuration) ? "Release" : Configuration);
30+
//// todo remove casting when new version of flubu is available
31+
BuildVersion = FetchBuildVersion(context as ITaskContext);
32+
Console.WriteLine(BuildVersion.Version());
33+
TestProjectFiles = Glob.Files("./test", "*/*.csproj", GlobOptions.MatchFullPath).Select(x => $"./test/{x}").ToList();
34+
ProjectFiles = Glob.Files("./src", "*/*.csproj").Select(x => $"./src/{x}").ToList();
35+
}
36+
37+
protected override void ConfigureTargets(ITaskContext context)
38+
{
39+
var clean = context.CreateTarget("Clean")
40+
.AddCoreTask(x => x.Clean()
41+
.AddDirectoryToClean(ArtifactsDir, true));
42+
43+
var restore = context.CreateTarget("Restore")
44+
.DependsOn(clean)
45+
.AddCoreTask(x => x.Restore());
46+
47+
var build = context.CreateTarget("Build")
48+
.DependsOn(restore)
49+
.AddCoreTask(x => x.Build()
50+
.InformationalVersion(BuildVersion.VersionWithSuffix()));
51+
52+
var tests = context.CreateTarget("Tests")
53+
.ForEach(TestProjectFiles,
54+
(projectFile, target) =>
55+
{
56+
target.AddCoreTask(x => x.Test()
57+
.Project(projectFile)
58+
.NoBuild());
59+
});
60+
61+
var pack = context.CreateTarget("Pack")
62+
.ForEach(ProjectFiles, (projectFile, target) =>
63+
{
64+
target.AddCoreTask(x => x.Pack()
65+
.NoBuild()
66+
.Project(projectFile)
67+
.IncludeSymbols()
68+
.VersionSufix(BuildVersion.Suffix)
69+
.OutputDirectory(ArtifactsDir));
70+
});
71+
72+
context.CreateTarget("Default")
73+
.SetAsDefault()
74+
.DependsOn(clean, restore, build, tests, pack);
75+
}
76+
}
77+
}

build/BuildScript.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="FlubuCore" Version="4.2.1" />
9+
<PackageReference Include="Glob" Version="1.1.3" />
10+
</ItemGroup>
11+
12+
</Project>

build/BuildVersion.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace BuildScript
6+
{
7+
public class BuildVersion
8+
{
9+
public BuildVersion(int major, int minor, int patch, string quality)
10+
{
11+
Major = major;
12+
Minor = minor;
13+
Patch = patch;
14+
Quality = quality;
15+
}
16+
17+
public int Major { get; set; }
18+
19+
public int Minor { get; set; }
20+
21+
public int Patch { get; set; }
22+
23+
public string Quality { get; set; }
24+
25+
public string Suffix { get; set; }
26+
27+
public string VersionWithoutQuality()
28+
{
29+
return $"{Major}.{Minor}.{Patch}";
30+
}
31+
32+
public string Version()
33+
{
34+
return VersionWithoutQuality() + (Quality == null ? string.Empty : $"-{Quality}");
35+
}
36+
37+
public string VersionWithSuffix()
38+
{
39+
return Version() + (Suffix == null ? string.Empty : $"-{Suffix}");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)