-
Notifications
You must be signed in to change notification settings - Fork 11
/
Build.ps1
80 lines (61 loc) · 2.61 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
$ErrorActionPreference = 'Stop'
$framework = 'net6.0'
function Clean-Output
{
if(Test-Path ./artifacts) { rm ./artifacts -Force -Recurse }
}
function Restore-Packages
{
& dotnet restore
}
function Execute-Tests
{
& dotnet test ./test/Datalust.ClefTool.Tests/Datalust.ClefTool.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", "linux-arm64", "osx-x64", "win-x64", "osx-arm64")
foreach ($rid in $rids) {
$tfm = $framework
& dotnet publish ./src/Datalust.ClefTool/Datalust.ClefTool.csproj -c Release -f $tfm -r $rid --self-contained `
/p:VersionPrefix=$version /p:PublishSingleFile=true /p:PublishReadyToRun=true
if($LASTEXITCODE -ne 0) { exit 4 }
# Make sure the archive contains a reasonable root filename
mv ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/publish/ ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/
if ($rid.StartsWith("win-")) {
& ./build/7-zip/7za.exe a -tzip ./artifacts/clef-$version-$rid.zip ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }
# Back to the original directory name
mv ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/ ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/publish/
} else {
& ./build/7-zip/7za.exe a -ttar clef-$version-$rid.tar ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }
# Back to the original directory name
mv ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/ ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/publish/
& ./build/7-zip/7za.exe a -tgzip ./artifacts/clef-$version-$rid.tar.gz clef-$version-$rid.tar
if($LASTEXITCODE -ne 0) { exit 6 }
rm clef-$version-$rid.tar
}
}
}
function Publish-DotNetTool($version)
{
# Tool packages have to target a single non-platform-specific TFM; doing this here is cleaner than attempting it in the CSPROJ directly
& dotnet pack ./src/Datalust.ClefTool/Datalust.ClefTool.csproj -c Release --output ./artifacts /p:VersionPrefix=$version /p:TargetFrameworks=$framework
if($LASTEXITCODE -ne 0) { exit 7 }
}
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