-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild-tasks.ps1
More file actions
266 lines (221 loc) · 8.43 KB
/
build-tasks.ps1
File metadata and controls
266 lines (221 loc) · 8.43 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
param(
[Parameter()]
[string]
$GithubToken
)
task GithubBuild Initialize, Clean, Build, ThirdPartyNotices, Pack
task LocalBuild GithubBuild, UnitTest, IntegrationTest
task Pack PackGlobalTool, PackPoweShellModule, PackNuget472, PackManualDownload
task IntegrationTest InitializeIntegrationTest, PsDesktopTest, PsCoreTest, SdkToolTest, NetRuntimeLinuxTest, NetRuntimeWindowsTest
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
task Initialize {
$root = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..\..\'))
$sources = Join-Path $root 'Sources'
$bin = Join-Path $root 'bin'
$artifacts = Join-Path $bin 'artifacts'
$script:settings = @{
nugetexe = Join-Path $root 'Build\nuget.exe'
sources = $sources
bin = $bin
artifacts = $artifacts
artifactsPowerShell = Join-Path $artifacts 'PowerShell'
integrationTests = Join-Path $bin 'IntegrationTests'
version = Get-ReleaseVersion -SourcePath $sources
githubToken = $GithubToken
repositoryCommitId = git rev-parse HEAD
}
$script:frameworks = 'net472', 'net8.0', 'net9.0'
$script:databases = 'MsSql', 'PgSql', 'MySql'
Write-Output "PackageVersion: $($settings.version)"
Write-Output "CommitId: $($settings.repositoryCommitId)"
}
task Clean {
Remove-DirectoryRecurse -Path $settings.bin
Remove-DirectoryRecurse -Path $settings.sources -Filters 'bin', 'obj'
New-Item -Path $settings.bin -ItemType Directory | Out-Null
}
task Build {
$solutionFile = Join-Path $settings.sources 'SqlDatabase.slnx'
exec { dotnet restore $solutionFile }
exec { dotnet build $solutionFile -t:Rebuild -p:Configuration=Release }
}
task ThirdPartyNotices {
Invoke-Build -File 'build-tasks.third-party.ps1' -settings $settings
}
task PackGlobalTool {
$projectFile = Join-Path $settings.sources 'SqlDatabase\SqlDatabase.csproj'
exec {
dotnet pack `
-c Release `
-p:PackAsTool=true `
-p:GlobalTool=true `
-p:PackageVersion=$($settings.version) `
-p:RepositoryCommit=$($settings.repositoryCommitId) `
-o $($settings.artifacts) `
$projectFile
}
}
task PackPoweShellModule {
$source = Join-Path $settings.bin 'SqlDatabase.PowerShell'
$dest = $settings.artifactsPowerShell
Copy-Item -Path $source -Destination $dest -Recurse
# .psd1 set module version
$psdFile = Join-Path $dest 'SqlDatabase.psd1'
((Get-Content -Path $psdFile -Raw) -replace '1.2.3', $settings.version) | Set-Content -Path $psdFile
# copy license
Copy-Item -Path (Join-Path $settings.sources '..\LICENSE.md') -Destination $dest
# copy ThirdPartyNotices
Copy-Item -Path (Join-Path $settings.bin 'ThirdPartyNotices.txt') -Destination $dest
Get-ChildItem $dest -Include *.pdb -Recurse | Remove-Item
}
task PackNuget472 PackPoweShellModule, {
$bin = $settings.artifactsPowerShell
if (-not $bin.EndsWith('\')) {
$bin += '\'
}
$nuspec = Join-Path $settings.sources 'SqlDatabase.Package\nuget\package.nuspec'
exec {
& $($settings.nugetexe) pack `
-NoPackageAnalysis `
-verbosity detailed `
-OutputDirectory $($settings.artifacts) `
-Version $($settings.version) `
-p RepositoryCommit=$($settings.repositoryCommitId) `
-p bin=$bin `
$nuspec
}
}
task PackManualDownload PackGlobalTool, PackPoweShellModule, {
Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter 'publish' | Remove-Item -Force -Recurse
Get-ChildItem -Path $settings.bin -Recurse -Directory -Filter 'win-arm64' | Remove-Item -Force -Recurse
$out = $settings.artifacts
$lic = Join-Path $settings.sources '..\LICENSE.md'
$thirdParty = Join-Path $settings.bin 'ThirdPartyNotices.txt'
$packageVersion = $settings.version
$destination = Join-Path $out "SqlDatabase.$packageVersion-PowerShell.zip"
$source = Join-Path $settings.artifactsPowerShell '*'
Compress-Archive -Path $source -DestinationPath $destination
foreach ($target in $frameworks) {
$destination = Join-Path $out "SqlDatabase.$packageVersion-$target.zip"
$source = Join-Path $settings.bin "SqlDatabase\$target\*"
Compress-Archive -Path $source, $lic, $thirdParty -DestinationPath $destination
}
}
task UnitTest {
$builds = @()
foreach ($case in $frameworks) {
$builds += @{
File = 'build-tasks.unit-test.ps1'
Sources = $settings.sources
Framework = $case
}
}
Build-Parallel $builds -ShowParameter Framework -MaximumBuilds 4
}
task InitializeIntegrationTest {
$dest = $settings.integrationTests
if (Test-Path $dest) {
Remove-Item -Path $dest -Force -Recurse
}
Copy-Item -Path (Join-Path $settings.sources 'IntegrationTests') -Destination $dest -Force -Recurse
$assemblyScript = Join-Path $settings.bin '..\Examples\CSharpMirationStep\bin\Release\net472\2.1_2.2.*'
foreach ($database in $databases) {
Copy-Item -Path $assemblyScript -Destination (Join-Path $dest "$database\Upgrade") -Force
}
$bashLine = "sed -i 's/\r//g'"
foreach ($database in $databases) {
$bashLine += " test/$database/TestGlobalTool.sh test/$database/Test.sh"
}
# fix unix line endings
$test = $dest + ':/test'
exec {
docker run --rm `
-v $test `
mcr.microsoft.com/dotnet/sdk:8.0 `
bash -c $bashLine
}
}
task PsDesktopTest {
$builds = @()
foreach ($database in $databases) {
$builds += @{
File = 'build-tasks.it-ps-desktop.ps1'
settings = $settings
database = $database
}
}
Build-Parallel $builds -ShowParameter database -MaximumBuilds 1
}
task PsCoreTest {
# show-powershell-images.ps1
$images = $(
'mcr.microsoft.com/powershell:7.2.0-ubuntu-20.04'
, 'mcr.microsoft.com/powershell:7.2.1-ubuntu-20.04'
, 'mcr.microsoft.com/powershell:7.2.2-ubuntu-20.04'
, 'mcr.microsoft.com/powershell:7.3-ubuntu-20.04'
, 'mcr.microsoft.com/powershell:7.4-ubuntu-20.04'
, 'mcr.microsoft.com/powershell:preview-7.5-ubuntu-20.04')
$builds = @()
foreach ($image in $images) {
exec { docker pull -q $image }
foreach ($database in $databases) {
$builds += @{
File = 'build-tasks.it-ps-core.ps1'
settings = $settings
database = $database
image = $image
}
}
}
Build-Parallel $builds -ShowParameter database, image -MaximumBuilds 4
}
task SdkToolTest {
$images = $(
'sqldatabase/dotnet_pwsh:8.0-sdk'
, 'sqldatabase/dotnet_pwsh:9.0-sdk')
$builds = @()
foreach ($image in $images) {
foreach ($database in $databases) {
$builds += @{
File = 'build-tasks.it-tool-linux.ps1'
settings = $settings
database = $database
image = $image
}
}
}
Build-Parallel $builds -ShowParameter database, image -MaximumBuilds 4
}
task NetRuntimeLinuxTest {
$testCases = $(
@{ targetFramework = 'net8.0'; image = 'sqldatabase/dotnet_pwsh:8.0-runtime' }
, @{ targetFramework = 'net9.0'; image = 'sqldatabase/dotnet_pwsh:9.0-runtime' }
)
$builds = @()
foreach ($case in $testCases) {
foreach ($database in $databases) {
$builds += @{
File = 'build-tasks.it-linux.ps1'
settings = $settings
targetFramework = $case.targetFramework
database = $database
image = $case.image
}
}
}
Build-Parallel $builds -ShowParameter database, targetFramework, image -MaximumBuilds 4
}
task NetRuntimeWindowsTest {
$builds = @()
foreach ($case in $frameworks) {
foreach ($database in $databases) {
$builds += @{
File = 'build-tasks.it-win.ps1'
settings = $settings
targetFramework = $case
database = $database
}
}
}
Build-Parallel $builds -ShowParameter database, targetFramework -MaximumBuilds 4
}