forked from datalust/seqcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
77 lines (60 loc) · 2.13 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
$ErrorActionPreference = 'Stop'
$framework = 'net5.0'
$windowsTfmSuffix = '-windows'
function Clean-Output
{
if(Test-Path ./artifacts) { rm ./artifacts -Force -Recurse }
}
function Restore-Packages
{
& dotnet restore
}
function Execute-Tests
{
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release /p:Configuration=Release /p:Platform=x64 /p:VersionPrefix=$version
if($LASTEXITCODE -ne 0) { exit 3 }
}
function Create-ArtifactDir
{
mkdir ./artifacts
}
function Publish-Archives($version)
{
$rids = @("linux-x64", "linux-musl-x64", "osx-x64", "win-x64")
foreach ($rid in $rids) {
$tfm = $framework
if ($rid -eq "win-x64") {
$tfm = "$tfm$windowsTfmSuffix"
}
& dotnet publish ./src/SeqCli/SeqCli.csproj -c Release -f $tfm -r $rid /p:VersionPrefix=$version
if($LASTEXITCODE -ne 0) { exit 4 }
# Make sure the archive contains a reasonable root filename
mv ./src/SeqCli/bin/Release/$tfm/$rid/publish/ ./src/SeqCli/bin/Release/$tfm/$rid/seqcli-$version-$rid/
if ($rid.StartsWith("win-")) {
& ./build/7-zip/7za.exe a -tzip ./artifacts/seqcli-$version-$rid.zip ./src/SeqCli/bin/Release/$tfm/$rid/seqcli-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }
} else {
& ./build/7-zip/7za.exe a -ttar seqcli-$version-$rid.tar ./src/SeqCli/bin/Release/$tfm/$rid/seqcli-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }
# Back to the original directory name
mv ./src/SeqCli/bin/Release/$tfm/$rid/seqcli-$version-$rid/ ./src/SeqCli/bin/Release/$tfm/$rid/publish/
& ./build/7-zip/7za.exe a -tgzip ./artifacts/seqcli-$version-$rid.tar.gz seqcli-$version-$rid.tar
if($LASTEXITCODE -ne 0) { exit 6 }
rm seqcli-$version-$rid.tar
}
}
}
function Publish-DotNetTool($version)
{
dotnet pack ./src/SeqCli/SeqCli.csproj -c Release --output ./artifacts /p:VersionPrefix=$version
}
Push-Location $PSScriptRoot
$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
Write-Output "Building version $version"
Clean-Output
Create-ArtifactDir
Restore-Packages
Publish-Archives($version)
Publish-DotNetTool($version)
Execute-Tests
Pop-Location