forked from Cimpress-MCP/serilog-sinks-awscloudwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
52 lines (39 loc) · 1.46 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$ErrorActionPreference = "Stop"
function Pack-Project
{
param([string] $DirectoryName)
Push-Location $DirectoryName
$revision = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "0.0.1" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
& dotnet pack -c Release -o ..\..\.\artifacts
if($LASTEXITCODE -ne 0) { exit 1 }
Pop-Location
}
function Update-BuildVersion
{
param([string] $FileName)
$revision = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "0.0.1" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
$csprojContent = Get-Content $FileName
$csprojContent | % { $_.Replace("<Version>0.0.1</Version>", "<Version>"+$revision+"</Version>") } | Set-Content $FileName
Write-Host "Set version of $FileName to $revision"
}
function Test-Project
{
param([string] $DirectoryName)
Push-Location $DirectoryName
& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
Pop-Location
}
Push-Location $PSScriptRoot
# Clean
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
# Modify .csproj
Get-ChildItem -Path .\src -Filter *.csproj -Recurse | ForEach-Object { Update-BuildVersion $_.FullName }
# Package restore
& dotnet restore
if($LASTEXITCODE -ne 0) { exit 1 }
# Build/package
Get-ChildItem -Path .\src -Filter *.csproj -Recurse | ForEach-Object { Pack-Project $_.DirectoryName }
# Test
Get-ChildItem -Path .\test -Filter *.csproj -Recurse | ForEach-Object { Test-Project $_.DirectoryName }
Pop-Location