Skip to content

Commit

Permalink
Added Cake build script
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Dec 12, 2015
1 parent 4b156a9 commit d27e3c1
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 37 deletions.
2 changes: 2 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### New in 0.0.1 (Released 2015/12/12)
* First experimental release of Cake.Git
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build script
build_script:
- ps: .\build.ps1 -Target AppVeyor

# Tests
test: off
213 changes: 213 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#addin "Cake.Slack"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////

var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");

///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var GitHookUri = EnvironmentVariable("Githookuri");
var GitChannel = "#cake";
var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var solutions = GetFiles("./**/*.sln");
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
var version = releaseNotes.Version.ToString();
var binDir = "./src/Cake.Git/bin/" + configuration;
var nugetRoot = "./nuget/";
var semVersion = isLocalBuild
? version
: string.Concat(version, "-build-", AppVeyor.Environment.Build.Number.ToString("0000"));
var assemblyInfo = new AssemblyInfoSettings {
Title = "Cake.Git",
Description = "Cake Git AddIn",
Product = "Cake.Git",
Company = "WCOM AB",
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = string.Format("Copyright © WCOM AB {0}", DateTime.Now.Year),
CLSCompliant = true
};
var nuGetPackSettings = new NuGetPackSettings {
Id = assemblyInfo.Product,
Version = assemblyInfo.InformationalVersion,
Title = assemblyInfo.Title,
Authors = new[] {assemblyInfo.Company},
Owners = new[] {assemblyInfo.Company},
Description = assemblyInfo.Description,
Summary = "Cake AddIn that extends Cake with Git SCM features",
ProjectUrl = new Uri("https://github.com/WCOMAB/Cake_Git/"),
IconUrl = new Uri("http://cdn.rawgit.com/WCOMAB/nugetpackages/master/Chocolatey/icons/wcom.png"),
LicenseUrl = new Uri("https://github.com/WCOMAB/Cake.Git/blob/master/LICENSE"),
Copyright = assemblyInfo.Copyright,
ReleaseNotes = releaseNotes.Notes.ToArray(),
Tags = new [] {"Cake", "Script", "Build", "Git"},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = new [] {
new NuSpecContent {Source = "Cake.Git.dll"},
new NuSpecContent {Source = "Cake.Git.pdb"},
new NuSpecContent {Source = "Cake.Git.xml"},
new NuSpecContent {Source = "LibGit2Sharp.dll"},
new NuSpecContent {Source = "LibGit2Sharp.pdb"},
new NuSpecContent {Source = "LibGit2Sharp.xml"},
new NuSpecContent {Source = "NativeBinaries/amd64/git2-821131f.dll", Target = "NativeBinaries/amd64/git2-821131f.dll"},
new NuSpecContent {Source = "NativeBinaries/amd64/git2-821131f.pdb", Target = "NativeBinaries/amd64/git2-821131f.pdb"},
new NuSpecContent {Source = "NativeBinaries/linux/amd64/libgit2-821131f.so", Target = "NativeBinaries/linux/amd64/libgit2-821131f.so"},
new NuSpecContent {Source = "NativeBinaries/osx/libgit2-821131f.dylib", Target = "NativeBinaries/osx/libgit2-821131f.dylib"},
new NuSpecContent {Source = "NativeBinaries/x86/git2-821131f.dll", Target = "NativeBinaries/x86/git2-821131f.dll"},
new NuSpecContent {Source = "NativeBinaries/x86/git2-821131f.pdb", Target = "NativeBinaries/x86/git2-821131f.pdb"},
},
BasePath = binDir,
OutputDirectory = nugetRoot
};

if (!isLocalBuild)
{
AppVeyor.UpdateBuildVersion(semVersion);
}

///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////

Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");

var buildStartMessage = string.Format(
"Building version {0} of {1} ({2}).",
version,
assemblyInfo.Product,
semVersion
);

