-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-and-test.ps1
executable file
·159 lines (138 loc) · 5.58 KB
/
build-and-test.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
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/pwsh
[CmdletBinding(PositionalBinding = $false)]
param (
[string][Alias('c')]$configuration = "Debug",
[string][Alias('a')]$architecture,
[switch]$ci,
[switch]$noTest,
[string]$deployTo
)
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
function Set-EnvironmentVariable([string]$name, [string]$value) {
Write-Host "setting $name=$value"
if (Test-Path env:GITHUB_ENV) {
Write-Output "$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
}
try {
$runTests = -Not $noTest
if ($ci) {
$env:VERSION_SUFFIX = ./build/make-version.ps1 -suffix beta
}
Write-Host "Using VERSION_SUFFIX=$env:VERSION_SUFFIX"
# assign architecture
if ($architecture -eq '') {
if ($IsWindows) {
$architecture = if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { "x64" } else { "arm64" }
}
else {
$architecture = if ((arch | Out-String).Trim() -eq "x86_64") { "x64" } else { "arm64" }
}
}
# build submodule
Push-Location "$PSScriptRoot/src/IxMilia.Converters"
. .\build-and-test.ps1 -configuration $configuration -noTest
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Pop-Location
# restore
dotnet restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# build client contracts file
. ./build-contracts-files.ps1
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# build js client
Push-Location "$PSScriptRoot/src/javascript-client"
npm i
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if ($IsLinux -And $architecture -eq "arm64") {
# when cross-compiling for linux arm64, we specifically need the x64 version of icon-gen and sharp
foreach ($package in @("icon-gen", "sharp")) {
npm install --platform=linux --arch=x64 $package
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
}
npm run compile
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Pop-Location
# build
dotnet build --configuration $configuration --no-restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# tests
if ($runTests) {
dotnet test --no-restore --no-build --configuration $configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
# publish
$os = if ($IsLinux) { "linux" } elseif ($IsMacOS) { "osx" } elseif ($IsWindows) { "win" }
$packagesDir = "$PSScriptRoot/artifacts/packages/$configuration"
New-Item -ItemType Directory -Path $packagesDir -Force
$packageParentDir = "$PSScriptRoot/artifacts/publish/$configuration"
$packageOutputDir = "$packageParentDir/bcad-$os-$architecture"
. ./publish.ps1 -configuration $configuration -runtime "$os-$architecture" -output $packageOutputDir
if ($IsLinux -And ($architecture -eq "arm64") -And ($LASTEXITCODE -ne 0)) {
# this never works the first time?
. ./publish.ps1 -configuration $configuration -runtime "$os-$architecture" -output $packageOutputDir
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# remove unnecessary files
$unnecessaryFiles = @(
"bcad.dbg",
"bcad.pdb",
"IxMilia.Dxf.xml"
)
foreach ($file in $unnecessaryFiles) {
if (Test-Path "$packageOutputDir/$file") {
Remove-Item "$packageOutputDir/$file"
}
}
# create bccoreconsole
Push-Location "$PSScriptRoot/src/bccoreconsole"
$goarch = if ($architecture -eq "x64") { "amd64" } else { "arm64" }
$env:GOARCH = $goarch
go build -o "$packageOutputDir/" -buildvcs=false
$env:GOARCH = ""
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Pop-Location
# create package
$artifactShortName = "bcad-$os-$architecture"
$artifactExtension = if ($IsWindows) { "zip" } else { "tar.gz" }
$artifactName = "$artifactShortName.$artifactExtension"
$artifactPath = "$packagesDir/$artifactName"
Set-EnvironmentVariable "artifact_name" $artifactName
Set-EnvironmentVariable "artifact_path" $artifactPath
if ($IsWindows) {
Compress-Archive -Path "$packageOutputDir" -DestinationPath $artifactPath -Force
Set-EnvironmentVariable "secondary_artifact_name" "win-$architecture"
Set-EnvironmentVariable "secondary_artifact_path" $artifactPath
}
else {
$packageVersionPrefix = (Get-Content "$PSScriptRoot/version.txt" | Out-String).Trim()
$packageVersionSuffix = "$env:VERSION_SUFFIX"
if ($packageVersionSuffix -ne "") {
$packageVersionSuffix = ".$packageVersionSuffix"
}
$packageVersion = "$packageVersionPrefix$packageVersionSuffix"
$packageArchitecture = if ($architecture -eq "x64") { "amd64" } else { "arm64" }
$packageName = "bcad_${packageVersion}_$packageArchitecture.deb"
Set-EnvironmentVariable "secondary_artifact_name" "deb-$architecture"
Set-EnvironmentVariable "secondary_artifact_path" "$packagesDir/$packageName"
tar -zcf $artifactPath -C "$packageParentDir/" "$artifactShortName"
./build-package.sh --configuration $configuration --architecture $architecture
}
if ($deployTo -ne "") {
$deploySource = "$packageParentDir/$artifactShortName"
$deployDestination = "$deployTo/$artifactShortName"
if (Test-Path $deployDestination) {
Remove-Item -Path $deployDestination -Recurse -Force
}
Write-Host "Deploying to $deployDestination"
Copy-Item -Path $deploySource -Destination $deployDestination -Recurse -Force
}
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}