[CmdletBinding()] param( [string]$BackendSource = "D:\Work\Inogen_new\backend", [string]$OutputRoot = (Join-Path $PSScriptRoot "..\artifacts"), [string]$SigningPrivateKey = $env:INOGEN_RELEASE_SIGNING_KEY, [switch]$SkipNpmInstall ) $ErrorActionPreference = "Stop" $frontendSource = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path $backendSourcePath = (Resolve-Path -LiteralPath $BackendSource).Path $outputRootPath = [IO.Path]::GetFullPath($OutputRoot) $releaseName = "Inogen-{0}" -f (Get-Date -Format "yyyyMMdd-HHmmss") $releasePath = Join-Path $outputRootPath $releaseName $backendOutput = Join-Path $releasePath "backend" $frontendOutput = Join-Path $releasePath "frontend" $toolOutput = Join-Path $releasePath "tools\Inogen.DataTransfer" if ([string]::IsNullOrWhiteSpace($SigningPrivateKey)) { throw "Set INOGEN_RELEASE_SIGNING_KEY to the absolute path of the RSA private PEM used for release signing." } $signingKeyPath = (Resolve-Path -LiteralPath $SigningPrivateKey).Path New-Item -ItemType Directory -Force -Path $backendOutput, $frontendOutput, $toolOutput | Out-Null function Assert-NativeCommandSucceeded([string]$operation) { if ($LASTEXITCODE -ne 0) { throw "$operation failed with exit code $LASTEXITCODE." } } function Protect-Assemblies([string]$targetPath, [string[]]$moduleNames) { $obfuscatedPath = Join-Path $targetPath "obfuscated" New-Item -ItemType Directory -Force -Path $obfuscatedPath | Out-Null $moduleElements = $moduleNames | ForEach-Object { $modulePath = [System.Security.SecurityElement]::Escape((Join-Path $targetPath $_)) $rules = @(" ") if ($_ -eq "Inogen.Infrastructure.dll") { $rules += " " $rules += " " $rules += " " } " $([Environment]::NewLine)$($rules -join [Environment]::NewLine)$([Environment]::NewLine) " } $configPath = Join-Path $targetPath "obfuscar.xml" $config = @( "", "", " ", " ", " ", " ", " ", " ", " ", " ", ($moduleElements -join [Environment]::NewLine), "" ) -join [Environment]::NewLine [IO.File]::WriteAllText($configPath, $config, [Text.UTF8Encoding]::new($false)) Push-Location $backendSourcePath try { dotnet tool run obfuscar.console -- $configPath Assert-NativeCommandSucceeded "Assembly obfuscation" } finally { Pop-Location } foreach ($module in $moduleNames) { Copy-Item -LiteralPath (Join-Path $obfuscatedPath $module) -Destination (Join-Path $targetPath $module) -Force } Remove-Item -LiteralPath $obfuscatedPath -Recurse -Force Remove-Item -LiteralPath $configPath -Force } function Write-SignedIntegrityManifest([string]$targetPath, [string[]]$fileNames) { $protectorProject = Join-Path $backendSourcePath "tools\Inogen.ReleaseProtector\Inogen.ReleaseProtector.csproj" dotnet run --project $protectorProject --configuration Release -- sign $signingKeyPath $targetPath @fileNames Assert-NativeCommandSucceeded "Release integrity signing" } Push-Location $frontendSource try { if (-not $SkipNpmInstall) { npm ci Assert-NativeCommandSucceeded "npm ci" } npm run typecheck Assert-NativeCommandSucceeded "Frontend typecheck" npm run build Assert-NativeCommandSucceeded "Frontend build" Copy-Item -Path (Join-Path $frontendSource "build\client\*") -Destination $frontendOutput -Recurse -Force } finally { Pop-Location } dotnet publish (Join-Path $backendSourcePath "src\Inogen.Api\Inogen.Api.csproj") ` --configuration Release --output $backendOutput --no-self-contained Assert-NativeCommandSucceeded "Backend publish" $developmentSettings = Join-Path $backendOutput "appsettings.Development.json" if (Test-Path -LiteralPath $developmentSettings) { Remove-Item -LiteralPath $developmentSettings -Force } dotnet publish (Join-Path $backendSourcePath "tools\Inogen.DataTransfer\Inogen.DataTransfer.csproj") ` --configuration Release --output $toolOutput --no-self-contained Assert-NativeCommandSucceeded "Administration tool publish" Push-Location $backendSourcePath try { dotnet tool restore Assert-NativeCommandSucceeded "Obfuscator restore" } finally { Pop-Location } $backendModules = @("Inogen.Api.dll", "Inogen.Application.dll") $toolModules = @("Inogen.DataTransfer.dll", "Inogen.Application.dll") $integrityModules = @("Inogen.Api.dll", "Inogen.Application.dll", "Inogen.Domain.dll", "Inogen.Infrastructure.dll") Protect-Assemblies $backendOutput $backendModules Protect-Assemblies $toolOutput $toolModules Get-ChildItem -LiteralPath $backendOutput, $toolOutput -Filter "*.pdb" -File | Remove-Item -Force Get-ChildItem -LiteralPath $backendOutput, $toolOutput -Filter "Mapping.txt" -File | Remove-Item -Force Write-SignedIntegrityManifest $backendOutput $integrityModules Copy-Item -LiteralPath (Join-Path $PSScriptRoot "appsettings.Production.template.json") ` -Destination (Join-Path $backendOutput "appsettings.Production.json") -Force Copy-Item -LiteralPath (Join-Path $PSScriptRoot "INSTALL.md") -Destination $releasePath -Force $assetPath = Join-Path $backendOutput "data\deployment\assets" New-Item -ItemType Directory -Force -Path $assetPath, (Join-Path $backendOutput "data\files"), ` (Join-Path $backendOutput "data\activation") | Out-Null foreach ($asset in @("product-logo.svg", "abniro.png", "besparan.png", "khwarazmi.png", "faravash1.png", "faravash2.png", "kimia.png")) { Copy-Item -LiteralPath (Join-Path $frontendSource "public\$asset") -Destination $assetPath -Force } $zipPath = "$releasePath.zip" Compress-Archive -LiteralPath $releasePath -DestinationPath $zipPath -CompressionLevel Optimal Write-Host "Release folder: $releasePath" Write-Host "Release archive: $zipPath"