Skip to content

Commit 4d2391a

Browse files
authored
Handle immutable desktop releases (#41)
Fixes the desktop release asset upload path for repos with immutable releases enabled. What changed: - If no GitHub Release exists, keep creating the release with DMG assets in the initial create path. - If a draft release exists, upload the DMG assets and publish it. - If a published immutable release already exists, fail with a clear error instead of trying an impossible asset upload. This prevents the confusing HTTP 422 immutable release failure and supports a safe draft-release flow.
1 parent 25f623a commit 4d2391a

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/release-desktop.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,21 @@ jobs:
154154
run: |
155155
VERSION="${GITHUB_REF_NAME#v}"
156156
TITLE="v${VERSION}"
157-
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
158-
gh release upload "$GITHUB_REF_NAME" artifacts/Second-mac-arm64.dmg artifacts/Second-mac-arm64.dmg.sha256 --repo "$GITHUB_REPOSITORY" --clobber
159-
else
160-
gh release create "$GITHUB_REF_NAME" artifacts/Second-mac-arm64.dmg artifacts/Second-mac-arm64.dmg.sha256 --repo "$GITHUB_REPOSITORY" --title "$TITLE" --notes "Second ${VERSION}"
157+
158+
if RELEASE_JSON="$(gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --json isDraft,isImmutable 2>/dev/null)"; then
159+
IS_DRAFT="$(jq -r '.isDraft' <<< "$RELEASE_JSON")"
160+
IS_IMMUTABLE="$(jq -r '.isImmutable' <<< "$RELEASE_JSON")"
161+
162+
if [[ "$IS_DRAFT" == "true" ]]; then
163+
gh release upload "$GITHUB_REF_NAME" artifacts/Second-mac-arm64.dmg artifacts/Second-mac-arm64.dmg.sha256 --repo "$GITHUB_REPOSITORY" --clobber
164+
gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --draft=false --latest --title "$TITLE" --notes "Second ${VERSION}"
165+
elif [[ "$IS_IMMUTABLE" == "true" ]]; then
166+
echo "::error::Release $GITHUB_REF_NAME is already published and immutable, so assets cannot be attached. Delete the GitHub Release and rerun this job, or create releases as drafts before this workflow runs."
167+
exit 1
168+
else
169+
gh release upload "$GITHUB_REF_NAME" artifacts/Second-mac-arm64.dmg artifacts/Second-mac-arm64.dmg.sha256 --repo "$GITHUB_REPOSITORY" --clobber
170+
fi
171+
exit 0
161172
fi
173+
174+
gh release create "$GITHUB_REF_NAME" artifacts/Second-mac-arm64.dmg artifacts/Second-mac-arm64.dmg.sha256 --repo "$GITHUB_REPOSITORY" --title "$TITLE" --notes "Second ${VERSION}"

0 commit comments

Comments
 (0)