Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Sep 18, 2018
2 parents d4d9ac0 + 60fcfb8 commit 7981279
Show file tree
Hide file tree
Showing 32 changed files with 1,448 additions and 263 deletions.
152 changes: 142 additions & 10 deletions .psscripts/build-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ function Test-IsWindows
[environment]::OSVersion.Platform -ne "Unix"
}

function Invoke-UnsafeCmd ($cmd)
{
<#
.DESCRIPTION
Runs a shell or bash command, but doesn't throw an error if the command didn't exit with 0.
.PARAMETER cmd
The command to be executed.
.EXAMPLE
Invoke-Cmd -Cmd "dotnet new classlib"
.NOTES
Use this PowerShell command to execute any CLI commands which might not exit with 0 on a success.
#>

Write-Host $cmd -ForegroundColor DarkCyan
if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" }
Invoke-Expression -Command $cmd
}

function Invoke-Cmd ($Cmd)
{
<#
Expand All @@ -31,9 +52,7 @@ function Invoke-Cmd ($Cmd)
Use this PowerShell command to execute any dotnet CLI commands in order to ensure that they behave the same way in the case of an error across different environments (Windows, OSX and Linux).
#>

Write-Host $Cmd -ForegroundColor DarkCyan
if (Test-IsWindows) { $Cmd = "cmd.exe /C $Cmd" }
Invoke-Expression -Command $Cmd
Invoke-UnsafeCmd $cmd
if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$Cmd'."; return }
}

Expand All @@ -52,13 +71,39 @@ function Remove-OldBuildArtifacts
Remove-Item $_ -Recurse -Force }
}

function Test-CompareVersions ($projFile, [string]$gitTag)
function Get-ProjectVersion ($projFile)
{
Write-Host "Matching version against git tag..." -ForegroundColor Magenta
<#
.DESCRIPTION
Gets the <Version> value of a .NET Core *.csproj, *.fsproj or *.vbproj file.
.PARAMETER cmd
The relative or absolute path to the .NET Core project file.
#>

[xml]$xml = Get-Content $projFile
[string]$version = $xml.Project.PropertyGroup.Version
[string] $version = $xml.Project.PropertyGroup.Version
$version
}

function Get-NuspecVersion ($nuspecFile)
{
<#
.DESCRIPTION
Gets the <version> value of a .nuspec file.
.PARAMETER cmd
The relative or absolute path to the .nuspec file.
#>

[xml] $xml = Get-Content $nuspecFile
[string] $version = $xml.package.metadata.version
$version
}

function Test-CompareVersions ($version, [string]$gitTag)
{
Write-Host "Matching version against git tag..." -ForegroundColor Magenta
Write-Host "Project version: $version" -ForegroundColor Cyan
Write-Host "Git tag version: $gitTag" -ForegroundColor Cyan

Expand All @@ -74,6 +119,7 @@ function Test-CompareVersions ($projFile, [string]$gitTag)

function dotnet-info { Invoke-Cmd "dotnet --info" }
function dotnet-version { Invoke-Cmd "dotnet --version" }
function dotnet-restore ($project, $argv) { Invoke-Cmd "dotnet restore $project $argv" }
function dotnet-build ($project, $argv) { Invoke-Cmd "dotnet build $project $argv" }
function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" }
function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" }
Expand Down Expand Up @@ -167,6 +213,65 @@ function Write-DotnetCoreVersions
Write-Host ".NET Core Runtime version: $runtimeVersion" -ForegroundColor Cyan
}

function Get-DesiredSdk
{
<#
.DESCRIPTION
Gets the desired .NET Core SDK version from the global.json file.
#>

Get-Content "global.json" `
| ConvertFrom-Json `
| ForEach-Object { $_.sdk.version.ToString() }
}

function Get-NetCoreSdkFromWeb ($version)
{
<#
.DESCRIPTION
Downloads the desired .NET Core SDK version from the internet and saves it under a temporary file name which will be returned by the function.
.PARAMETER version
The SDK version which should be downloaded.
#>

$os = if (Test-IsWindows) { "windows" } else { "linux" }

$response = Invoke-WebRequest `
-Uri "https://www.microsoft.com/net/download/thank-you/dotnet-sdk-$version-$os-x64-binaries" `
-Method Get `
-MaximumRedirection 0 `

$downloadLink =
$response.Links `
| Where-Object { $_.onclick -eq "recordManualDownload()" } `
| Select-Object -Expand href

$tempFile = [System.IO.Path]::GetTempFileName()
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadLink, $tempFile)
return $tempFile
}

function Install-NetCoreSdk ($sdkZipPath)
{
<#
.DESCRIPTION
Extracts the zip archive which contains the .NET Core SDK and installs it in the current working directory under .dotnetsdk.
.PARAMETER version
The zip archive which contains the .NET Core SDK.
#>


$env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
New-Item $env:DOTNET_INSTALL_DIR -ItemType Directory -Force

Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($sdkZipPath, $env:DOTNET_INSTALL_DIR)
$env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
}

