Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit d3838ba

Browse files
cake build script
1 parent c58a804 commit d3838ba

3 files changed

Lines changed: 200 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,4 @@ paket-files/
250250
# JetBrains Rider
251251
.idea/
252252
*.sln.iml
253+
tools/**

build.cake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#tool "nuget:?package=xunit.runner.console&version=2.1.0"
2+
3+
#addin "Cake.FileHelpers"
4+
5+
var target = Argument("target", "Default");
6+
var configuration = Argument("configuration", "Release");
7+
var artifactsDir = Directory("./artifacts");
8+
var srcDir = Directory("./src");
9+
var solution = srcDir + File("SqlStreamStore.HAL.sln");
10+
var buildNumber = string.IsNullOrWhiteSpace(EnvironmentVariable("BUILD_NUMBER")) ? "0" : EnvironmentVariable("BUILD_NUMBER");
11+
12+
Task("Clean")
13+
.Does(() =>
14+
{
15+
CleanDirectory(artifactsDir);
16+
});
17+
18+
Task("RestorePackages")
19+
.IsDependentOn("Clean")
20+
.Does(() =>
21+
{
22+
DotNetCoreRestore(solution);
23+
NuGetRestore(solution);
24+
});
25+
26+
Task("Build")
27+
.IsDependentOn("RestorePackages")
28+
.Does(() =>
29+
{
30+
DotNetCoreBuild(solution, new DotNetCoreBuildSettings {
31+
Configuration = configuration
32+
});
33+
});
34+
35+
Task("RunTests")
36+
.IsDependentOn("Build")
37+
.Does(() =>
38+
{
39+
40+
var testProjects = new string[] { "SqlStreamStore.HAL.Tests" };
41+
42+
foreach(var testProject in testProjects) {
43+
var projectDir = srcDir + Directory(testProject);
44+
StartProcess("dotnet", new ProcessSettings {
45+
Arguments = "xunit",
46+
WorkingDirectory = projectDir
47+
});
48+
}
49+
});
50+
51+
Task("NuGetPack")
52+
.IsDependentOn("Build")
53+
.Does(() =>
54+
{
55+
var versionSuffix = "build" + buildNumber.ToString().PadLeft(5, '0');
56+
57+
DotNetCorePack(srcDir + Directory("SqlStreamStore.HAL"), new DotNetCorePackSettings {
58+
ArgumentCustomization = args => args.Append("/p:Version=1.0.0-" + versionSuffix),
59+
OutputDirectory = artifactsDir,
60+
NoBuild = true,
61+
Configuration = configuration,
62+
VersionSuffix = versionSuffix
63+
});
64+
});
65+
66+
Task("Default")
67+
.IsDependentOn("RunTests")
68+
.IsDependentOn("NuGetPack");
69+
70+
RunTarget(target);

build.ps1

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<#
2+
.SYNOPSIS
3+
This is a Powershell script to bootstrap a Cake build.
4+
.DESCRIPTION
5+
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
6+
and execute your Cake build script with the parameters you provide.
7+
.PARAMETER Target
8+
The build script target to run.
9+
.PARAMETER Configuration
10+
The build configuration to use.
11+
.PARAMETER Verbosity
12+
Specifies the amount of information to be displayed.
13+
.PARAMETER WhatIf
14+
Performs a dry run of the build script.
15+
No tasks will be executed.
16+
.PARAMETER ScriptArgs
17+
Remaining arguments are added here.
18+
.LINK
19+
http://cakebuild.net
20+
#>
21+
22+
[CmdletBinding()]
23+
Param(
24+
[string]$Target = "Default",
25+
[ValidateSet("Release", "Debug")]
26+
[string]$Configuration = "Release",
27+
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
28+
[string]$Verbosity = "Verbose",
29+
[switch]$WhatIf,
30+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
31+
[string[]]$ScriptArgs
32+
)
33+
34+
$CakeVersion = "0.19.3"
35+
$DotNetChannel = "preview";
36+
$DotNetVersion = "1.0.3";
37+
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
38+
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
39+
40+
# Make sure tools folder exists
41+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
42+
$ToolPath = Join-Path $PSScriptRoot "tools"
43+
if (!(Test-Path $ToolPath)) {
44+
Write-Verbose "Creating tools directory..."
45+
New-Item -Path $ToolPath -Type directory | out-null
46+
}
47+
48+
###########################################################################
49+
# INSTALL .NET CORE CLI
50+
###########################################################################
51+
52+
Function Remove-PathVariable([string]$VariableToRemove)
53+
{
54+
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
55+
if ($path -ne $null)
56+
{
57+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
58+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
59+
}
60+
61+
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
62+
if ($path -ne $null)
63+
{
64+
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
65+
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
66+
}
67+
}
68+
69+
# Get .NET Core CLI path if installed.
70+
$FoundDotNetCliVersion = $null;
71+
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
72+
$FoundDotNetCliVersion = dotnet --version;
73+
}
74+
75+
if($FoundDotNetCliVersion -ne $DotNetVersion) {
76+
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
77+
if (!(Test-Path $InstallPath)) {
78+
mkdir -Force $InstallPath | Out-Null;
79+
}
80+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
81+
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
82+
83+
Remove-PathVariable "$InstallPath"
84+
$env:PATH = "$InstallPath;$env:PATH"
85+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
86+
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
87+
}
88+
89+
###########################################################################
90+
# INSTALL NUGET
91+
###########################################################################
92+
93+
# Make sure nuget.exe exists.
94+
$NugetPath = Join-Path $ToolPath "nuget.exe"
95+
if (!(Test-Path $NugetPath)) {
96+
Write-Host "Downloading NuGet.exe..."
97+
(New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
98+
}
99+
100+
###########################################################################
101+
# INSTALL CAKE
102+
###########################################################################
103+
104+
# Make sure Cake has been installed.
105+
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe"
106+
if (!(Test-Path $CakePath)) {
107+
Write-Host "Installing Cake..."
108+
Invoke-Expression "&`"$NugetPath`" install Cake -Version $CakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
109+
if ($LASTEXITCODE -ne 0) {
110+
Throw "An error occured while restoring Cake from NuGet."
111+
}
112+
}
113+
114+
###########################################################################
115+
# RUN BUILD SCRIPT
116+
###########################################################################
117+
118+
# Build the argument list.
119+
$Arguments = @{
120+
target=$Target;
121+
configuration=$Configuration;
122+
verbosity=$Verbosity;
123+
dryrun=$WhatIf;
124+
}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value };
125+
126+
# Start Cake
127+
Write-Host "Running build script..."
128+
Invoke-Expression "& `"$CakePath`" `"build.cake`" $Arguments $ScriptArgs"
129+
exit $LASTEXITCODE

0 commit comments

Comments
 (0)