Skip to content

Instantly share code, notes, and snippets.

@devlead
Last active January 14, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlead/818927b03a0f3762e20d269ef4e29eb2 to your computer and use it in GitHub Desktop.
Save devlead/818927b03a0f3762e20d269ef4e29eb2 to your computer and use it in GitHub Desktop.
$CakeVersion = "0.34.1"
if (![string]::IsNullOrWhiteSpace($env:CAKE_VERSION))
{
$CakeVersion = $env:CAKE_VERSION
}
$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 CAKE
###########################################################################
if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue))
{
if ($PSVersionTable.PSVersion.Major -le 3)
{
& {
function global:Expand-Archive
{
param([string]$Path, [string]$DestinationPath)
$shell = New-Object -com shell.application
$zip = $shell.NameSpace($Path)
foreach($item in $zip.items())
{
$shell.Namespace($DestinationPath).copyhere($item)
}
}
}
}
else
{
& {
Add-Type -AssemblyName System.IO.Compression.FileSystem
function global:Expand-Archive
{
param([string]$Path, [string]$DestinationPath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($Path, $DestinationPath)
}
}
}
}
# Make sure Cake has been installed.
$CakePath = Join-Path $ToolPath "Cake.$CakeVersion"
$CakeExePath = Join-Path $CakePath "Cake.exe"
$CakeZipPath = Join-Path $ToolPath "Cake.zip"
$CakeUri = "https://www.nuget.org/api/v2/package/Cake/$CakeVersion"
if (!(Test-Path $CakeExePath)) {
Write-Host "Installing Cake $CakeVersion..."
(New-Object System.Net.WebClient).DownloadFile($CakeUri, $CakeZipPath)
Expand-Archive $CakeZipPath $CakePath
Remove-Item $CakeZipPath
}
###########################################################################
# RUN BUILD SCRIPT
###########################################################################
if ($IsRunningOnUnix)
{
& mono "$CakeExePath" --bootstrap
if ($LASTEXITCODE -eq 0)
{
& mono "$CakeExePath" $args
}
}
else
{
& "$CakeExePath" --bootstrap
if ($LASTEXITCODE -eq 0)
{
& "$CakeExePath" $args
}
}
exit $LASTEXITCODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment