.forgejo/workflows/dotnet.yaml aktualisiert
Some checks failed
Dotnet Build / build (push) Failing after 1m16s

This commit is contained in:
WeeXnes 2025-05-18 20:24:24 +00:00
parent d9981c025d
commit d698312381

View file

@ -83,28 +83,54 @@ jobs:
$owner = "WeeXnes"
$repo = "WeeXnesSuite"
$tag = "$env:PROJECT_VERSION"
$token = $env:RELEASE_TOKEN
$fileName = "currentRelease_$tag.zip"
$filePath = "release/$fileName"
# Get release info by tag to get release ID
$releaseInfoUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases/tags/$tag"
# Check if release exists
$releaseUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases/tags/$tag"
try {
$release = Invoke-RestMethod -Uri $releaseInfoUrl -Headers @{ Authorization = "token $env:RELEASE_TOKEN" }
$releaseId = $release.id
Write-Host "Found release ID: $releaseId"
$release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ Authorization = "token $token" }
} catch {
Write-Error "Failed to find release with tag '$tag'. Make sure the release exists."
Write-Host "Release for tag $tag not found, creating..."
$createReleaseUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases"
$body = @{
tag_name = $tag
name = $tag
draft = $false
prerelease = $false
} | ConvertTo-Json
$release = Invoke-RestMethod -Uri $createReleaseUrl -Headers @{ Authorization = "token $token"; "Content-Type" = "application/json" } -Method Post -Body $body
}
$releaseId = $release.id
Write-Host "Release ID: $releaseId"
# Upload the asset (form-data)
$uploadUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases/$releaseId/assets?name=$fileName"
Write-Host "Uploading asset to $uploadUrl"
$form = [System.Collections.Generic.Dictionary[string,object]]::new()
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
$bytesContent = [System.Net.Http.ByteArrayContent]::new($fileContent)
$bytesContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::new("application/zip")
$form.Add("attachment", $bytesContent)
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.DefaultRequestHeaders.Authorization = [System.Net.Http.Headers.AuthenticationHeaderValue]::new("token", $token)
$content = New-Object System.Net.Http.MultipartFormDataContent
$content.Add($bytesContent, "attachment", $fileName)
$response = $client.PostAsync($uploadUrl, $content).Result
$responseContent = $response.Content.ReadAsStringAsync().Result
if ($response.IsSuccessStatusCode) {
Write-Host "Upload succeeded!"
} else {
Write-Error "Upload failed! Status: $($response.StatusCode) Content: $responseContent"
exit 1
}
# Upload the asset to the release by ID
$uploadUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases/$releaseId/assets?name=$fileName"
Write-Host "Uploading asset to: $uploadUrl"
Invoke-RestMethod -Uri $uploadUrl `
-Headers @{ Authorization = "token $env:RELEASE_TOKEN" } `
-Method Post `
-ContentType "application/zip" `
-InFile $filePath
Write-Host "Upload complete."