From c8f363c7500e96b60add40e8352756e4d042a2f8 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Sun, 21 Jan 2018 00:55:03 +0100 Subject: [PATCH] Updated to Cake 0.25.0 * PowerShell core bootstrapper support --- build.ps1 | 81 ++++++++++++++++++++++++++++++++++++++++--------------- build.sh | 18 +++++-------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/build.ps1 b/build.ps1 index a15ac42..a944341 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,8 +1,7 @@ -$CakeVersion = "0.24.0" +$CakeVersion = "0.25.0" $DotNetChannel = "LTS"; -$DotNetVersion = "2.1.3"; -$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v2.1.3/scripts/obtain/dotnet-install.ps1"; -$ENV:CAKE_NUGET_USEINPROCESSCLIENT='true' +$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 @@ -34,23 +33,44 @@ Function Remove-PathVariable([string]$VariableToRemove) } # Get .NET Core CLI path if installed. -$FoundDotNetCliVersion = $null; +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +$env:DOTNET_CLI_TELEMETRY_OPTOUT=1 +$FoundDotNetCliVersion = $null + + if (Get-Command dotnet -ErrorAction SilentlyContinue) { - $FoundDotNetCliVersion = dotnet --version; + $FoundDotNetCliVersion = dotnet --version } -if($FoundDotNetCliVersion -ne $DotNetVersion) { +if($FoundDotNetCliVersion -ne $DotNetVersion) +{ $InstallPath = Join-Path $PSScriptRoot ".dotnet" + Remove-PathVariable "$InstallPath" + $env:PATH = "$InstallPath;$env:PATH" + if (!(Test-Path $InstallPath)) { - mkdir -Force $InstallPath | Out-Null; + New-Item -ItemType Directory -Force $InstallPath | Out-Null; } - (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1"); - & $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath; - Remove-PathVariable "$InstallPath" - $env:PATH = "$InstallPath;$env:PATH" - $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 + [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; + } } ########################################################################### @@ -67,17 +87,34 @@ Function Unzip # Make sure Cake has been installed. -$CakePath = Join-Path $ToolPath "Cake.$CakeVersion/Cake.exe" -if (!(Test-Path $CakePath)) { +$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", "$ToolPath\Cake.zip") - Unzip "$ToolPath\Cake.zip" "$ToolPath/Cake.$CakeVersion" - Remove-Item "$ToolPath\Cake.zip" + (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 ########################################################################### - -& "$CakePath" $args -exit $LASTEXITCODE \ No newline at end of file +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 +} \ No newline at end of file diff --git a/build.sh b/build.sh index 48f1dc2..b9400df 100755 --- a/build.sh +++ b/build.sh @@ -1,16 +1,10 @@ #!/usr/bin/env bash -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -# Define directories. +# Define varibles +CAKE_VERSION=0.25.0 +DOTNET_SDK_VERSION=2.1.4 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) TOOLS_DIR=$SCRIPT_DIR/tools -CAKE_VERSION=0.24.0 CAKE_EXE=$TOOLS_DIR/Cake.$CAKE_VERSION/Cake.exe -export CAKE_NUGET_USEINPROCESSCLIENT="true" # Make sure the tools folder exist. if [ ! -d "$TOOLS_DIR" ]; then @@ -25,8 +19,8 @@ echo "Installing .NET CLI..." if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then mkdir "$SCRIPT_DIR/.dotnet" fi -curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://raw.githubusercontent.com/dotnet/cli/v2.1.3/scripts/obtain/dotnet-install.sh -sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version 2.1.3 --install-dir .dotnet --no-path +curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://raw.githubusercontent.com/dotnet/cli/v$DOTNET_SDK_VERSION/scripts/obtain/dotnet-install.sh +sudo bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_SDK_VERSION --install-dir .dotnet --no-path export PATH="$SCRIPT_DIR/.dotnet":$PATH export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1 @@ -57,4 +51,4 @@ fi ########################################################################### # Start Cake -exec mono "$CAKE_EXE" "$@" \ No newline at end of file +(exec mono "$CAKE_EXE" --bootstrap) && (exec mono "$CAKE_EXE" "$@") \ No newline at end of file