Navigation Menu

Skip to content

Commit

Permalink
Add nuke build.
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Nov 7, 2017
1 parent 810f4e6 commit 9879ba4
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 0 deletions.
Binary file added .nuke
Binary file not shown.
5 changes: 5 additions & 0 deletions GitVersion.yml
@@ -0,0 +1,5 @@
assembly-versioning-scheme: MajorMinor
mode: Mainline

ignore:
sha: []
52 changes: 52 additions & 0 deletions build.ps1
@@ -0,0 +1,52 @@
[CmdletBinding()]
Param(
[switch]$NoInit,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$BuildArguments
)

Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { $host.SetShouldExit(1) }
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

###########################################################################
# CONFIGURATION
###########################################################################

$NuGetVersion = "latest"
$SolutionDirectory = "$PSScriptRoot\.\src"
$BuildProjectFile = "$PSScriptRoot\.\build\.build.csproj"
$BuildExeFile = "$PSScriptRoot\.\build\bin\debug\.build.exe"

$TempDirectory = "$PSScriptRoot\.tmp"

$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/$NuGetVersion/nuget.exe"
$NuGetFile = "$TempDirectory\nuget.exe"
$env:NUGET_EXE = $NuGetFile

###########################################################################
# PREPARE BUILD
###########################################################################

function ExecSafe([scriptblock] $cmd) {
& $cmd
if ($LastExitCode -ne 0) { throw "The following call failed with exit code $LastExitCode. '$cmd'" }
}

if (!$NoInit) {
md -force $TempDirectory > $null

if (!(Test-Path $NuGetFile)) { (New-Object System.Net.WebClient).DownloadFile($NuGetUrl, $NuGetFile) }
elseif ($NuGetVersion -eq "latest") { & $NuGetFile update -Self }

ExecSafe { & $NuGetFile restore $BuildProjectFile -SolutionDirectory $SolutionDirectory }
ExecSafe { & $NuGetFile install Nuke.MSBuildLocator -ExcludeVersion -OutputDirectory $TempDirectory -SolutionDirectory $SolutionDirectory }
}

$MSBuildFile = & "$TempDirectory\Nuke.MSBuildLocator\tools\Nuke.MSBuildLocator.exe"
ExecSafe { & $MSBuildFile $BuildProjectFile }

###########################################################################
# EXECUTE BUILD
###########################################################################

ExecSafe { & $BuildExeFile $BuildArguments }
50 changes: 50 additions & 0 deletions build.sh
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

NOINIT=0
BUILD_ARGUMENTS=()
for i in "$@"; do
case $(echo $1 | awk '{print tolower($0)}') in
-noinit) NOINIT=1;;
*) BUILD_ARGUMENTS+=("$1") ;;
esac
shift
done

set -eo pipefail
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)

###########################################################################
# CONFIGURATION
###########################################################################

NUGET_VERSION="latest"
SOLUTION_DIRECTORY="$SCRIPT_DIR/./src"
BUILD_PROJECT_FILE="$SCRIPT_DIR/./build/.build.csproj"
BUILD_EXE_FILE="$SCRIPT_DIR/./build/bin/Debug/.build.exe"

TEMP_DIRECTORY="$SCRIPT_DIR/.tmp"

NUGET_URL="https://dist.nuget.org/win-x86-commandline/$NUGET_VERSION/nuget.exe"
NUGET_FILE="$TEMP_DIRECTORY/nuget.exe"
export NUGET_EXE="$NUGET_FILE"

###########################################################################
# PREPARE BUILD
###########################################################################

if ! ((NOINIT)); then
mkdir -p "$TEMP_DIRECTORY"

if [ ! -f "$NUGET_FILE" ]; then curl -Lsfo "$NUGET_FILE" $NUGET_URL;
elif [ $NUGET_VERSION == "latest" ]; then mono "$NUGET_FILE" update -Self; fi

mono "$NUGET_FILE" restore "$BUILD_PROJECT_FILE" -SolutionDirectory $SOLUTION_DIRECTORY
fi

msbuild "$BUILD_PROJECT_FILE"

###########################################################################
# EXECUTE BUILD
###########################################################################

mono "$BUILD_EXE_FILE" ${BUILD_ARGUMENTS[@]}
18 changes: 18 additions & 0 deletions build/.build.csproj
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace></RootNamespace>
<IsPackable>false</IsPackable>
<NoWarn>CS0649;CS0169</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="0.1.385" />
<PackageReference Include="GitVersion.CommandLine" Version="4.0.0-beta0011" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
</ItemGroup>

