WeeXnesSuite/.forgejo/workflows/dotnet.yaml
WeeXnes d698312381
Some checks failed
Dotnet Build / build (push) Failing after 1m16s
.forgejo/workflows/dotnet.yaml aktualisiert
2025-05-18 20:24:24 +00:00

136 lines
No EOL
4.8 KiB
YAML

name: Dotnet Build
on: [push]
jobs:
build:
runs-on: win11
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: MSBuild version
run: |
msbuild -version
- name: Extract project version
run: |
$version = Select-String -Path "WeeXnes/WeeXnes.csproj" -Pattern "<Version>(.+?)</Version>" | ForEach-Object {
($_ -match "<Version>(.+?)</Version>") | Out-Null
$matches[1]
}
Write-Output "Version extracted: $version"
"PROJECT_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding ASCII -Append
- name: Test exported version variable
run: |
Write-Output "The extracted project version is: $env:PROJECT_VERSION"
if (-not $env:PROJECT_VERSION) {
Write-Error "PROJECT_VERSION variable is not set!"
exit 1
}
- name: Restore Packages
run: nuget restore WeeXnes.sln
- name: Build Solution
run: |
msbuild WeeXnes.sln /p:DeleteExistingFiles=True /p:platform="Any CPU" /p:configuration="Release"
- name: Packing Zip
run: |
$zipName = "currentRelease_$env:PROJECT_VERSION.zip"
Compress-Archive -Path `
WeeXnes\bin\Release\WeeXnes.exe, `
WeeXnes\bin\Release\System.Drawing.Common.dll, `
WeeXnes\bin\Release\Wpf.Ui.dll, `
WeeXnes_UAC\bin\Release\WeeXnes_UAC.exe, `
WeeXnes\bin\Release\DiscordRPC.dll, `
WeeXnes\bin\Release\Newtonsoft.Json.dll, `
Autostart\bin\Release\Autostart.exe, `
WXPlugin\bin\Release\WXPlugin.dll, `
Update\bin\Release\Update.exe `
-CompressionLevel Optimal `
-DestinationPath $zipName
Write-Output "Created zip: $zipName"
- name: Prepare release directory
run: |
mkdir release
move currentRelease_$env:PROJECT_VERSION.zip release\
- name: Create Git tag
run: |
git config user.name "WeeXnes"
git config user.email "weexnes@weexnes.dev"
git tag $env:PROJECT_VERSION
git push origin $env:PROJECT_VERSION
- name: Upload Release Asset to Forgejo
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
PROJECT_VERSION: ${{ env.PROJECT_VERSION }}
run: |
$owner = "WeeXnes"
$repo = "WeeXnesSuite"
$tag = "$env:PROJECT_VERSION"
$token = $env:RELEASE_TOKEN
$fileName = "currentRelease_$tag.zip"
$filePath = "release/$fileName"
# Check if release exists
$releaseUrl = "https://git.weexnes.dev/api/v1/repos/$owner/$repo/releases/tags/$tag"
try {
$release = Invoke-RestMethod -Uri $releaseUrl -Headers @{ Authorization = "token $token" }
} catch {
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
}