Skip to content

Commit

Permalink
Moves build to Cake
Browse files Browse the repository at this point in the history
  • Loading branch information
Philo committed Jun 22, 2016
1 parent 7045354 commit 5b10b7a
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Build related
/tools/
/VersionAssemblyInfo.cs
/artifacts/

# User-specific files
*.suo
*.user
Expand Down
20 changes: 9 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
version: '{build}'
skip_tags: true
os: Visual Studio 2015
configuration: Release
before_build:
cmd: nuget restore -DisableParallelProcessing -NonInteractive
build:
project: Nest.Queryify.sln
verbosity: minimal
after_build:
cmd: nuget pack src/Nest.Queryify/Nest.Queryify.csproj -Version %GitVersion_NugetVersion% -IncludeReferencedProjects -Properties "Configuration=%CONFIGURATION%" -Verbosity quiet -Symbols
init:
- cmd: git config --global core.autocrlf true
cache:
- packages -> src\**\packages.config
- tools -> tools\packages.config
build_script:
- ps: .\build.ps1 -Target "Default" -Verbosity "Normal" -Configuration "Release"
test: off
artifacts:
- path: Nest.Queryify.*.nupkg
cache: packages -> src\packages.config
- path: artifacts\*.nupkg
194 changes: 194 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#tool "xunit.runner.console"
#tool "GitVersion.CommandLine"

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var solutionPath = MakeAbsolute(File(Argument("solutionPath", "./Nest.Queryify.sln")));
var nugetProjects = Argument("nugetProjects", "Nest.Queryify");


//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////

var testAssemblies = "./tests/**/bin/" +configuration +"/*.Tests.dll";

var artifacts = MakeAbsolute(Directory(Argument("artifactPath", "./artifacts")));
var buildOutput = MakeAbsolute(Directory(artifacts +"/build/"));
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
var versionAssemblyInfo = MakeAbsolute(File(Argument("versionAssemblyInfo", "VersionAssemblyInfo.cs")));

IEnumerable<FilePath> nugetProjectPaths = null;
SolutionParserResult solution = null;
GitVersion versionInfo = null;

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Setup(() => {
if(!FileExists(solutionPath)) throw new Exception(string.Format("Solution file not found - {0}", solutionPath.ToString()));
solution = ParseSolution(solutionPath.ToString());

var projects = solution.Projects.Where(x => nugetProjects.Contains(x.Name));
if(projects == null || !projects.Any()) throw new Exception(string.Format("Unable to find projects '{0}' in solution '{1}'", nugetProjects, solutionPath.GetFilenameWithoutExtension()));
nugetProjectPaths = projects.Select(p => p.Path);

// if(!FileExists(nugetProjectPath)) throw new Exception("project path not found");
Information("[Setup] Using Solution '{0}'", solutionPath.ToString());
});

Task("Clean")
.Does(() =>
{
CleanDirectories(artifacts.ToString());
CreateDirectory(artifacts);
CreateDirectory(buildOutput);

var binDirs = GetDirectories(solutionPath.GetDirectory() +@"\src\**\bin");
var objDirs = GetDirectories(solutionPath.GetDirectory() +@"\src\**\obj");
CleanDirectories(binDirs);
CleanDirectories(objDirs);
});

Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solutionPath, new NuGetRestoreSettings());
});

Task("Update-Version-Info")
.IsDependentOn("CreateVersionAssemblyInfo")
.Does(() =>
{
versionInfo = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true,
UpdateAssemblyInfoFilePath = versionAssemblyInfo
});

if(versionInfo != null) {
Information("Version: {0}", versionInfo.FullSemVer);
} else {
throw new Exception("Unable to determine version");
}
});

Task("CreateVersionAssemblyInfo")
.WithCriteria(() => !FileExists(versionAssemblyInfo))
.Does(() =>
{
Information("Creating version assembly info");
CreateAssemblyInfo(versionAssemblyInfo, new AssemblyInfoSettings {
Version = "0.0.0.0",
FileVersion = "0.0.0.0",
InformationalVersion = "",
});
});

Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Update-Version-Info")
.Does(() =>
{
MSBuild(solutionPath, settings => settings
.WithProperty("TreatWarningsAsErrors","true")
.WithProperty("UseSharedCompilation", "false")
.WithProperty("AutoParameterizationWebConfigConnectionStrings", "false")
.SetVerbosity(Verbosity.Quiet)
.SetConfiguration(configuration)
.WithTarget("Rebuild")
);
});

Task("Copy-Files")
.IsDependentOn("Build")
.Does(() =>
{
EnsureDirectoryExists(buildOutput);
CopyFile("./src/Nest.Queryify/bin/" +configuration +"/Nest.Queryify.dll", buildOutput +"/Nest.Queryify.dll");
CopyFile("./src/Nest.Queryify/bin/" +configuration +"/Nest.Queryify.pdb", buildOutput +"/Nest.Queryify.pdb");
});


