-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.ps1
148 lines (121 loc) · 4.68 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
param (
[string]
$ProjectOrSolutionPath = "SoftwareUpdater\SoftwareUpdater.csproj",
[bool]
$TestOnly = $False,
[bool]
$BuildSimpleUpdaterOnly = $False,
[bool]
$ShouldExit = $False
)
function Main {
# inspired by ci script from https://github.com/datalust/piggy.
# inspired by ci script from https://github.com/Azure/azure-functions-core-tools.
$path = $ProjectOrSolutionPath
[string] $ciTag = If ([string]::IsNullOrEmpty($env:APPVEYOR_REPO_TAG_NAME)) {$env:CI_COMMIT_TAG} Else {$env:APPVEYOR_REPO_TAG_NAME}
$isReleaseBuild = ![string]::IsNullOrEmpty($ciTag)
[string] $versionToBuild = $NULL
if ($isReleaseBuild) {
$versionToBuild = If ($ciTag.StartsWith('v')) {$ciTag.SubString(1)} Else {$ciTag}
}
Write-Host "Building $(If ([string]::IsNullOrEmpty($versionToBuild)) { "default version" } Else { "version $versionToBuild" } )"
Push-Location $PSScriptRoot
if ($TestOnly) {
Start-Tests
} elseif ($BuildSimpleUpdaterOnly) {
Publish-SimpleUpdate -Version "$versionToBuild"
} else {
Publish-SimpleUpdate -Version "$versionToBuild"
Start-Tests
New-ArtifactDir
Publish-NugetPackage -Path "$path" -Version "$versionToBuild"
}
Pop-Location
}
function New-ArtifactDir {
if (Test-Path "./artifacts") {
Remove-Item -Path "./artifacts" -Force -Recurse
}
New-Item -Path "." -Name "artifacts" -ItemType "directory" | Out-Null
}
function Start-Tests {
if (-Not (Test-Exe("dotnet"))) {
Throw "The executable dotnet was not found in your path."
}
foreach ($file in Get-ChildItem -Path . -Recurse | Where-Object {$_.Name -like "*.Test.csproj"}) {
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
Write-Host "Testing assembly $($file.Name)"
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
iu dotnet test "$($file.FullName)" --verbosity "minimal"
}
}
function Publish-SimpleUpdate {
param (
$Version
)
if (-Not (Test-Exe("msbuild"))) {
Throw "The executable msbuild was not found in your path."
}
$simpleUpdaterCsproj = "SimpleFileUpdater/SimpleFileUpdater/SimpleFileUpdater.csproj"
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
Write-Host "Building SimpleFileUpdater"
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
iu msbuild "$simpleUpdaterCsproj" "/verbosity:minimal" "/t:Restore,Publish" "/p:Configuration=Release" "/bl:SimpleFileUpdater/net20.binlog" "/p:AdminManifest=false" "/p:TargetFramework=net461" $(If ([string]::IsNullOrEmpty($Version)) { "" } Else { "/p:Version=$Version" })
iu msbuild "$simpleUpdaterCsproj" "/verbosity:minimal" "/t:Restore,Publish" "/p:Configuration=Release" "/bl:SimpleFileUpdater/net20.admin.binlog" "/p:AdminManifest=true" "/p:TargetFramework=net461" $(If ([string]::IsNullOrEmpty($Version)) { "" } Else { "/p:Version=$Version" })
iu msbuild "$simpleUpdaterCsproj" "/verbosity:minimal" "/t:Restore,Publish" "/p:Configuration=Release" "/bl:SimpleFileUpdater/netcoreapp2.0.binlog" "/p:AdminManifest=false" "/p:TargetFramework=netcoreapp2.0" $(If ([string]::IsNullOrEmpty($Version)) { "" } Else { "/p:Version=$Version" })
}
function Publish-NugetPackage {
param (
$Path,
$Version
)
if (-Not (Test-Exe("msbuild"))) {
Throw "The executable msbuild was not found in your path."
}
$publishDir = Resolve-Path -Path "./artifacts"
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
Write-Host "Publishing nuget package"
Write-Host "@@@@@@@@@@@@@@@@@@@@@@@"
iu msbuild "$path" "/verbosity:minimal" "/t:Restore,Pack" "/p:Configuration=Release" "/bl:pack.binlog" "/p:PackageOutputPath=$publishDir" $(If ([string]::IsNullOrEmpty($Version)) { "" } Else { "/p:Version=$Version" })
}
function Test-Exe($exeName) {
return [bool](Get-Command $exeName -ErrorAction SilentlyContinue);
}
function Invoke-Utility {
<#
.SYNOPSIS
Invokes an external utility, ensuring successful execution.
.DESCRIPTION
Invokes an external utility (program) and, if the utility indicates failure by
way of a nonzero exit code, throws a script-terminating error.
* Pass the command the way you would execute the command directly.
* Do NOT use & as the first argument if the executable name is not a literal.
.EXAMPLE
Invoke-Utility git push
Executes `git push` and throws a script-terminating error if the exit code
is nonzero.
#>
$exe, $argsForExe = $Args
$ErrorActionPreference = 'Stop' # in case $exe isn't found
& $exe $argsForExe
if ($LASTEXITCODE) {
Throw "$exe indicated failure (exit code $LASTEXITCODE; full command: $Args)."
}
}
[int] $exitcode = 0
try {
Set-Alias iu Invoke-Utility
Main
} catch {
if (-Not $ShouldExit) {
throw $_.Exception
}
$exceptionCatched = $_.Exception.ToString()
Write-Host "Exception : $exceptionCatched"
$exitcode = 1
}
if ($ShouldExit) {
Write-Host "Exit code $exitcode"
$host.SetShouldExit($exitcode)
exit
}