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

Commit c8c0794

Browse files
authored
Build using Cake .NET tool (#137)
1 parent ec6e1ee commit c8c0794

File tree

4 files changed

+31
-335
lines changed

4 files changed

+31
-335
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"cake.tool": {
6+
"version": "0.32.1",
7+
"commands": [
8+
"dotnet-cake"
9+
]
10+
}
11+
}
12+
}

build.ps1

Lines changed: 11 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,235 +1,15 @@
1-
##########################################################################
2-
# This is the Cake bootstrapper script for PowerShell.
3-
# This file was downloaded from https://github.com/cake-build/resources
4-
# Feel free to change this file to fit your needs.
5-
##########################################################################
1+
$ErrorActionPreference = 'Stop'
62

7-
<#
3+
$SCRIPT_NAME = "recipe.cake"
84

9-
.SYNOPSIS
10-
This is a Powershell script to bootstrap a Cake build.
5+
Write-Host "Restoring .NET Core tools"
6+
dotnet tool restore
7+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
118

12-
.DESCRIPTION
13-
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14-
and execute your Cake build script with the parameters you provide.
9+
Write-Host "Bootstrapping Cake"
10+
dotnet cake $SCRIPT_NAME --bootstrap
11+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
1512

16-
.PARAMETER Script
17-
The build script to execute.
18-
.PARAMETER Target
19-
The build script target to run.
20-
.PARAMETER Configuration
21-
The build configuration to use.
22-
.PARAMETER Verbosity
23-
Specifies the amount of information to be displayed.
24-
.PARAMETER ShowDescription
25-
Shows description about tasks.
26-
.PARAMETER DryRun
27-
Performs a dry run.
28-
.PARAMETER Experimental
29-
Uses the nightly builds of the Roslyn script engine.
30-
.PARAMETER Mono
31-
Uses the Mono Compiler rather than the Roslyn script engine.
32-
.PARAMETER SkipToolPackageRestore
33-
Skips restoring of packages.
34-
.PARAMETER ScriptArgs
35-
Remaining arguments are added here.
36-
37-
.LINK
38-
https://cakebuild.net
39-
40-
#>
41-
42-
[CmdletBinding()]
43-
Param(
44-
[string]$Script = "recipe.cake",
45-
[string]$Target = "Default",
46-
[ValidateSet("Release", "Debug")]
47-
[string]$Configuration = "Release",
48-
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
49-
[string]$Verbosity = "Verbose",
50-
[switch]$ShowDescription,
51-
[Alias("WhatIf", "Noop")]
52-
[switch]$DryRun,
53-
[switch]$Experimental,
54-
[switch]$Mono,
55-
[switch]$SkipToolPackageRestore,
56-
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
57-
[string[]]$ScriptArgs
58-
)
59-
60-
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
61-
function MD5HashFile([string] $filePath)
62-
{
63-
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
64-
{
65-
return $null
66-
}
67-
68-
[System.IO.Stream] $file = $null;
69-
[System.Security.Cryptography.MD5] $md5 = $null;
70-
try
71-
{
72-
$md5 = [System.Security.Cryptography.MD5]::Create()
73-
$file = [System.IO.File]::OpenRead($filePath)
74-
return [System.BitConverter]::ToString($md5.ComputeHash($file))
75-
}
76-
finally
77-
{
78-
if ($file -ne $null)
79-
{
80-
$file.Dispose()
81-
}
82-
}
83-
}
84-
85-
function GetProxyEnabledWebClient
86-
{
87-
$wc = New-Object System.Net.WebClient
88-
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
89-
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
90-
$wc.Proxy = $proxy
91-
return $wc
92-
}
93-
94-
Write-Host "Preparing to run build script..."
95-
96-
if(!$PSScriptRoot){
97-
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
98-
}
99-
100-
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
101-
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
102-
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
103-
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
104-
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
105-
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
106-
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
107-
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
108-
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
109-
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
110-
111-
# Make sure tools folder exists
112-
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
113-
Write-Verbose -Message "Creating tools directory..."
114-
New-Item -Path $TOOLS_DIR -Type directory | out-null
115-
}
116-
117-
# Make sure that packages.config exist.
118-
if (!(Test-Path $PACKAGES_CONFIG)) {
119-
Write-Verbose -Message "Downloading packages.config..."
120-
try {
121-
$wc = GetProxyEnabledWebClient
122-
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
123-
Throw "Could not download packages.config."
124-
}
125-
}
126-
127-
# Try find NuGet.exe in path if not exists
128-
if (!(Test-Path $NUGET_EXE)) {
129-
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
130-
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
131-
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
132-
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
133-
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
134-
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
135-
}
136-
}
137-
138-
# Try download NuGet.exe if not exists
139-
if (!(Test-Path $NUGET_EXE)) {
140-
Write-Verbose -Message "Downloading NuGet.exe..."
141-
try {
142-
$wc = GetProxyEnabledWebClient
143-
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
144-
} catch {
145-
Throw "Could not download NuGet.exe."
146-
}
147-
}
148-
149-
# Save nuget.exe path to environment to be available to child processed
150-
$ENV:NUGET_EXE = $NUGET_EXE
151-
152-
# Restore tools from NuGet?
153-
if(-Not $SkipToolPackageRestore.IsPresent) {
154-
Push-Location
155-
Set-Location $TOOLS_DIR
156-
157-
# Check for changes in packages.config and remove installed tools if true.
158-
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
159-
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
160-
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
161-
Write-Verbose -Message "Missing or changed package.config hash..."
162-
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
163-
}
164-
165-
Write-Verbose -Message "Restoring tools from NuGet..."
166-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
167-
168-
if ($LASTEXITCODE -ne 0) {
169-
Throw "An error occurred while restoring NuGet tools."
170-
}
171-
else
172-
{
173-
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
174-
}
175-
Write-Verbose -Message ($NuGetOutput | out-string)
176-
177-
Pop-Location
178-
}
179-
180-
# Restore addins from NuGet
181-
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
182-
Push-Location
183-
Set-Location $ADDINS_DIR
184-
185-
Write-Verbose -Message "Restoring addins from NuGet..."
186-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
187-
188-
if ($LASTEXITCODE -ne 0) {
189-
Throw "An error occurred while restoring NuGet addins."
190-
}
191-
192-
Write-Verbose -Message ($NuGetOutput | out-string)
193-
194-
Pop-Location
195-
}
196-
197-
# Restore modules from NuGet
198-
if (Test-Path $MODULES_PACKAGES_CONFIG) {
199-
Push-Location
200-
Set-Location $MODULES_DIR
201-
202-
Write-Verbose -Message "Restoring modules from NuGet..."
203-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
204-
205-
if ($LASTEXITCODE -ne 0) {
206-
Throw "An error occurred while restoring NuGet modules."
207-
}
208-
209-
Write-Verbose -Message ($NuGetOutput | out-string)
210-
211-
Pop-Location
212-
}
213-
214-
# Make sure that Cake has been installed.
215-
if (!(Test-Path $CAKE_EXE)) {
216-
Throw "Could not find Cake.exe at $CAKE_EXE"
217-
}
218-
219-
220-
221-
# Build Cake arguments
222-
$cakeArguments = @("$Script");
223-
if ($Target) { $cakeArguments += "-target=$Target" }
224-
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
225-
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
226-
if ($ShowDescription) { $cakeArguments += "-showdescription" }
227-
if ($DryRun) { $cakeArguments += "-dryrun" }
228-
if ($Experimental) { $cakeArguments += "-experimental" }
229-
if ($Mono) { $cakeArguments += "-mono" }
230-
$cakeArguments += $ScriptArgs
231-
232-
# Start Cake
233-
Write-Host "Running build script..."
234-
&$CAKE_EXE $cakeArguments
235-
exit $LASTEXITCODE
13+
Write-Host "Running Build"
14+
dotnet cake $SCRIPT_NAME @args
15+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

