Forge
powershellad090a99
1# Publish win-x64 build to GitLab: Generic Package + release asset link.
2# Run from repo root on Windows (no Runner). Webcam uses OpenCvSharp4.runtime.win — default only win-x64.
3# Required: GITLAB_URL, GITLAB_TOKEN. Usage: .\scripts\publish-release-win.ps1 -Version 2026.03.08 -CreateRelease
4
5param(
6 [Parameter(Mandatory = $true)]
7 [string] $Version,
8 [string] $Tag = "v$Version",
9 [string] $GitLabUrl,
10 [string] $Token,
11 [string] $ProjectPath = "Krawler/webcam-mcp",
12 [string[]] $Rids = @("win-x64"),
13 [switch] $CreateRelease
14)
15
16$ErrorActionPreference = "Stop"
17$baseUrl = if ($GitLabUrl) { $GitLabUrl.TrimEnd('/') } else { $env:GITLAB_URL?.TrimEnd('/') }
18$token = if ($Token) { $Token } else { $env:GITLAB_TOKEN }
19if (-not $baseUrl -or -not $token) { Write-Error "Set GITLAB_URL and GITLAB_TOKEN (or pass -GitLabUrl and -Token)." }
20$projectId = $ProjectPath -replace '/', '%2F'
21$api = "$baseUrl/api/v4"
22$pkgName = "webcam-mcp"
23$zipPaths = @()
24
25foreach ($rid in $Rids) {
26 $zipName = "webcam-mcp-$rid.zip"
27 $outDir = "publish-release-temp-$rid"
28 if (Test-Path $outDir) { Remove-Item -Recurse -Force $outDir }
29 Write-Host "Building $rid ..."
30 dotnet publish -c Release -r $rid -o $outDir
31 if ($LASTEXITCODE -ne 0) { Write-Warning "dotnet publish -r $rid failed; skipping."; continue }
32 $zipPath = Join-Path $PWD $zipName
33 if (Test-Path $zipPath) { Remove-Item -Force $zipPath }
34 Compress-Archive -Path "$outDir\*" -DestinationPath $zipPath
35 Remove-Item -Recurse -Force $outDir
36 $zipPaths += @{ Name = $zipName; Path = $zipPath }; Write-Host " -> $zipName"
37}
38if ($zipPaths.Count -eq 0) { Write-Error "No builds succeeded." }
39
40foreach ($z in $zipPaths) {
41 $uploadUrl = "$api/projects/$projectId/packages/generic/$pkgName/$Version/$($z.Name)"
42 Write-Host "Uploading $($z.Name) ..."
43 Invoke-RestMethod -Uri $uploadUrl -Method Put -InFile $z.Path -Headers @{ "PRIVATE-TOKEN" = $token } -ContentType "application/octet-stream"
44}
45if ($CreateRelease) {
46 $commitSha = (git rev-parse HEAD).Trim()
47 $body = @{ tag_name = $Tag; ref = $commitSha; name = "Release $Tag"; description = "Pre-built: $($Rids -join ', ') (no Runner)." } | ConvertTo-Json
48 Invoke-RestMethod -Uri "$api/projects/$projectId/releases" -Method Post -Headers @{ "PRIVATE-TOKEN" = $token } -Body $body -ContentType "application/json"
49 Write-Host "Release $Tag created."
50}
51foreach ($z in $zipPaths) {
52 $assetUrl = "$api/projects/$projectId/packages/generic/$pkgName/$Version/$($z.Name)"
53 $linkBody = @{ name = $z.Name; url = $assetUrl; link_type = "package" } | ConvertTo-Json
54 try { Invoke-RestMethod -Uri "$api/projects/$projectId/releases/$Tag/assets/links" -Method Post -Headers @{ "PRIVATE-TOKEN" = $token } -Body $linkBody -ContentType "application/json; charset=utf-8"; Write-Host "Asset link added: $($z.Name)" }
55 catch { Write-Warning "Could not add asset link for $($z.Name): $_" }
56}
57foreach ($z in $zipPaths) { Remove-Item -Force $z.Path -ErrorAction SilentlyContinue }
58Write-Host "Done."
59
View only · write via MCP/CIDE