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