diff --git a/Build.ps1 b/Build.ps1 index 185d930..8349021 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,85 +1,48 @@ -param( - [String] $majorMinor = "0.0", # 2.0 - [String] $patch = "0", # $env:APPVEYOR_BUILD_VERSION - [String] $customLogger = "", # C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll - [Switch] $notouch, - [String] $sln # e.g serilog-sink-name -) +echo "build: Build started" -function Set-AssemblyVersions($informational, $assembly) -{ - (Get-Content assets/CommonAssemblyInfo.cs) | - ForEach-Object { $_ -replace """1.0.0.0""", """$assembly""" } | - ForEach-Object { $_ -replace """1.0.0""", """$informational""" } | - ForEach-Object { $_ -replace """1.1.1.1""", """$($informational).0""" } | - Set-Content assets/CommonAssemblyInfo.cs -} +Push-Location $PSScriptRoot -function Install-NuGetPackages($solution) -{ - nuget restore $solution +if(Test-Path .\artifacts) { + echo "build: Cleaning .\artifacts" + Remove-Item .\artifacts -Force -Recurse } -function Invoke-MSBuild($solution, $customLogger) -{ - if ($customLogger) - { - msbuild "$solution" /verbosity:minimal /p:Configuration=Release /logger:"$customLogger" - } - else - { - msbuild "$solution" /verbosity:minimal /p:Configuration=Release - } -} +& dotnet restore --no-cache -function Invoke-NuGetPackProj($csproj) -{ - nuget pack -Prop Configuration=Release -Symbols $csproj -} +$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; +$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$commitHash = $(git rev-parse --short HEAD) +$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] -function Invoke-NuGetPackSpec($nuspec, $version) -{ - nuget pack $nuspec -Version $version -OutputDirectory ..\..\ -} +echo "build: Package version suffix is $suffix" +echo "build: Build version suffix is $buildSuffix" -function Invoke-NuGetPack($version) -{ - ls src/**/*.csproj | - Where-Object { -not ($_.Name -like "*net40*") } | - ForEach-Object { Invoke-NuGetPackProj $_ } -} - -function Invoke-Build($majorMinor, $patch, $customLogger, $notouch, $sln) -{ - $package="$majorMinor.$patch" - $slnfile = "$sln.sln" - - Write-Output "$sln $package" +foreach ($src in ls src/*) { + Push-Location $src - if (-not $notouch) - { - $assembly = "$majorMinor.0.0" + echo "build: Packaging project in $src" - Write-Output "Assembly version will be set to $assembly" - Set-AssemblyVersions $package $assembly + & dotnet build -c Release --version-suffix=$buildSuffix + if ($suffix) { + & dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix --no-build + } else { + & dotnet pack -c Release --include-source -o ..\..\artifacts --no-build } + if($LASTEXITCODE -ne 0) { exit 1 } - Install-NuGetPackages $slnfile - - Invoke-MSBuild $slnfile $customLogger - - Invoke-NuGetPack $package + Pop-Location } -$ErrorActionPreference = "Stop" +foreach ($test in ls test/*.Tests) { + Push-Location $test + + echo "build: Testing project in $test" -if (-not $sln) -{ - $slnfull = ls *.sln | - Where-Object { -not ($_.Name -like "*net40*") } | - Select -first 1 + & dotnet test -c Release + if($LASTEXITCODE -ne 0) { exit 3 } - $sln = $slnfull.BaseName + Pop-Location } -Invoke-Build $majorMinor $patch $customLogger $notouch $sln +Pop-Location \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..9cdbbb1 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,25 @@ +version: '{build}' +skip_tags: true +image: Visual Studio 2017 +configuration: Release +install: + - ps: mkdir -Force ".\build\" | Out-Null +build_script: +- ps: ./Build.ps1 +test: off +artifacts: +- path: artifacts/Serilog.*.nupkg +deploy: +- provider: NuGet + api_key: + secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x + skip_symbols: true + on: + branch: /^(master|dev)$/ +- provider: GitHub + auth_token: + secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX + artifact: /Serilog.*\.nupkg/ + tag: v$(appveyor_build_version) + on: + branch: master \ No newline at end of file diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29