build.sh

Lines changed: 8 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,11 @@
1-
#!/usr/bin/env bash
2-
##########################################################################
3-
# This is the Cake bootstrapper script for Linux and OS X.
4-
# This file was downloaded from https://github.com/cake-build/resources
5-
# Feel free to change this file to fit your needs.
6-
##########################################################################
1+
#!/bin/bash
2+
SCRIPT_NAME="recipe.cake"
73

8-
# Define directories.
9-
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
10-
TOOLS_DIR=$SCRIPT_DIR/tools
11-
NUGET_EXE=$TOOLS_DIR/nuget.exe
12-
NUGET_URL=https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
13-
CAKE_VERSION=0.32.1
14-
CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe
4+
echo "Restoring .NET Core tools"
5+
dotnet tool restore
156

16-
# Temporarily skip verification of addins.
17-
export CAKE_SETTINGS_SKIPVERIFICATION='true'
7+
echo "Bootstrapping Cake"
8+
dotnet cake $SCRIPT_NAME --bootstrap
189

19-
# Define default arguments.
20-
SCRIPT="recipe.cake"
21-
TARGET="Default"
22-
CONFIGURATION="Release"
23-
VERBOSITY="verbose"
24-
DRYRUN=
25-
SCRIPT_ARGUMENTS=()
26-
27-
# Parse arguments.
28-
for i in "$@"; do
29-
case $1 in
30-
-t|--target) TARGET="$2"; shift ;;
31-
-c|--configuration) CONFIGURATION="$2"; shift ;;
32-
-v|--verbosity) VERBOSITY="$2"; shift ;;
33-
-d|--dryrun) DRYRUN="-dryrun" ;;
34-
--) shift; SCRIPT_ARGUMENTS+=("$@"); break ;;
35-
*) SCRIPT_ARGUMENTS+=("$1") ;;
36-
esac
37-
shift
38-
done
39-
40-
# Make sure the tools folder exist.
41-
if [ ! -d "$TOOLS_DIR" ]; then
42-
mkdir "$TOOLS_DIR"
43-
fi
44-
45-
# Print Mono version.
46-
echo "Mono version:"
47-
mono --version
48-
echo ""
49-
50-
###########################################################################
51-
# INSTALL .NET CORE CLI
52-
###########################################################################
53-
54-
echo "Installing .NET CLI..."
55-
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
56-
mkdir "$SCRIPT_DIR/.dotnet"
57-
fi
58-
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh
59-
sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version 2.1.400 --install-dir .dotnet --no-path
60-
export PATH="$SCRIPT_DIR/.dotnet":$PATH
61-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
62-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
63-
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
64-
"$SCRIPT_DIR/.dotnet/dotnet" --info
65-
66-
###########################################################################
67-
# INSTALL NUGET
68-
###########################################################################
69-
70-
# Download NuGet if it does not exist.
71-
if [ ! -f "$NUGET_EXE" ]; then
72-
echo "Downloading NuGet..."
73-
curl -Lsfo "$NUGET_EXE" $NUGET_URL
74-
if [ $? -ne 0 ]; then
75-
echo "An error occurred while downloading nuget.exe."
76-
exit 1
77-
fi
78-
fi
79-
80-
###########################################################################
81-
# INSTALL CAKE
82-
###########################################################################
83-
84-
if [ ! -f "$CAKE_EXE" ]; then
85-
mono "$NUGET_EXE" install Cake -Version $CAKE_VERSION -OutputDirectory "$TOOLS_DIR"
86-
if [ $? -ne 0 ]; then
87-
echo "An error occurred while installing Cake."
88-
exit 1
89-
fi
90-
fi
91-
92-
# Make sure that Cake has been installed.
93-
if [ ! -f "$CAKE_EXE" ]; then
94-
echo "Could not find Cake.exe at '$CAKE_EXE'."
95-
exit 1
96-
fi
97-
98-
###########################################################################
99-
# RUN BUILD SCRIPT
100-
###########################################################################
101-
102-
# Start Cake
103-
exec mono "$CAKE_EXE" $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}"
10+
echo "Running Build"
11+
dotnet cake $SCRIPT_NAME "$@"

tools/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)