Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f528fa3
commit 51afa01
Showing
9 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
build/BuildScript.csproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> ProjectFiles { get; set; } | ||
|
||
protected List<string> 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FlubuCore" Version="4.2.1" /> | ||
<PackageReference Include="Glob" Version="1.1.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"); | ||
} | ||
} | ||
} |