-
Notifications
You must be signed in to change notification settings - Fork 56
/
build.ps1
105 lines (73 loc) · 2.74 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
param(
[string]$packageVersion = $null,
[string]$configuration = "Release"
)
. "./build-common.ps1"
$solutionName = "loggly"
$sourceUrl = "https://github.com/neutmute/loggly-csharp"
function init {
# Initialization
$global:rootFolder = Split-Path -parent $script:MyInvocation.MyCommand.Path
$global:rootFolder = Join-Path $rootFolder .
$global:packagesFolder = Join-Path $rootFolder packages
$global:outputFolder = Join-Path $rootFolder _output
# Test for AppVeyor config
if(!(Test-Path Env:\PackageVersion )){
$env:PackageVersion = $env:APPVEYOR_BUILD_VERSION
}
# Default when no env vars
if(!(Test-Path Env:\PackageVersion )){
$env:PackageVersion = "1.0.0.0"
}
_WriteOut -ForegroundColor $ColorScheme.Banner "-= $solutionName Build =-"
_WriteConfig "rootFolder" $rootFolder
_WriteConfig "version" $env:PackageVersion
}
function restorePackages{
_WriteOut -ForegroundColor $ColorScheme.Banner "nuget restore"
New-Item -Force -ItemType directory -Path $packagesFolder
_DownloadNuget $packagesFolder
nuget restore
dotnet restore "$rootFolder\$solutionName.sln"
checkExitCode
}
function nugetPack{
_WriteOut -ForegroundColor $ColorScheme.Banner "Nuget pack"
if(!(Test-Path Env:\nuget )){
$env:nuget = nuget
}
dotnet pack "$rootFolder\$solutionName.sln" --configuration $configuration --no-build --no-restore -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:ContinuousIntegrationBuild=true -p:EmbedUntrackedSources=true -p:PublishRepositoryUrl=true --output $outputFolder
checkExitCode
}
function nugetPublish{
if($env:APPVEYOR_PULL_REQUEST_NUMBER){
_WriteOut -ForegroundColor Yellow "Pull Request Build Detected. Skipping Publish"
}
else{
if(Test-Path Env:\nugetapikey ){
_WriteOut -ForegroundColor $ColorScheme.Banner "Nuget publish..."
&nuget push $outputFolder\* -ApiKey "$env:nugetapikey" -source https://www.nuget.org
}
else{
_WriteOut -ForegroundColor Yellow "nugetapikey environment variable not detected. Skipping nuget publish"
}
}
}
function buildSolution{
_WriteOut -ForegroundColor $ColorScheme.Banner "Build Solution"
New-Item -Force -ItemType directory -Path $outputFolder
dotnet build "$rootFolder\$solutionName.sln" --configuration $configuration -p:PackageVersion=$env:PackageVersion -p:ContinuousIntegrationBuild=true -p:EmbedUntrackedSources=true -p:PublishRepositoryUrl=true
checkExitCode
}
function executeTests{
_WriteOut -ForegroundColor $ColorScheme.Banner "Execute Tests"
dotnet test $rootFolder\source\Loggly.Tests
checkExitCode
}
init
restorePackages
buildSolution
executeTests
nugetPack
nugetPublish
Write-Host "Build $env:PackageVersion complete"