|
1 |
| -param( |
2 |
| - [String] $majorMinor = "0.0", # 2.0 |
3 |
| - [String] $patch = "0", # $env:APPVEYOR_BUILD_VERSION |
4 |
| - [String] $customLogger = "", # C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll |
5 |
| - [Switch] $notouch |
6 |
| -) |
7 |
| - |
8 |
| -function Set-AssemblyVersions($informational, $assembly) |
| 1 | +$root = $(Get-Item $($MyInvocation.MyCommand.Path)).DirectoryName |
| 2 | + |
| 3 | +function Install-Dnvm |
9 | 4 | {
|
10 |
| - (Get-Content assets/CommonAssemblyInfo.cs) | |
11 |
| - ForEach-Object { $_ -replace """1.0.0.0""", """$assembly""" } | |
12 |
| - ForEach-Object { $_ -replace """1.0.0""", """$informational""" } | |
13 |
| - ForEach-Object { $_ -replace """1.1.1.1""", """$($informational).0""" } | |
14 |
| - Set-Content assets/CommonAssemblyInfo.cs |
| 5 | + & where.exe dnvm 2>&1 | Out-Null |
| 6 | + if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true)) |
| 7 | + { |
| 8 | + Write-Host "DNVM not found" |
| 9 | + &{$Branch='dev';iex ((New-Object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))} |
| 10 | + |
| 11 | + # Normally this happens automatically during install but AppVeyor has |
| 12 | + # an issue where you may need to manually re-run setup from within this process. |
| 13 | + if($env:DNX_HOME -eq $NULL) |
| 14 | + { |
| 15 | + Write-Host "Initial DNVM environment setup failed; running manual setup" |
| 16 | + $tempDnvmPath = Join-Path $env:TEMP "dnvminstall" |
| 17 | + $dnvmSetupCmdPath = Join-Path $tempDnvmPath "dnvm.ps1" |
| 18 | + & $dnvmSetupCmdPath setup |
| 19 | + } |
| 20 | + } |
15 | 21 | }
|
16 | 22 |
|
17 |
| -function Install-NuGetPackages() |
| 23 | +function Get-DnxVersion |
18 | 24 | {
|
19 |
| - nuget restore serilog-sinks-splunk.sln |
| 25 | + $globalJson = Join-Path $PSScriptRoot "global.json" |
| 26 | + $jsonData = Get-Content -Path $globalJson -Raw | ConvertFrom-JSON |
| 27 | + return $jsonData.sdk.version |
20 | 28 | }
|
21 | 29 |
|
22 |
| -function Invoke-MSBuild($solution, $customLogger) |
| 30 | +function Restore-Packages |
23 | 31 | {
|
24 |
| - if ($customLogger) |
25 |
| - { |
26 |
| - msbuild "$solution" /verbosity:minimal /p:Configuration=Release /logger:"$customLogger" |
27 |
| - } |
28 |
| - else |
29 |
| - { |
30 |
| - msbuild "$solution" /verbosity:minimal /p:Configuration=Release |
31 |
| - } |
| 32 | + param([string] $DirectoryName) |
| 33 | + & dnu restore ("""" + $DirectoryName + """") |
32 | 34 | }
|
33 | 35 |
|
34 |
| -function Invoke-NuGetPackProj($csproj) |
| 36 | +function Build-Projects |
35 | 37 | {
|
36 |
| - nuget pack -Prop Configuration=Release -Symbols $csproj |
| 38 | + param($Directory, $pack) |
| 39 | + |
| 40 | + $DirectoryName = $Directory.DirectoryName |
| 41 | + $artifactsFolder = join-path $root "artifacts" |
| 42 | + $projectsFolder = join-path $artifactsFolder $Directory.Name |
| 43 | + $buildFolder = join-path $projectsFolder "testbin" |
| 44 | + $packageFolder = join-path $projectsFolder "packages" |
| 45 | + |
| 46 | + & dnu build ("""" + $DirectoryName + """") --configuration Release --out $buildFolder; if($LASTEXITCODE -ne 0) { exit 1 } |
| 47 | + |
| 48 | + if($pack){ |
| 49 | + & dnu pack ("""" + $DirectoryName + """") --configuration Release --out $packageFolder; if($LASTEXITCODE -ne 0) { exit 1 } |
| 50 | + } |
37 | 51 | }
|
38 |
| - |
39 |
| -function Invoke-NuGetPackSpec($nuspec, $version) |
| 52 | + |
| 53 | +function Test-Projects |
40 | 54 | {
|
41 |
| - nuget pack $nuspec -Version $version -OutputDirectory ..\..\ |
| 55 | + param([string] $DirectoryName) |
| 56 | + & dnx -p ("""" + $DirectoryName + """") test; if($LASTEXITCODE -ne 0) { exit 2 } |
42 | 57 | }
|
43 | 58 |
|
44 |
| -function Invoke-NuGetPack($version) |
45 |
| -{ |
46 |
| - pushd .\src\Serilog.Sinks.Splunk |
47 |
| - Invoke-NuGetPackSpec "Serilog.Sinks.Splunk.nuspec" $version |
48 |
| - popd |
| 59 | +function Remove-PathVariable |
| 60 | +{ |
| 61 | + param([string] $VariableToRemove) |
| 62 | + $path = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 63 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 64 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") |
| 65 | + $path = [Environment]::GetEnvironmentVariable("PATH", "Process") |
| 66 | + $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
| 67 | + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") |
49 | 68 | }
|
50 | 69 |
|
51 |
| -function Invoke-Build($majorMinor, $patch, $customLogger, $notouch) |
52 |
| -{ |
53 |
| - $package="$majorMinor.$patch" |
| 70 | +Push-Location $PSScriptRoot |
54 | 71 |
|
55 |
| - Write-Output "Building Serilog.Sinks.Splunk $package" |
| 72 | +$dnxVersion = Get-DnxVersion |
56 | 73 |
|
57 |
| - if (-not $notouch) |
58 |
| - { |
59 |
| - $assembly = "$majorMinor.0.0" |
| 74 | +# Clean |
| 75 | +if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } |
60 | 76 |
|
61 |
| - Write-Output "Assembly version will be set to $assembly" |
62 |
| - Set-AssemblyVersions $package $assembly |
63 |
| - } |
| 77 | +# Remove the installed DNVM from the path and force use of |
| 78 | +# per-user DNVM (which we can upgrade as needed without admin permissions) |
| 79 | +Remove-PathVariable "*Program Files\Microsoft DNX\DNVM*" |
64 | 80 |
|
65 |
| - Install-NuGetPackages |
66 |
| - |
67 |
| - Invoke-MSBuild "serilog-sinks-splunk.sln" $customLogger |
| 81 | +# Make sure per-user DNVM is installed |
| 82 | +Install-Dnvm |
68 | 83 |
|
69 |
| - Invoke-NuGetPack $package |
70 |
| -} |
| 84 | +# Install DNX |
| 85 | +dnvm install $dnxVersion -r CoreCLR -NoNative |
| 86 | +dnvm install $dnxVersion -r CLR -NoNative |
| 87 | +dnvm use $dnxVersion -r CLR |
| 88 | + |
| 89 | +# Package restore |
| 90 | +Get-ChildItem -Path . -Filter *.xproj -Recurse | ForEach-Object { Restore-Packages $_.DirectoryName } |
| 91 | + |
| 92 | +# Set build number |
| 93 | +$env:DNX_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 94 | +Write-Host "Build number: " $env:DNX_BUILD_VERSION |
| 95 | + |
| 96 | +# Build/package |
| 97 | +Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Build-Projects $_ $true } |
| 98 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Build-Projects $_ $false } |
| 99 | + |
| 100 | +# Test |
| 101 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName } |
| 102 | + |
| 103 | +# Switch to Core CLR |
| 104 | +dnvm use $dnxVersion -r CoreCLR |
| 105 | + |
| 106 | +# Test again |
| 107 | +Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object { Test-Projects $_.DirectoryName } |
71 | 108 |
|
72 |
| -$ErrorActionPreference = "Stop" |
73 |
| -Invoke-Build $majorMinor $patch $customLogger $notouch |
| 109 | +Pop-Location |
0 commit comments