83 lines
3.4 KiB
PowerShell
83 lines
3.4 KiB
PowerShell
[CmdletBinding()]
|
|||
|
|
param(
|
||
|
|
[Parameter(Mandatory = $true)] [string] $OnnxPath,
|
||
|
|
[Parameter(Mandatory = $true)] [string] $OrtDllPath,
|
||
|
|
[Parameter(Mandatory = $true)] [string] $FfmpegPath,
|
||
|
|
[Parameter(Mandatory = $true)] [string] $FfprobePath,
|
||
|
|
[Parameter(Mandatory = $true)] [string] $OutputDirectory
|
||
|
|
)
|
||
|
|
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
|
||
|
|
function Resolve-RequiredFile([string] $Path, [string] $Name) {
|
||
|
|
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
|
||
|
|
throw "$Name does not exist or is not a file: $Path"
|
||
|
|
}
|
||
|
|
return (Resolve-Path -LiteralPath $Path).Path
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-ReleaseFileInfo([string] $Path, [string] $Name) {
|
||
|
|
$item = Get-Item -LiteralPath $Path
|
||
|
|
return [ordered]@{
|
||
|
|
name = $Name
|
||
|
|
sha256 = (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
|
||
|
|
bytes = $item.Length
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$onnx = Resolve-RequiredFile $OnnxPath 'ONNX model'
|
||
|
|
$ort = Resolve-RequiredFile $OrtDllPath 'ONNX Runtime DLL'
|
||
|
|
$ffmpeg = Resolve-RequiredFile $FfmpegPath 'FFmpeg executable'
|
||
|
|
$ffprobe = Resolve-RequiredFile $FfprobePath 'FFprobe executable'
|
||
|
|
$target = [System.IO.Path]::GetFullPath($OutputDirectory)
|
||
|
|
if (Test-Path -LiteralPath $target) {
|
||
|
|
$existing = Get-ChildItem -LiteralPath $target -Force
|
||
|
|
if ($existing.Count -gt 0) {
|
||
|
|
throw "OutputDirectory must be empty: $target"
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
New-Item -ItemType Directory -Path $target | Out-Null
|
||
|
|
}
|
||
|
|
|
||
|
|
$scriptRoot = Split-Path -Parent $PSCommandPath
|
||
|
|
$v2Root = Split-Path -Parent $scriptRoot
|
||
|
|
$runtime = Join-Path $target 'runtime'
|
||
|
|
New-Item -ItemType Directory -Path $runtime | Out-Null
|
||
|
|
|
||
|
|
$oldCgo = $env:CGO_ENABLED
|
||
|
|
$env:CGO_ENABLED = '1'
|
||
|
|
try {
|
||
|
|
Push-Location $v2Root
|
||
|
|
go build -trimpath -ldflags '-s -w' -o (Join-Path $target 'silver-pose.exe') ./cmd/silver-pose
|
||
|
|
} finally {
|
||
|
|
Pop-Location
|
||
|
|
$env:CGO_ENABLED = $oldCgo
|
||
|
|
}
|
||
|
|
|
||
|
|
Copy-Item -LiteralPath $onnx -Destination (Join-Path $runtime 'best.onnx')
|
||
|
|
Copy-Item -LiteralPath $ort -Destination (Join-Path $runtime 'onnxruntime.dll')
|
||
|
|
Copy-Item -LiteralPath $ffmpeg -Destination (Join-Path $runtime 'ffmpeg.exe')
|
||
|
|
Copy-Item -LiteralPath $ffprobe -Destination (Join-Path $runtime 'ffprobe.exe')
|
||
|
|
Copy-Item -LiteralPath (Join-Path $v2Root 'config.example.json') -Destination (Join-Path $target 'config.example.json')
|
||
|
|
Copy-Item -LiteralPath (Join-Path (Split-Path -Parent $v2Root) 'docs\v2-demo-runbook.md') -Destination (Join-Path $target 'v2-demo-runbook.md')
|
||
|
|
|
||
|
|
$ffmpegVersion = (& (Join-Path $runtime 'ffmpeg.exe') -version | Select-Object -First 1)
|
||
|
|
$ffprobeVersion = (& (Join-Path $runtime 'ffprobe.exe') -version | Select-Object -First 1)
|
||
|
|
$manifest = [ordered]@{
|
||
|
|
format = 'silver-pose-v2-runtime-1'
|
||
|
|
generated_at_utc = [DateTime]::UtcNow.ToString('o')
|
||
|
|
go_version = (& go version)
|
||
|
|
ffmpeg_version = $ffmpegVersion
|
||
|
|
ffprobe_version = $ffprobeVersion
|
||
|
|
files = @(
|
||
|
|
(Get-ReleaseFileInfo (Join-Path $target 'silver-pose.exe') 'silver-pose.exe'),
|
||
|
|
(Get-ReleaseFileInfo (Join-Path $runtime 'best.onnx') 'runtime/best.onnx'),
|
||
|
|
(Get-ReleaseFileInfo (Join-Path $runtime 'onnxruntime.dll') 'runtime/onnxruntime.dll'),
|
||
|
|
(Get-ReleaseFileInfo (Join-Path $runtime 'ffmpeg.exe') 'runtime/ffmpeg.exe'),
|
||
|
|
(Get-ReleaseFileInfo (Join-Path $runtime 'ffprobe.exe') 'runtime/ffprobe.exe')
|
||
|
|
)
|
||
|
|
}
|
||
|
|
$manifest | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $target 'runtime-manifest.json') -Encoding UTF8
|
||
|
|
|
||
|
|
Write-Output "V2 release created: $target"
|