diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eca979c..6d59f24 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,3 +107,50 @@ jobs: - `Microsoft.Graph.Authentication` Modul (wird beim ersten Start automatisch angeboten) files: "IntuneManager-${{ steps.ver.outputs.TAG }}.msi" generate_release_notes: false + + - name: Mirror MSI to Gitea release + shell: pwsh + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_BASE: https://git.wende.it/api/v1 + GITEA_OWNER: marco + GITEA_REPO: Intune-Manager + TAG: ${{ steps.ver.outputs.TAG }} + MSI_NAME: ${{ steps.build.outputs.MSI_NAME }} + COMMIT_SHA: ${{ github.sha }} + run: | + if ([string]::IsNullOrWhiteSpace($env:GITEA_TOKEN)) { + Write-Host "::notice::GITEA_TOKEN nicht gesetzt — Gitea-Upload uebersprungen." + exit 0 + } + $headers = @{ Authorization = "token $env:GITEA_TOKEN" } + $repoUrl = "$($env:GITEA_BASE)/repos/$($env:GITEA_OWNER)/$($env:GITEA_REPO)" + + # Release per Tag suchen; sonst anlegen (Tag wird bei Bedarf am Commit erzeugt). + $rel = $null + try { $rel = Invoke-RestMethod -Headers $headers -Uri "$repoUrl/releases/tags/$($env:TAG)" -Method GET } catch { $rel = $null } + if (-not $rel) { + $body = @{ + tag_name = $env:TAG + target_commitish = $env:COMMIT_SHA + name = "Intune Manager $($env:TAG)" + body = "Automatisch aus der GitHub-CI gespiegelt." + } | ConvertTo-Json + $rel = Invoke-RestMethod -Headers $headers -Uri "$repoUrl/releases" -Method POST -ContentType 'application/json' -Body $body + } + $relId = $rel.id + + # Vorhandenes Asset gleichen Namens entfernen (idempotent bei Re-Runs). + try { + $assets = Invoke-RestMethod -Headers $headers -Uri "$repoUrl/releases/$relId/assets" -Method GET + foreach ($a in @($assets)) { + if ($a.name -eq $env:MSI_NAME) { + Invoke-RestMethod -Headers $headers -Uri "$repoUrl/releases/$relId/assets/$($a.id)" -Method DELETE | Out-Null + } + } + } catch {} + + # MSI als Attachment hochladen (multipart, Feldname 'attachment'). + $assetUri = "$repoUrl/releases/$relId/assets?name=$([uri]::EscapeDataString($env:MSI_NAME))" + Invoke-RestMethod -Headers $headers -Uri $assetUri -Method POST -Form @{ attachment = Get-Item -LiteralPath $env:MSI_NAME } | Out-Null + Write-Host "MSI '$($env:MSI_NAME)' -> Gitea-Release '$($env:TAG)' hochgeladen."