Skip to content

Commit c0cf0da

Browse files
Refresh integrity tree before packaging
1 parent c21e6f9 commit c0cf0da

4 files changed

Lines changed: 63 additions & 21 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,15 @@ jobs:
225225
-CertificateName '${{ secrets.CODE_SIGNING_CERTIFICATE_NAME }}' `
226226
-TimestampServer '${{ vars.CODE_SIGNING_TIMESTAMP_SERVER }}'
227227
228-
- name: Generate integrity tree
229-
shell: pwsh
230-
run: .\scripts\generate-integrity-tree.ps1 -Path $PWD/unigetui_bin -MinOutput
231-
232-
- name: Validate integrity tree
233-
shell: pwsh
234-
run: .\scripts\verify-integrity-tree.ps1 -Path $PWD/unigetui_bin -FailOnUnexpectedFiles
235-
236228
- name: Build installer
237229
shell: pwsh
238230
run: |
239231
$Platform = '${{ matrix.platform }}'
240232
$OutputDir = Join-Path $PWD "output"
241233
New-Item $OutputDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
242234
235+
.\scripts\refresh-integrity-tree.ps1 -Path $PWD/unigetui_bin -FailOnUnexpectedFiles
236+
243237
# Configure Inno Setup to use AzureSignTool
244238
$IssPath = "UniGetUI.iss"
245239
@@ -266,6 +260,8 @@ jobs:
266260
$Platform = '${{ matrix.platform }}'
267261
New-Item "output" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
268262
263+
.\scripts\refresh-integrity-tree.ps1 -Path $PWD/unigetui_bin -FailOnUnexpectedFiles
264+
269265
# Zip
270266
Compress-Archive -Path "unigetui_bin/*" -DestinationPath "output/UniGetUI.$Platform.zip" -CompressionLevel Optimal
271267

scripts/build.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,14 @@ Get-ChildItem $PublishDir | Move-Item -Destination $BinDir -Force
9494
# WingetUI.exe alias for backward compat
9595
Copy-Item (Join-Path $BinDir "UniGetUI.exe") (Join-Path $BinDir "WingetUI.exe") -Force
9696

97-
# --- Integrity tree ---
98-
Write-Host "`n=== Generating integrity tree ===" -ForegroundColor Cyan
99-
& (Join-Path $PSScriptRoot "generate-integrity-tree.ps1") -Path $BinDir -MinOutput
100-
101-
Write-Host "`n=== Validating integrity tree ===" -ForegroundColor Cyan
102-
& (Join-Path $PSScriptRoot "verify-integrity-tree.ps1") -Path $BinDir -FailOnUnexpectedFiles
103-
10497
# --- Package output ---
10598
if (Test-Path $OutputPath) { Remove-Item $OutputPath -Recurse -Force }
10699
New-Item $OutputPath -ItemType Directory | Out-Null
107100

108101
$ZipPath = Join-Path $OutputPath "UniGetUI.$Platform.zip"
102+
Write-Host "`n=== Refreshing integrity tree before zip packaging ===" -ForegroundColor Cyan
103+
& (Join-Path $PSScriptRoot "refresh-integrity-tree.ps1") -Path $BinDir -FailOnUnexpectedFiles
104+
109105
Write-Host "`n=== Creating zip: $ZipPath ===" -ForegroundColor Cyan
110106
Compress-Archive -Path (Join-Path $BinDir "*") -DestinationPath $ZipPath -CompressionLevel Optimal
111107

@@ -130,6 +126,9 @@ if (-not $SkipInstaller) {
130126
$IssPath = Join-Path $RepoRoot "UniGetUI.iss"
131127
$IssContent = Get-Content $IssPath -Raw
132128

129+
Write-Host "`n=== Refreshing integrity tree before installer packaging ===" -ForegroundColor Cyan
130+
& (Join-Path $PSScriptRoot "refresh-integrity-tree.ps1") -Path $BinDir -FailOnUnexpectedFiles
131+
133132
try {
134133
$IssContentNoSign = $IssContent -Replace '(?m)^SignTool=.*$', '; SignTool=azsign (disabled for local build)'
135134
$IssContentNoSign = $IssContentNoSign -Replace '(?m)^SignedUninstaller=yes', 'SignedUninstaller=no'

scripts/refresh-integrity-tree.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env pwsh
2+
<#
3+
.SYNOPSIS
4+
Regenerates IntegrityTree.json and validates it against the current folder contents.
5+
6+
.PARAMETER Path
7+
The directory whose IntegrityTree.json should be refreshed and validated.
8+
9+
.PARAMETER FailOnUnexpectedFiles
10+
Fail validation if files exist in the directory tree but are not present in
11+
IntegrityTree.json.
12+
#>
13+
14+
[CmdletBinding()]
15+
param(
16+
[Parameter(Mandatory, Position = 0)]
17+
[string] $Path,
18+
19+
[switch] $FailOnUnexpectedFiles
20+
)
21+
22+
$ErrorActionPreference = 'Stop'
23+
24+
if (-not (Test-Path $Path -PathType Container)) {
25+
throw "The directory '$Path' does not exist."
26+
}
27+
28+
$Path = (Resolve-Path $Path).Path
29+
$GenerateScriptPath = Join-Path $PSScriptRoot 'generate-integrity-tree.ps1'
30+
$VerifyScriptPath = Join-Path $PSScriptRoot 'verify-integrity-tree.ps1'
31+
32+
if (-not (Test-Path $GenerateScriptPath -PathType Leaf)) {
33+
throw "Integrity tree generator not found at '$GenerateScriptPath'."
34+
}
35+
36+
if (-not (Test-Path $VerifyScriptPath -PathType Leaf)) {
37+
throw "Integrity tree validator not found at '$VerifyScriptPath'."
38+
}
39+
40+
Write-Host "Refreshing integrity tree in $Path..."
41+
& $GenerateScriptPath -Path $Path -MinOutput
42+
43+
$ValidationParameters = @{ Path = $Path }
44+
if ($FailOnUnexpectedFiles) {
45+
$ValidationParameters.FailOnUnexpectedFiles = $true
46+
}
47+
48+
& $VerifyScriptPath @ValidationParameters

scripts/sign.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,15 @@ function Update-IntegrityTree {
115115
return
116116
}
117117

118-
$TreeScriptPath = Join-Path $PSScriptRoot "generate-integrity-tree.ps1"
119-
if (-not (Test-Path $TreeScriptPath -PathType Leaf)) {
120-
Write-Warning "Integrity tree generator not found at $TreeScriptPath"
118+
$TreeRefreshScriptPath = Join-Path $PSScriptRoot "refresh-integrity-tree.ps1"
119+
if (-not (Test-Path $TreeRefreshScriptPath -PathType Leaf)) {
120+
Write-Warning "Integrity tree refresh script not found at $TreeRefreshScriptPath"
121121
return
122122
}
123123

124-
Write-Host "Refreshing integrity tree in $RootPath..."
125-
& $TreeScriptPath -Path $RootPath -MinOutput
124+
& $TreeRefreshScriptPath -Path $RootPath -FailOnUnexpectedFiles
126125
if ($LASTEXITCODE -ne 0) {
127-
throw "generate-integrity-tree.ps1 failed with exit code $LASTEXITCODE"
126+
throw "refresh-integrity-tree.ps1 failed with exit code $LASTEXITCODE"
128127
}
129128
}
130129

0 commit comments

Comments
 (0)