forked from exercism/csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
149 lines (130 loc) · 5.16 KB
/
build.ps1
File metadata and controls
149 lines (130 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.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 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 Exercise
The exercise to build and test. If not specified, all exercises will be built and tested.
.PARAMETER ScriptArgs
Remaining arguments are added here.
.LINK
http://cakebuild.net
#>
[CmdletBinding()]
Param(
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Normal",
[switch]$WhatIf,
[string]$Exercise,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$ScriptArgs
)
function GetProxyEnabledWebClient
{
$wc = New-Object System.Net.WebClient
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$wc.Proxy = $proxy
return $wc
}
Write-Host "Preparing to run build script..."
if(!$PSScriptRoot){
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
$CAKE_VERSION = "0.21.1"
$CAKE_DLL = Join-Path $TOOLS_DIR "Cake.CoreCLR.$CAKE_VERSION/Cake.dll"
$DOTNET_DIR = Join-Path $PSScriptRoot ".dotnet"
$DOTNET_CORE_2_VERSION = "2.0.0"
$DOTNET_CORE_1_VERSION = "1.0.4"
$DOTNET_INSTALLER_SCRIPT_URL = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
$DOTNET_INSTALLER_SCRIPT = Join-Path $DOTNET_DIR "dotnet-install.ps1"
$env:PATH = "$TOOLS_DIR;$DOTNET_DIR;$env:PATH"
# 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 dotnet folder exists
if ((Test-Path $PSScriptRoot) -and !(Test-Path $DOTNET_DIR)) {
Write-Verbose -Message "Creating .dotnet directory..."
New-Item -Path $DOTNET_DIR -Type directory | out-null
}
# Try download .NET installer script if not exists
if (!(Test-Path $DOTNET_INSTALLER_SCRIPT)) {
Write-Verbose -Message "Downloading .NET installer script..."
try {
$wc = GetProxyEnabledWebClient
$wc.DownloadFile($DOTNET_INSTALLER_SCRIPT_URL, $DOTNET_INSTALLER_SCRIPT)
} catch {
Throw "Could not download .NET installer script."
}
}
# Install .NET Core runtimes
Invoke-Expression "&`"$DOTNET_INSTALLER_SCRIPT`" -Version $DOTNET_CORE_1_VERSION -InstallDir `"$DOTNET_DIR`""
Invoke-Expression "&`"$DOTNET_INSTALLER_SCRIPT`" -Version $DOTNET_CORE_2_VERSION -InstallDir `"$DOTNET_DIR`""
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
# 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 $_ -PathType Container) }
$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 {
$wc = GetProxyEnabledWebClient
$wc.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
# Try install Cake
if (!(Test-Path $CAKE_DLL)) {
Write-Verbose -Message "Installing Cake..."
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install Cake.CoreCLR -Version $CAKE_VERSION -OutputDirectory `"$TOOLS_DIR`""
if ($LASTEXITCODE -ne 0) {
Throw "Could not install Cake."
}
Write-Verbose -Message ($NuGetOutput | out-string)
}
# Make sure that Cake has been installed
if (!(Test-Path $CAKE_DLL)) {
Throw "Could not find Cake.dll at $CAKE_DLL"
}
# Build Cake arguments
$cakeArguments = @("$Script");
if ($Target) { $cakeArguments += "-target=$Target" }
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
if ($ShowDescription) { $cakeArguments += "-showdescription" }
if ($DryRun) { $cakeArguments += "-dryrun" }
if ($Exercise) { $cakeArguments += "-exercise=$Exercise" }
$cakeArguments += $ScriptArgs
# Start Cake
Write-Host "Running build script..."
Invoke-Expression "&dotnet `"$CAKE_DLL`" $cakeArguments"
exit $LASTEXITCODE