Skip to content

Commit bdd73ca

Browse files
authored
Merge pull request #3884 from BrentOzarULTD/3881_release_process
#3881 Build better merge/test/release process
2 parents 8fef37c + 2d5366e commit bdd73ca

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

Documentation/Development/Build Installation Scripts.ps1

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ $RepoRoot = (Resolve-Path "$ScriptDir\..\..\").Path
2626
$ErrorLog = Join-Path $ScriptDir "release_errors_$(Get-Date -Format 'yyyyMMdd').log"
2727
$Today = Get-Date -Format "yyyyMMdd"
2828
$BranchName = "${Today}_release_prep"
29+
$Utf8NoBom = New-Object System.Text.UTF8Encoding $false
2930

3031
# ── Helper: run a SQL string via sqlcmd, return output ───────────────────────
3132
function Invoke-SqlCmd-String {
3233
param([string]$Sql, [string]$Label)
3334

3435
$tmpFile = [System.IO.Path]::GetTempFileName() + ".sql"
35-
$Sql | Set-Content -Path $tmpFile -Encoding UTF8
36+
[System.IO.File]::WriteAllText($tmpFile, $Sql, $Utf8NoBom)
3637

3738
$prevPref = $ErrorActionPreference
3839
$ErrorActionPreference = "Continue"
@@ -69,7 +70,7 @@ $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
6970
--------------------------------------------------------------------------------
7071
$Details
7172
"@
72-
Add-Content -Path $ErrorLog -Value $entry
73+
Add-Content -Path $ErrorLog -Value $entry -Encoding UTF8
7374
Write-Host " FAIL: $Label" -ForegroundColor Red
7475
}
7576

@@ -118,13 +119,11 @@ try {
118119
# ══════════════════════════════════════════════════════════════════════════════
119120
Write-Host "`n=== Step 3: Update version numbers ===" -ForegroundColor Cyan
120121

121-
$versionPattern = "(?<=SELECT\s+@Version\s*=\s*')[^']+(?=',\s*@VersionDate\s*=\s*')[^']*'[^']+'"
122-
# Simpler approach: match the entire SELECT @Version line and replace
123122
$spFiles = Get-ChildItem -Path $RepoRoot -Filter "sp_*.sql"
124123
foreach ($file in $spFiles) {
125-
$content = Get-Content $file.FullName -Raw
124+
$content = [System.IO.File]::ReadAllText($file.FullName)
126125
$content = $content -replace "SELECT\s+@Version\s*=\s*'[^']+',\s*@VersionDate\s*=\s*'[^']+';", "SELECT @Version = '$newVersion', @VersionDate = '$Today';"
127-
Set-Content -Path $file.FullName -Value $content -NoNewline
126+
[System.IO.File]::WriteAllText($file.FullName, $content, $Utf8NoBom)
128127
Write-Host " Updated: $($file.Name)"
129128
}
130129

@@ -133,41 +132,41 @@ foreach ($file in $spFiles) {
133132
# ══════════════════════════════════════════════════════════════════════════════
134133
Write-Host "`n=== Step 4: Build Install-*.sql ===" -ForegroundColor Cyan
135134

136-
$SqlVersionsPath = Join-Path $RepoRoot "SqlServerVersions.sql"
137-
$BlitzFirstPath = Join-Path $RepoRoot "sp_BlitzFirst.sql"
138-
$InstallAllPath = Join-Path $RepoRoot "Install-All-Scripts.sql"
135+
$SqlVersionsPath = Join-Path $RepoRoot "SqlServerVersions.sql"
136+
$BlitzFirstPath = Join-Path $RepoRoot "sp_BlitzFirst.sql"
137+
$InstallAllPath = Join-Path $RepoRoot "Install-All-Scripts.sql"
139138
$InstallAzurePath = Join-Path $RepoRoot "Install-Azure.sql"
140139

141140
# ── Install-Azure.sql ────────────────────────────────────────────────────────
142-
# All sp_Blitz*.sql except sp_Blitz.sql, sp_BlitzBackups.sql, sp_DatabaseRestore.sql
143-
Get-ChildItem -Path $RepoRoot -Filter "sp_Blitz*.sql" |
141+
# All sp_Blitz*.sql except sp_Blitz.sql, sp_BlitzBackups.sql, sp_DatabaseRestore.sql, sp_BlitzFirst.sql
142+
$azureContent = Get-ChildItem -Path $RepoRoot -Filter "sp_Blitz*.sql" |
144143
Where-Object { $_.Name -ne "sp_Blitz.sql" -and $_.Name -notlike "*BlitzBackups*" -and $_.Name -notlike "*DatabaseRestore*" -and $_.Name -notlike "*BlitzFirst*" } |
145-
ForEach-Object { Get-Content $_.FullName } |
146-
Set-Content -Path $InstallAzurePath -Force
144+
ForEach-Object { Get-Content $_.FullName -Raw }
147145

148146
if (Test-Path $BlitzFirstPath) {
149-
Add-Content -Path $InstallAzurePath -Value (Get-Content -Path $BlitzFirstPath)
147+
$azureContent += Get-Content -Path $BlitzFirstPath -Raw
150148
}
151149

150+
[System.IO.File]::WriteAllText($InstallAzurePath, ($azureContent -join "`r`n"), $Utf8NoBom)
152151
Write-Host " Built: Install-Azure.sql"
153152

154153
# ── Install-All-Scripts.sql ──────────────────────────────────────────────────
155154
# All sp_*.sql except sp_BlitzInMemoryOLTP.sql and sp_BlitzFirst.sql
156-
Get-ChildItem -Path $RepoRoot -Filter "sp_*.sql" |
155+
$allContent = Get-ChildItem -Path $RepoRoot -Filter "sp_*.sql" |
157156
Where-Object { $_.Name -notlike "*BlitzInMemoryOLTP*" -and $_.Name -notlike "*BlitzFirst*" } |
158-
ForEach-Object { Get-Content $_.FullName } |
159-
Set-Content -Path $InstallAllPath -Force
157+
ForEach-Object { Get-Content $_.FullName -Raw }
160158

161159
# Append SqlServerVersions.sql
162160
if (Test-Path $SqlVersionsPath) {
163-
Add-Content -Path $InstallAllPath -Value (Get-Content -Path $SqlVersionsPath)
161+
$allContent += Get-Content -Path $SqlVersionsPath -Raw
164162
}
165163

166164
# Append sp_BlitzFirst.sql last
167165
if (Test-Path $BlitzFirstPath) {
168-
Add-Content -Path $InstallAllPath -Value (Get-Content -Path $BlitzFirstPath)
166+
$allContent += Get-Content -Path $BlitzFirstPath -Raw
169167
}
170168

169+
[System.IO.File]::WriteAllText($InstallAllPath, ($allContent -join "`r`n"), $Utf8NoBom)
171170
Write-Host " Built: Install-All-Scripts.sql"
172171

173172
# ══════════════════════════════════════════════════════════════════════════════

0 commit comments

Comments
 (0)