From 4573a7df99464f279600363f7017d2b4bd459c43 Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Mon, 16 Nov 2026 11:25:12 +0000 Subject: [PATCH] fix(release): attach release assets while the release is still a draft GitHub accepts release assets only on a release that has not been published yet. In a repository with release immutability enabled the asset endpoint rejects the upload outright: Octokit.ApiValidationException: Cannot upload assets to an immutable release. at Purview.Build.Modules.UploadArtifactsAsync The release was created published and the artifacts were uploaded afterwards, so a repository with immutable releases could not publish an artifact-bearing release: the tag and release appeared, the asset upload failed, and the run failed in CreateGitHubReleaseModule. A release that carries artifacts is now created as a draft, the artifacts are attached, and the release is published once they are there. A release with nothing to attach is still created and published in a single call, as before. Publishing is what creates the tag, so nothing observable appears before the artifacts exist. Version 0.9.2. --- package.json | 2 +- .../Modules/CreateGitHubReleaseModule.cs | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index dda529b..553ffe3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "build", - "version": "0.9.1", + "version": "0.9.2", "description": "Shared build/test/release pipeline for the purview-dev organisation, packaged as a pinned .NET tool with a GitHub composite action and reusable workflows.", "license": "MIT", "author": { diff --git a/src/src/Build/Modules/CreateGitHubReleaseModule.cs b/src/src/Build/Modules/CreateGitHubReleaseModule.cs index 72c8f16..0ef34d7 100644 --- a/src/src/Build/Modules/CreateGitHubReleaseModule.cs +++ b/src/src/Build/Modules/CreateGitHubReleaseModule.cs @@ -89,6 +89,15 @@ CancellationToken cancellationToken // latest stable release. var isPrerelease = releaseSettings.Value.ShouldMarkPrerelease(unit.Version); + // GitHub accepts release assets only while the release is still a draft. A + // published release is immutable in a repository that enables release + // immutability, and the asset endpoint then rejects the upload outright + // ("Cannot upload assets to an immutable release"). A release that carries + // artifacts is therefore created as a draft, filled, and published once the + // artifacts are attached; a release with nothing to attach is published in + // one call, exactly as before. + var uploadArtifacts = releaseSettings.Value.UploadArtifacts; + var release = await context .GitHub() .Client.Repository.Release.Create( @@ -98,18 +107,34 @@ CancellationToken cancellationToken Name = unit.Tag, GenerateReleaseNotes = true, Prerelease = isPrerelease, + Draft = uploadArtifacts, } ); context.Logger.LogInformation( - "Created GitHub release {Tag}{Prerelease}.", + "Created GitHub release {Tag}{Prerelease}{Draft}.", unit.Tag, - isPrerelease ? " as a prerelease" : string.Empty + isPrerelease ? " as a prerelease" : string.Empty, + uploadArtifacts ? " as a draft" : string.Empty ); - if (releaseSettings.Value.UploadArtifacts) + if (uploadArtifacts) + { await UploadArtifactsAsync(context, release, cancellationToken); + // Publishing is the last step, so a release is never observable without + // its artifacts. + release = await context + .GitHub() + .Client.Repository.Release.Edit( + repositoryId, + release.Id, + new ReleaseUpdate { Draft = false } + ); + + context.Logger.LogInformation("Published GitHub release {Tag}.", unit.Tag); + } + return release; }