75 lines
4.6 KiB
PowerShell
75 lines
4.6 KiB
PowerShell
param(
|
|
[string]$MavenCommand = 'mvn',
|
|
[string]$JavaHome = $env:JAVA_HOME
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$repo = Split-Path $PSScriptRoot -Parent
|
|
Set-Location $repo
|
|
if ((git status --porcelain)) { throw 'Commit the source changes before packaging. The release must identify a clean commit.' }
|
|
$commit = (git rev-parse HEAD).Trim()
|
|
$releaseId = (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + $commit.Substring(0, 8)
|
|
if ($JavaHome) { $env:JAVA_HOME = $JavaHome }
|
|
& $MavenCommand -B -ntp '-Dmaven.repo.local=.tools/m2' -f control-plane-java/pom.xml clean verify
|
|
if ($LASTEXITCODE -ne 0) { throw 'Java verification failed; no release created.' }
|
|
|
|
# Never load developer .env files while building distributable browser assets.
|
|
Push-Location prototype
|
|
try {
|
|
$env:VITE_CONTROL_PLANE_URL = '/'
|
|
$env:VITE_AUTH_MODE = 'remote'
|
|
& node node_modules/vue-tsc/bin/vue-tsc.js --noEmit
|
|
if ($LASTEXITCODE -ne 0) { throw 'Vue type check failed.' }
|
|
& node --experimental-strip-types --test tests/chat-stream.test.mjs tests/model-catalog.test.mjs tests/pricing.test.mjs
|
|
if ($LASTEXITCODE -ne 0) { throw 'Frontend verification failed.' }
|
|
& node build-release.mjs
|
|
if ($LASTEXITCODE -ne 0) { throw 'Vue build failed.' }
|
|
} finally { Pop-Location }
|
|
|
|
$artifactRoot = Join-Path $repo 'artifacts'
|
|
New-Item -ItemType Directory -Force -Path $artifactRoot | Out-Null
|
|
$staging = Join-Path $artifactRoot ('moyi-test-' + $releaseId)
|
|
New-Item -ItemType Directory -Path $staging | Out-Null
|
|
# Copy tracked deployment files only, never .env, certificates or .git.
|
|
$tracked = @(git ls-files infra/moyi scripts/live-gateway-smoke.py docs/11-server-test-deployment.md docs/13-model-groups-registration-credit.md docs/14-lifecycle-usage-credit-adjustments.md docs/15-relay-onboarding.md docs/16-streaming-chat-billing.md docs/17-catalog-and-key-selection.md)
|
|
foreach ($relative in $tracked) {
|
|
if ($relative -match '(^|/)(\.env\.cloud|\.deploy-mode|certs)(/|$)') { throw 'Sensitive path in release allowlist.' }
|
|
$destination = Join-Path $staging $relative
|
|
New-Item -ItemType Directory -Force -Path (Split-Path $destination -Parent) | Out-Null
|
|
$text = [IO.File]::ReadAllText((Join-Path $repo $relative)).Replace("`r`n", "`n")
|
|
[IO.File]::WriteAllText($destination, $text, [Text.UTF8Encoding]::new($false))
|
|
}
|
|
foreach ($relative in @('control-plane-java/Dockerfile.runtime', 'control-plane-java/Dockerfile.runtime.dockerignore', 'prototype/Dockerfile.runtime', 'prototype/Dockerfile.runtime.dockerignore', 'prototype/nginx.conf')) {
|
|
$destination = Join-Path $staging $relative
|
|
New-Item -ItemType Directory -Force -Path (Split-Path $destination -Parent) | Out-Null
|
|
[IO.File]::WriteAllText($destination, [IO.File]::ReadAllText((Join-Path $repo $relative)).Replace("`r`n", "`n"), [Text.UTF8Encoding]::new($false))
|
|
}
|
|
New-Item -ItemType Directory -Path (Join-Path $staging 'control-plane-java/target') | Out-Null
|
|
Copy-Item -LiteralPath 'control-plane-java/target/moyi-control-plane.jar' -Destination (Join-Path $staging 'control-plane-java/target/moyi-control-plane.jar')
|
|
Copy-Item -LiteralPath 'prototype/dist' -Destination (Join-Path $staging 'prototype/dist') -Recurse
|
|
Copy-Item -LiteralPath 'docs/11-server-test-deployment.md' -Destination (Join-Path $staging 'DEPLOYMENT.md')
|
|
$hashes = [ordered]@{}
|
|
foreach ($file in Get-ChildItem -LiteralPath $staging -File -Recurse | Sort-Object FullName) {
|
|
$relative = $file.FullName.Substring($staging.Length + 1).Replace('\', '/')
|
|
$hashes[$relative] = (Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
}
|
|
$manifest = [ordered]@{
|
|
release = $releaseId
|
|
commit = $commit
|
|
builtAt = (Get-Date).ToUniversalTime().ToString('o')
|
|
kind = 'precompiled-jar-and-static-assets-not-offline-docker-images'
|
|
javaRelease = 21
|
|
database = 'PostgreSQL 15'
|
|
redis = 'Tair standard'
|
|
checks = @('maven-clean-verify', 'vue-tsc', 'frontend-stream-tests', 'frontend-catalog-tests', 'frontend-pricing-tests', 'vite-build')
|
|
sha256 = $hashes
|
|
}
|
|
[IO.File]::WriteAllText((Join-Path $staging 'release-manifest.json'), ($manifest | ConvertTo-Json -Depth 5), [Text.UTF8Encoding]::new($false))
|
|
$archive = $staging + '.tar.gz'
|
|
& tar -czf $archive -C $staging .
|
|
if ($LASTEXITCODE -ne 0) { throw 'Archive creation failed.' }
|
|
$checksum = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
[IO.File]::WriteAllText(($archive + '.sha256'), "$checksum $([IO.Path]::GetFileName($archive))`n", [Text.UTF8Encoding]::new($false))
|
|
Write-Output "Release: $archive"
|
|
Write-Output "SHA256: $checksum"
|
|
Write-Output 'Contains compiled artifacts, not Docker images. First deployment needs registry connectivity.'
|