</Project>
45 changes: 45 additions & 0 deletions build/.build.csproj.dotsettings
@@ -0,0 +1,45 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/ImplicitNullability/EnableFields/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_INTERNAL_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_PRIVATE_MODIFIER/@EntryValue">Implicit</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/METHOD_OR_OPERATOR_BODY/@EntryValue">ExpressionBody</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Applicability/=File/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/CustomProperties/=Extension/@EntryIndexedValue">json</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/CustomProperties/=FileName/@EntryIndexedValue">metadata</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/CustomProperties/=ValidateFileName/@EntryIndexedValue">True</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Description/@EntryValue">NUKE tool metadata</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Field/=name/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Field/=name/Expression/@EntryValue">getFileNameWithoutExtension()</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Field/=name/InitialRange/@EntryValue">-1</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Field/=name/Order/@EntryValue">0</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Reformat/@EntryValue">True</s:Boolean>


<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Scope/=E8F0594528C33E45BBFEC6CFE851095D/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Scope/=E8F0594528C33E45BBFEC6CFE851095D/Type/@EntryValue">InCSharpProjectFile</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=A7552288530102459B5E4251A0BDAF86/Text/@EntryValue">{&#xD;
"$schema": "./_schema.json#",&#xD;
"name": "$name$",&#xD;
"customExecutable": true,&#xD;
"tasks": [&#xD;
{&#xD;
"settingsClass": {&#xD;
"properties": [&#xD;
{&#xD;
$END$&#xD;
}&#xD;
]&#xD;
}&#xD;
}&#xD;
]&#xD;
}</s:String></wpf:ResourceDictionary>
85 changes: 85 additions & 0 deletions build/Build.cs
@@ -0,0 +1,85 @@
// /*
// * Copyright 2007-2015 JetBrains
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */

using System;
using System.Linq;
using System.Web.UI.WebControls.WebParts;
using Nuke.Common.Tools;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Tools.Nunit;
using Nuke.Core;
using Nuke.Core.IO;
using Nuke.Core.Tooling;
using Nuke.Core.Utilities.Collections;
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using static Nuke.Common.Tools.Nunit.NunitTasks;
using static Nuke.Core.IO.FileSystemTasks;
using static Nuke.Core.IO.PathConstruction;

class Build : NukeBuild
{
public static int Main () => Execute<Build>(x => x.Compile);

[GitVersion] readonly GitVersion GitVersion;
[Parameter] readonly string MyGetApiKey;

Target Clean => _ => _
.OnlyWhen(() => false) // Disabled for safety.
.Executes(() =>
{
DeleteDirectories(GlobDirectories(SourceDirectory, "**/bin", "**/obj"));
EnsureCleanDirectory(OutputDirectory);
});

Target Restore => _ => _
.DependsOn(Clean)
.Executes(() =>
{
MSBuild(s => DefaultMSBuildRestore);
});

Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
MSBuild(s => DefaultMSBuildCompile);
});

Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
{
Nunit3(s => s
.AddInputFiles(GlobFiles(RootDirectory / "test", $"**/bin/{Configuration}/tests.dll"))
.EnableNoResults()
.SetToolPath(ToolPathResolver.GetPackageExecutable("NUnit.ConsoleRunner", "nunit3-console.exe")));
});

Target Pack => _ => _
.DependsOn(Compile)
.Executes(() =>
{
GlobFiles(RootDirectory / "install", "*.nuspec")
.ForEach(x => NuGetPack(s => DefaultNuGetPack
.SetTargetPath(x)
.SetBasePath(RootDirectory / "install")
.SetOutputDirectory(OutputDirectory)));
});


}
4 changes: 4 additions & 0 deletions src/CyclomaticComplexity.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ".build", "..\build\.build.csproj", "{500D453D-FD1F-410C-9D3B-A29A182C091A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CyclomaticComplexity", "CyclomaticComplexity\CyclomaticComplexity.csproj", "{4FF42D42-187D-4332-8154-49506B1DB698}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "..\test\src\tests.csproj", "{4C980A6F-C0F0-42D1-8AB0-C6F47A6F098A}"
Expand All @@ -13,6 +15,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{500D453D-FD1F-410C-9D3B-A29A182C091A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{500D453D-FD1F-410C-9D3B-A29A182C091A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FF42D42-187D-4332-8154-49506B1DB698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FF42D42-187D-4332-8154-49506B1DB698}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FF42D42-187D-4332-8154-49506B1DB698}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 9879ba4

Please sign in to comment.