# ----------------------------------------------
# AppVeyor functions
# ----------------------------------------------
Expand All @@ -175,16 +280,43 @@ function Test-IsAppVeyorBuild { return ($env:APPVEYOR -eq $true
function Test-IsAppVeyorBuildTriggeredByGitTag { return ($env:APPVEYOR_REPO_TAG -eq $true) }
function Get-AppVeyorGitTag { return $env:APPVEYOR_REPO_TAG_NAME }

function Update-AppVeyorBuildVersion ($projFile)
function Update-AppVeyorBuildVersion ($version)
{
if (Test-IsAppVeyorBuild)
{
Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta

[xml]$xml = Get-Content $projFile
$version = $xml.Project.PropertyGroup.Version
$buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER"
Write-Host "Setting AppVeyor build version to $buildVersion."
Update-AppveyorBuild -Version $buildVersion
}
}

# ----------------------------------------------
# Host Writing functions
# ----------------------------------------------

function Write-BuildHeader ($projectTitle)
{
$header = " $projectTitle ";
$bar = ""
for ($i = 0; $i -lt $header.Length; $i++) { $bar += "-" }

Write-Host ""
Write-Host $bar -ForegroundColor DarkYellow
Write-Host $header -ForegroundColor DarkYellow
Write-Host $bar -ForegroundColor DarkYellow
Write-Host ""
}

function Write-SuccessFooter ($msg)
{
$footer = " $msg ";
$bar = ""
for ($i = 0; $i -lt $footer.Length; $i++) { $bar += "-" }

Write-Host ""
Write-Host $bar -ForegroundColor Green
Write-Host $footer -ForegroundColor Green
Write-Host $bar -ForegroundColor Green
Write-Host ""
}
60 changes: 4 additions & 56 deletions .psscripts/install-dotnet.ps1
Original file line number Diff line number Diff line change
@@ -1,67 +1,15 @@
# ----------------------------------------------------------
# Install script to check and download the correct .NET SDK
# ----------------------------------------------------------

function Test-IsWindows
{
[environment]::OSVersion.Platform -ne "Unix"
}

function Invoke-Cmd ($cmd)
{
Write-Host $cmd -ForegroundColor DarkCyan
if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" }
Invoke-Expression -Command $cmd
if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return }
}

function dotnet-version { Invoke-Cmd "dotnet --version" }

function Get-DesiredSdk
{
Get-Content "global.json" | ConvertFrom-Json | % { $_.sdk.version.ToString() }
}

function Get-NetCoreSdk ($version)
{
$os = if (Test-IsWindows) { "windows" } else { "linux" }

$response = Invoke-WebRequest `
-Uri "https://www.microsoft.com/net/download/thank-you/dotnet-sdk-$version-$os-x64-binaries" `
-Method Get `
-MaximumRedirection 0 `

$downloadLink =
$response.Links `
| Where-Object { $_.onclick -eq "recordManualDownload()" } `
| Select-Object -Expand href

$tempFile = [System.IO.Path]::GetTempFileName()
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadLink, $tempFile)
return $tempFile
}

function Install-NetCoreSdk ($sdkZipPath)
{
$env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
New-Item $env:DOTNET_INSTALL_DIR -ItemType Directory -Force

Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($sdkZipPath, $env:DOTNET_INSTALL_DIR)
$env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
}

# ----------------------------------------------
# Install .NET Core SDK
# ----------------------------------------------

$ErrorActionPreference = "Stop"

Import-module "$PSScriptRoot\build-functions.ps1" -Force

# Rename the global.json before making the dotnet --version call
# This will prevent AppVeyor to fail because it might not find
# the desired SDK specified in the global.json
$globalJson = Get-Item "global.json"
$globalJson = Get-Item "$PSScriptRoot\..\global.json"
Rename-Item -Path $globalJson.FullName -NewName "global.json.bak" -Force

# Get the current .NET Core SDK version
Expand All @@ -81,7 +29,7 @@ if ($desiredSdk -eq $currentSdk)
Write-Host "The current .NET SDK ($currentSdk) doesn't match the project's desired .NET SDK ($desiredSdk)." -ForegroundColor Yellow
Write-Host "Attempting to download and install the correct .NET SDK..."

$sdkZipPath = Get-NetCoreSdk $desiredSdk
$sdkZipPath = Get-NetCoreSdkFromWeb $desiredSdk
Install-NetCoreSdk $sdkZipPath

Write-Host ".NET SDK installation complete." -ForegroundColor Green
Expand Down
2 changes: 1 addition & 1 deletion .psscripts/nuget.ps1 → .psscripts/nuget-updates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Write-Host " Scanning all projects for NuGet package upgrades "
Write-Host "--------------------------------------------------"
Write-Host ""

$projects = Get-ChildItem "*.*proj" -Recurse | % { $_.FullName }
$projects = Get-ChildItem "..\**\*.*proj" -Recurse | % { $_.FullName }

foreach ($project in $projects)
{
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ language: csharp
sudo: required
dist: trusty

dotnet: 2.1.400
dotnet: 2.1.402

mono:
- 4.6.1
- 4.8.1
Expand Down
Loading

0 comments on commit 7981279

Please sign in to comment.