param( [string]$Configuration = "Release" ) $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $PSScriptRoot $projectPath = Join-Path $repoRoot "src\OCSentinelCli\OCSentinelCli.csproj" $installerRoot = Join-Path $repoRoot "installer" $artifactsRoot = Join-Path $repoRoot "artifacts" $publishRoot = Join-Path $artifactsRoot "publish\win-x64" $packageRoot = Join-Path $artifactsRoot "client-package" $zipPath = Join-Path $artifactsRoot "OCSentinelClient-win-x64.zip" [xml]$projectXml = Get-Content $projectPath $version = $projectXml.Project.PropertyGroup.Version | Select-Object -First 1 if ([string]::IsNullOrWhiteSpace($version)) { $version = "0.0.0" } Write-Host "Building OfficeCom Sentinel client package version $version" if (Test-Path $publishRoot) { Remove-Item -LiteralPath $publishRoot -Recurse -Force } if (Test-Path $packageRoot) { Remove-Item -LiteralPath $packageRoot -Recurse -Force } if (Test-Path $zipPath) { Remove-Item -LiteralPath $zipPath -Force } New-Item -ItemType Directory -Force -Path $publishRoot, $packageRoot | Out-Null New-Item -ItemType Directory -Force -Path (Join-Path $packageRoot "app"), (Join-Path $packageRoot "scripts"), (Join-Path $packageRoot "config"), (Join-Path $packageRoot "samples") | Out-Null & dotnet restore $projectPath -r win-x64 if ($LASTEXITCODE -ne 0) { throw "dotnet restore failed" } & dotnet publish $projectPath ` -c $Configuration ` -r win-x64 ` --self-contained true ` -p:PublishSingleFile=true ` -p:IncludeNativeLibrariesForSelfExtract=true ` -o $publishRoot if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed" } Copy-Item -Path (Join-Path $publishRoot "OCSentinelCli.exe") -Destination (Join-Path $packageRoot "app\OCSentinelCli.exe") -Force if (Test-Path (Join-Path $publishRoot "OCSentinelCli.pdb")) { Copy-Item -Path (Join-Path $publishRoot "OCSentinelCli.pdb") -Destination (Join-Path $packageRoot "app\OCSentinelCli.pdb") -Force } Copy-Item -Path (Join-Path $installerRoot "install-ocsentinel.ps1") -Destination (Join-Path $packageRoot "scripts\install-ocsentinel.ps1") -Force Copy-Item -Path (Join-Path $installerRoot "uninstall-ocsentinel.ps1") -Destination (Join-Path $packageRoot "scripts\uninstall-ocsentinel.ps1") -Force Copy-Item -Path (Join-Path $installerRoot "update-ocsentinel.ps1") -Destination (Join-Path $packageRoot "scripts\update-ocsentinel.ps1") -Force Copy-Item -Path (Join-Path $installerRoot "runtime-run-ocsentinel.ps1") -Destination (Join-Path $packageRoot "scripts\run-ocsentinel.ps1") -Force Copy-Item -Path (Join-Path $installerRoot "runtime-run-ocsentinel-monitor.ps1") -Destination (Join-Path $packageRoot "scripts\run-ocsentinel-monitor.ps1") -Force Copy-Item -Path (Join-Path $repoRoot "scripts\protect-ocsentinel-secret.ps1") -Destination (Join-Path $packageRoot "scripts\protect-ocsentinel-secret.ps1") -Force Copy-Item -Path (Join-Path $repoRoot "config\ocsentinel-settings.example.json") -Destination (Join-Path $packageRoot "config\ocsentinel-settings.example.json") -Force Copy-Item -Path (Join-Path $repoRoot "config\ocsentinel-client.example.json") -Destination (Join-Path $packageRoot "config\ocsentinel-client.example.json") -Force Copy-Item -Path (Join-Path $repoRoot "config\update-channel.example.json") -Destination (Join-Path $packageRoot "config\update-channel.example.json") -Force Copy-Item -Path (Join-Path $repoRoot "samples\ninja-vulnerability-export.example.csv") -Destination (Join-Path $packageRoot "samples\ninja-vulnerability-export.example.csv") -Force Copy-Item -Path (Join-Path $repoRoot "samples\webhook-payload.example.json") -Destination (Join-Path $packageRoot "samples\webhook-payload.example.json") -Force Copy-Item -Path (Join-Path $installerRoot "README.txt") -Destination (Join-Path $packageRoot "README.txt") -Force Set-Content -Path (Join-Path $packageRoot "VERSION.txt") -Value $version -NoNewline Compress-Archive -Path (Join-Path $packageRoot "*") -DestinationPath $zipPath -CompressionLevel Optimal -Force $sha256 = (Get-FileHash -Path $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() Set-Content -Path ($zipPath + ".sha256") -Value "$sha256 $(Split-Path -Leaf $zipPath)" -NoNewline Write-Host "OfficeCom Sentinel client package created at $zipPath" Write-Host "SHA256: $sha256"