Task("Build-NuGet-Package")
.IsDependentOn("Build")
.IsDependentOn("Copy-Files")
.Does(() =>
{
var settings = new NuGetPackSettings {
BasePath = buildOutput,
Id = "Nest.Queryify",
Authors = new [] { "Phil Oyston" },
Owners = new [] {"Phil Oyston", "Storm ID" },
Description = "Provides a mechanism to interact with Elasticsearch via a query object pattern",
LicenseUrl = new Uri("https://raw.githubusercontent.com/stormid/nest-queryify/master/LICENSE"),
ProjectUrl = new Uri("https://github.com/stormid/nest-queryify"),
IconUrl = new Uri("http://stormid.com/_/images/icons/apple-touch-icon.png"),
RequireLicenseAcceptance = false,
Properties = new Dictionary<string, string> { { "Configuration", configuration }},
Symbols = false,
NoPackageAnalysis = true,
Version = versionInfo.NuGetVersionV2,
OutputDirectory = artifacts,
Tags = new[] { "Elasticsearch", "Nest", "Storm" },
Files = new[] {
new NuSpecContent { Source = "Nest.Queryify.dll", Target = "lib/net45" },
new NuSpecContent { Source = "Nest.Queryify.pdb", Target = "lib/net45" },
},
Dependencies = new [] {
new NuSpecDependency { Id = "Nest", Version = "[1.6,2]" },
}
};
NuGetPack("./src/Nest.Queryify/Nest.Queryify.nuspec", settings);
});

Task("Package")
.IsDependentOn("Build")
.IsDependentOn("Build-NuGet-Package")
.Does(() => { });

Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(testResultsPath);

var settings = new XUnit2Settings {
XmlReportV1 = true,
NoAppDomain = true,
OutputDirectory = testResultsPath,
};

XUnit2(testAssemblies, settings);
});

Task("Update-AppVeyor-Build-Number")
.IsDependentOn("Update-Version-Info")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(versionInfo.FullSemVer +"|" +AppVeyor.Environment.Build.Number);
});

//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////

Task("Default")
.IsDependentOn("Update-Version-Info")
.IsDependentOn("Update-AppVeyor-Build-Number")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Package")
;

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);
145 changes: 145 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
##########################################################################
# This is the Cake bootstrapper script for PowerShell.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################

<#
.SYNOPSIS
This is a Powershell script to bootstrap a Cake build.
.DESCRIPTION
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
and execute your Cake build script with the parameters you provide.
.PARAMETER Script
The build script to execute.
.PARAMETER Target
The build script target to run.
.PARAMETER Configuration
The build configuration to use.
.PARAMETER Verbosity
Specifies the amount of information to be displayed.
.PARAMETER Experimental
Tells Cake to use the latest Roslyn release.
.PARAMETER WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER Mono
Tells Cake to use the Mono scripting engine.
.PARAMETER SkipToolPackageRestore
Skips restoring of packages.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
http://cakebuild.net
#>

[CmdletBinding()]
Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[Alias("DryRun","Noop")]
[switch]$WhatIf,
[switch]$Mono,
[switch]$SkipToolPackageRestore,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)

Write-Host "Preparing to run build script..."

$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition;
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"

# Should we use mono?
$UseMono = "";
if($Mono.IsPresent) {
Write-Verbose -Message "Using the Mono based scripting engine."
$UseMono = "-mono"
}

# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
Write-Verbose -Message "Using experimental version of Roslyn."
$UseExperimental = "-experimental"
}

# Is this a dry run?
$UseDryRun = "";
if($WhatIf.IsPresent) {
$UseDryRun = "-dryrun"
}

# Make sure tools folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
Write-Verbose -Message "Creating tools directory..."
New-Item -Path $TOOLS_DIR -Type directory | out-null
}

# Make sure that packages.config exist.
if (!(Test-Path $PACKAGES_CONFIG)) {
Write-Verbose -Message "Downloading packages.config..."
try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
Throw "Could not download packages.config."
}
}

# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
}
}

# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Write-Verbose -Message "Downloading NuGet.exe..."
try {
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
} catch {
Throw "Could not download NuGet.exe."
}
}

# Save nuget.exe path to environment to be available to child processed
$ENV:NUGET_EXE = $NUGET_EXE

# Restore tools from NuGet?
if(-Not $SkipToolPackageRestore.IsPresent) {
Push-Location
Set-Location $TOOLS_DIR
Write-Verbose -Message "Restoring tools from NuGet..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring NuGet tools."
}
Write-Verbose -Message ($NuGetOutput | out-string)
Pop-Location
}

# Make sure that Cake has been installed.
if (!(Test-Path $CAKE_EXE)) {
Throw "Could not find Cake.exe at $CAKE_EXE"
}

# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE
9 changes: 9 additions & 0 deletions cake.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; This is the default configuration file for Cake.
; This file was downloaded from https://github.com/cake-build/resources

[Roslyn]
NuGetSource=https://packages.nuget.org/api/v2

[Paths]
Tools=./tools
Addins=./tools/Addins
Loading

0 comments on commit 5b10b7a

Please sign in to comment.