-
-
Notifications
You must be signed in to change notification settings - Fork 11
324 lines (276 loc) · 11.4 KB
/
build-release.yml
File metadata and controls
324 lines (276 loc) · 11.4 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: Build and Publish Preview Release
on:
push:
pull_request:
workflow_dispatch:
inputs:
dbatools_branch:
description: 'dbatools branch to use (default: development)'
required: false
default: 'development'
env:
TENANTID: ${{ secrets.TENANTID }}
CLIENTID: ${{ secrets.CLIENTID }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLIENT_GUID_SECRET: ${{ secrets.CLIENT_GUID_SECRET }}
CLIENT_GUID: ${{ secrets.CLIENT_GUID }}
SMODefaultModuleName: dbatools
jobs:
setup-dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout dbatools repo
uses: actions/checkout@v4
with:
repository: dataplat/dbatools
ref: ${{ github.event.inputs.dbatools_branch || 'development' }}
path: dbatools
- name: Clone appveyor repo
run: git clone https://github.com/dataplat/appveyor-lab.git appveyor-lab
- name: Create tar archive with dot files
run: |
cd dbatools
tar -czf ../dbatools-repo.tar.gz --exclude='.git' .
cd ..
- name: Upload dbatools repo artifact
uses: actions/upload-artifact@v4
with:
name: dbatools-repo
path: dbatools-repo.tar.gz
- name: Upload appveyor repo artifact
uses: actions/upload-artifact@v4
with:
name: appveyor-repo
path: appveyor-lab
build-library:
runs-on: windows-latest
needs: setup-dependencies
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
6.0.x
- name: Install .NET Framework targeting packs
shell: pwsh
run: choco install netfx-4.7.2-devpack -y --no-progress
- name: Build complete library
shell: pwsh
run: .\build\build.ps1 -BuildZip
- name: Verify critical files
shell: pwsh
run: |
$artifactsDir = "./artifacts/dbatools.library"
$criticalPaths = @(
"desktop/lib",
"desktop/lib/runtimes/win-x64/native",
"desktop/third-party",
"core/lib",
"core/lib/runtimes/win-x64/native",
"core/third-party"
)
$missingPaths = @()
foreach ($path in $criticalPaths) {
$fullPath = Join-Path $artifactsDir $path
if (Test-Path $fullPath) {
Write-Host "✅ Found: $path" -ForegroundColor Green
} else {
Write-Host "❌ Missing: $path" -ForegroundColor Red
$missingPaths += $path
}
}
if ($missingPaths.Count -gt 0) {
Write-Host "Critical paths missing:" -ForegroundColor Red
$missingPaths | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
exit 1
}
Write-Host "All critical paths verified!" -ForegroundColor Green
- name: Upload library artifact
uses: actions/upload-artifact@v4
with:
name: dbatools-library
path: artifacts/dbatools.library/
- name: Upload release zip
uses: actions/upload-artifact@v4
with:
name: dbatools-library-zip
path: artifacts/dbatools.library.zip
test-matrix:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: build-library
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
script: ./dbatools/.github/scripts/gh-actions.ps1
shell: pwsh
working-directory: ${{ github.workspace }}
- os: macos-latest
script: ./dbatools/.github/scripts/gh-macactions.ps1
shell: pwsh
working-directory: ${{ github.workspace }}
- os: windows-latest
script: ./dbatools/.github/scripts/gh-winactions.ps1
shell: pwsh
working-directory: ${{ github.workspace }}
steps:
- uses: actions/checkout@v4
- name: Setup docker images (Linux only)
if: matrix.os == 'ubuntu-latest'
run: |
docker network create localnet
docker run -p 1433:1433 --volume shared:/shared:z --name mssql1 --hostname mssql1 --network localnet -d dbatools/sqlinstance
docker run -p 14333:1433 --volume shared:/shared:z --name mssql2 --hostname mssql2 --network localnet -d dbatools/sqlinstance2
- name: Install local SQL engine via mssqlsuite (Windows only)
if: matrix.os == 'windows-latest'
uses: potatoqualitee/mssqlsuite@v1.9
with:
install: sqlengine
sa-password: dbatools.I0
- name: Download dbatools.library artifact
uses: actions/download-artifact@v4
with:
name: dbatools-library-zip
- name: Download dbatools repo artifact
uses: actions/download-artifact@v4
with:
name: dbatools-repo
- name: Extract dbatools repo
run: |
mkdir -p dbatools
tar -xzf dbatools-repo.tar.gz -C dbatools
- name: Download appveyor repo artifact
uses: actions/download-artifact@v4
with:
name: appveyor-repo
path: appveyor-lab
- name: Extract library
shell: pwsh
run: |
New-Item -ItemType Directory -Path ./artifacts -Force | Out-Null
Expand-Archive -Path ./dbatools.library.zip -DestinationPath ./artifacts -Force
if (Test-Path ./artifacts/dbatools.library/dbatools.library.psd1) {
Write-Host "✅ Library extracted successfully" -ForegroundColor Green
} else {
Write-Error "❌ Failed to extract library"
exit 1
}
- name: Configure dbatools
shell: pwsh
run: |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
Import-Module ./dbatools/dbatools.psd1 -Force
Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Register
Set-DbatoolsConfig -FullName sql.connection.encrypt -Value $false -Register
if ($IsLinux) {
New-Item -ItemType Directory -Path /tmp/DbatoolsExport -Force | Out-Null
}
- name: Verify SqlClient runtime asset selection
uses: ./.github/actions/verify-sqlclient
- name: Install SqlPackagetests
shell: pwsh
run: |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
Import-Module ./dbatools/dbatools.psd1 -Force
Install-DbaSqlPackage -Verbose
- name: Debug working directory
shell: pwsh
run: |
Write-Host "Current working directory: $(Get-Location)"
Write-Host "Repository workspace: ${{ github.workspace }}"
Write-Host "Script path to execute: ${{ matrix.script }}"
Write-Host "Full script path: ${{ github.workspace }}/${{ matrix.script }}"
Write-Host "Directory tree from workspace root:"
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Where-Object Name -match github
- name: Run integration tests (PowerShell Core)
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
Import-Module ./dbatools/dbatools.psd1 -Force
$ErrorActionPreference = "Stop"
Write-Host "Running integration tests with ${{ matrix.script }}"
$null = Invoke-Pester ${{ matrix.script }} -Output Detailed -PassThru
- name: Run integration tests (Windows PowerShell)
if: matrix.os == 'windows-latest'
shell: powershell
working-directory: ${{ github.workspace }}
run: |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force
Import-Module ./dbatools/dbatools.psd1 -Force
$ErrorActionPreference = "Stop"
Write-Host "Running integration tests with ${{ matrix.script }} (Windows PowerShell)"
$null = Invoke-Pester ${{ matrix.script }} -Output Detailed -PassThru
create-preview-release:
needs: test-matrix
runs-on: windows-latest
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download release zip
uses: actions/download-artifact@v4
with:
name: dbatools-library-zip
- name: Extract library for version info
shell: pwsh
run: |
New-Item -ItemType Directory -Path ./artifacts -Force | Out-Null
Expand-Archive -Path ./dbatools.library.zip -DestinationPath ./artifacts -Force
- name: Generate preview version and update manifest
id: get_version
shell: pwsh
run: |
$date = Get-Date -Format "yyyy.M.d"
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
$branch = "${{ github.ref_name }}" -replace '[^A-Za-z0-9]', ''
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$previewVersion = "$date-preview-$branch-$timestamp"
} else {
$manifestPath = "./artifacts/dbatools.library/dbatools.library.psd1"
$manifest = Import-PowerShellDataFile $manifestPath
$currentVersion = $manifest.ModuleVersion
if ($currentVersion -like "*preview*") {
$previewVersion = "$currentVersion-$branch-$timestamp"
} else {
$previewVersion = "$date-preview-$branch-$timestamp"
}
}
Write-Host "Preview version: $previewVersion"
$psd1Version = if ($previewVersion -match '^(.*?-preview)') { $matches[1] } else { $previewVersion }
$manifestPath = "./artifacts/dbatools.library/dbatools.library.psd1"
$content = Get-Content $manifestPath -Raw
$content = $content -replace "ModuleVersion\s*=\s*'[^']*'", "ModuleVersion = '$psd1Version'"
Set-Content $manifestPath $content
"version=$previewVersion" >> $env:GITHUB_OUTPUT
"branch=$branch" >> $env:GITHUB_OUTPUT
- name: Create Preview Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.get_version.outputs.version }}
name: Preview Release v${{ steps.get_version.outputs.version }}
body: |
This is an automated preview release.
**Trigger Reason:** ${{ github.event_name == 'workflow_dispatch' && 'Manual workflow dispatch' || 'Version contains preview' }}
**Module Version:** ${{ steps.get_version.outputs.version }}
**Branch:** ${{ steps.get_version.outputs.branch }}
**Commit:** ${{ github.sha }}
**Build Date:** ${{ github.event.head_commit.timestamp }}
## Installation
```powershell
# Download and extract the zip file
Invoke-WebRequest -Uri "https://github.com/${{ github.repository }}/releases/download/v${{ steps.get_version.outputs.version }}/dbatools.library.zip" -OutFile dbatools.library.zip
Expand-Archive -Path dbatools.library.zip -DestinationPath . -Force
# Import the module
Import-Module ./dbatools.library.psd1
```
⚠️ **Note:** This is a preview release and should not be used in production.
draft: false
prerelease: true
files: ./dbatools.library.zip