forked from LitJSON/litjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
120 lines (103 loc) · 4.2 KB
/
build.ps1
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
$CakeVersion = "0.25.0"
$DotNetChannel = "LTS";
$DotNetVersion = "2.1.4";
$IsRunningOnUnix = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix
# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ToolPath = Join-Path $PSScriptRoot "tools"
if (!(Test-Path $ToolPath)) {
Write-Verbose "Creating tools directory..."
New-Item -Path $ToolPath -Type directory | out-null
}
###########################################################################
# INSTALL .NET CORE CLI
###########################################################################
Function Remove-PathVariable([string]$VariableToRemove)
{
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
}
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}
}
# Get .NET Core CLI path if installed.
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
$FoundDotNetCliVersion = $null
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$FoundDotNetCliVersion = dotnet --version
}
if($FoundDotNetCliVersion -ne $DotNetVersion)
{
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
Remove-PathVariable "$InstallPath"
$env:PATH = "$InstallPath;$env:PATH"
if (!(Test-Path $InstallPath)) {
New-Item -ItemType Directory -Force $InstallPath | Out-Null;
}
[string] $InstalledDotNetVersion = Get-ChildItem -Path ./.dotnet -File `
| Where-Object { $_.Name -eq 'dotnet' -or $_.Name -eq 'dotnet.exe' } `
| ForEach-Object { &$_.FullName --version }
if ($InstalledDotNetVersion -eq $DotNetVersion)
{
}
elseif ($IsRunningOnUnix)
{
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.sh";
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath/dotnet-install.sh");
sudo bash "$InstallPath/dotnet-install.sh" --version $DotNetVersion --install-dir "$InstallPath" --no-path
}
else
{
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v2.1.4/scripts/obtain/dotnet-install.ps1";
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
}
}
###########################################################################
# INSTALL CAKE
###########################################################################
Add-Type -AssemblyName System.IO.Compression.FileSystem
Function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
# Make sure Cake has been installed.
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion"
$CakeExePath = Join-Path $CakePath "Cake.exe"
$CakeZipPath = Join-Path $ToolPath "Cake.zip"
if (!(Test-Path $CakeExePath)) {
Write-Host "Installing Cake $CakeVersion..."
(New-Object System.Net.WebClient).DownloadFile("https://www.nuget.org/api/v2/package/Cake/$CakeVersion", $CakeZipPath)
Unzip $CakeZipPath $CakePath
Remove-Item $CakeZipPath
}
###########################################################################
# RUN BUILD SCRIPT
###########################################################################
if ($IsRunningOnUnix)
{
& mono "$CakeExePath" --bootstrap
if ($LASTEXITCODE -eq 0)
{
& mono "$CakeExePath" $args
}
exit $LASTEXITCODE
}
else
{
& "$CakeExePath" --bootstrap
if ($LASTEXITCODE -eq 0)
{
& "$CakeExePath" $args
}
exit $LASTEXITCODE
}