Skip to content

Commit edb65e2

Browse files
authored
Merge pull request #17 from nutthead/fix/immutable-release-prevention
fix(ci): Prevent immutable release failures with defensive checks
2 parents 0c99fe8 + 798d08e commit edb65e2

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,78 @@ jobs:
537537
with:
538538
path: release-artifacts
539539

540+
- name: Verify downloaded artifacts
541+
run: |
542+
echo "=== Verifying release artifacts ==="
543+
544+
# Check if release-artifacts directory exists
545+
if [ ! -d "release-artifacts" ]; then
546+
echo "❌ ERROR: release-artifacts directory was not created"
547+
echo "Artifact download failed"
548+
exit 1
549+
fi
550+
echo "✅ release-artifacts directory exists"
551+
552+
# Check if directory contains files
553+
if [ -z "$(ls -A release-artifacts 2>/dev/null)" ]; then
554+
echo "❌ ERROR: release-artifacts directory is empty"
555+
echo "No artifacts were downloaded from previous jobs"
556+
exit 1
557+
fi
558+
echo "✅ release-artifacts directory contains files"
559+
560+
# List all downloaded artifacts for debugging
561+
echo ""
562+
echo "Downloaded artifacts:"
563+
find release-artifacts -type f | sort
564+
565+
# Count archives (tar.gz and zip)
566+
ARCHIVE_COUNT=$(find release-artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) | wc -l)
567+
echo ""
568+
echo "Archive count: ${ARCHIVE_COUNT}"
569+
570+
if [ "$ARCHIVE_COUNT" -eq 0 ]; then
571+
echo "❌ ERROR: No .tar.gz or .zip archives found"
572+
exit 1
573+
fi
574+
echo "✅ Found ${ARCHIVE_COUNT} release archives"
575+
576+
- name: Check for existing release
577+
id: check_release
578+
run: |
579+
VERSION="${{ needs.prepare-release.outputs.version }}"
580+
581+
# Check if release already exists
582+
if gh release view "v${VERSION}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
583+
echo "⚠️ Release v${VERSION} already exists"
584+
585+
# Get release info
586+
IS_DRAFT=$(gh release view "v${VERSION}" --repo "${{ github.repository }}" --json isDraft -q '.isDraft')
587+
ASSET_COUNT=$(gh release view "v${VERSION}" --repo "${{ github.repository }}" --json assets -q '.assets | length')
588+
589+
echo " Draft: ${IS_DRAFT}"
590+
echo " Assets: ${ASSET_COUNT}"
591+
592+
if [ "$IS_DRAFT" = "false" ] && [ "$ASSET_COUNT" -eq 0 ]; then
593+
echo "❌ ERROR: Published release exists with no assets (likely from previous failed run)"
594+
echo " Deleting broken release to allow recreation..."
595+
gh release delete "v${VERSION}" --repo "${{ github.repository }}" --yes
596+
echo "✅ Broken release deleted"
597+
elif [ "$IS_DRAFT" = "false" ]; then
598+
echo "❌ ERROR: Published release already exists with ${ASSET_COUNT} assets"
599+
echo " Cannot overwrite published releases. Please:"
600+
echo " 1. Delete the release manually: gh release delete v${VERSION}"
601+
echo " 2. Or create a new version"
602+
exit 1
603+
else
604+
echo "✅ Draft release exists - will be updated"
605+
fi
606+
else
607+
echo "✅ No existing release found - will create new one"
608+
fi
609+
env:
610+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
611+
540612
- name: Generate release notes
541613
run: |
542614
VERSION="${{ needs.prepare-release.outputs.version }}"

0 commit comments

Comments
 (0)