Information(buildStartMessage);
if(!string.IsNullOrEmpty(GitHookUri))
{
Slack.Chat.PostMessage(
channel:GitChannel,
text:buildStartMessage,
messageSettings:new SlackChatMessageSettings { IncomingWebHookUrl = GitHookUri }
);
}
});

Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});

///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////

Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
});

Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}...", solution);
NuGetRestore(solution);
}
});

Task("SolutionInfo")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, assemblyInfo);
});

Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("SolutionInfo")
.Does(() =>
{
// Build all solutions.
foreach(var solution in solutions)
{
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithTarget("Build")
.SetConfiguration(configuration));
}
});


Task("Create-NuGet-Package")
.IsDependentOn("Build")
.Does(() =>
{
if (!DirectoryExists(nugetRoot))
{
CreateDirectory(nugetRoot);
}
NuGetPack(nuGetPackSettings);
});

Task("Publish-MyGet")
.IsDependentOn("Create-NuGet-Package")
.WithCriteria(() => !isLocalBuild)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}

var source = EnvironmentVariable("MYGET_SOURCE");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet source.");
}

// Get the path to the package.
var package = nugetRoot + "Cake.Git." + semVersion + ".nupkg";

// Push the package.
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
});


Task("Default")
.IsDependentOn("Create-NuGet-Package");

Task("AppVeyor")
.IsDependentOn("Publish-MyGet");

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

RunTarget(target);
111 changes: 111 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<#
.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 WhatIf
Performs a dry run of the build script.
No tasks will be executed.
.PARAMETER Experimental
Tells Cake to use the latest Roslyn release.
.LINK
http://cakebuild.net
#>

Param(
[string]$Script = "build.cake",
[string]$Target = "Default",
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[Alias("DryRun","Noop")]
[switch]$Experimental,
[switch]$WhatIf
)

$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"

# Should we use the new Roslyn?
$UseExperimental = "";
if($Experimental.IsPresent) {
$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)) {
New-Item -path $TOOLS_DIR -name logfiles -itemtype directory
}

# Try find NuGet.exe in path if not exists
if (!(Test-Path $NUGET_EXE)) {
"Trying to find nuget.exe in path"
$NUGET_EXE_IN_PATH = &where.exe nuget.exe
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH)) {
"Found $($NUGET_EXE_IN_PATH)"
$NUGET_EXE = $NUGET_EXE_IN_PATH
}
}

# Try download NuGet.exe if not exists
if (!(Test-Path $NUGET_EXE)) {
Invoke-WebRequest -Uri http://nuget.org/nuget.exe -OutFile $NUGET_EXE
}

# Make sure NuGet exists where we expect it.
if (!(Test-Path $NUGET_EXE)) {
Throw "Could not find NuGet.exe"
}

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

# Restore tools from NuGet.
Push-Location
Set-Location $TOOLS_DIR

# Restore packages
if (Test-Path $PACKAGES_CONFIG)
{
Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion"
}
# Install just Cake if missing config
else
{
Invoke-Expression "&`"$NUGET_EXE`" install Cake -ExcludeVersion -PreRelease -Source `"https://www.myget.org/F/cake`""
}
Pop-Location
if ($LASTEXITCODE -ne 0)
{
exit $LASTEXITCODE
}

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

# Start Cake
Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseDryRun $UseExperimental"
exit $LASTEXITCODE
8 changes: 7 additions & 1 deletion src/Cake.Git/Cake.Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Cake.Git.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -31,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Cake.Git.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cake.Core, Version=0.6.4.0, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -52,6 +54,10 @@
<ItemGroup>
<Compile Include="GitAliases.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Namespaces.cs" />
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -63,7 +69,7 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibGit2Sharp.NativeBinaries.1.0.106\build\LibGit2Sharp.NativeBinaries.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
Expand Down
Loading

0 comments on commit d27e3c1

Please sign in to comment.