#!/bin/bash
# Update the Sparkle appcast.xml with a new release
# Usage: ./update-appcast.sh VERSION TAG DMG_SIZE SPARKLE_SIGNATURE RELEASE_NOTES REPO
set -e
VERSION="$1"
TAG="$2"
DMG_SIZE="$3"
SPARKLE_SIGNATURE="$4"
RELEASE_NOTES="$5"
REPO="$6"
PUBDATE=$(date -R)
DMG_URL="https://github.com/${REPO}/releases/download/${TAG}/Cull-${VERSION}-macOS.dmg"
# Convert markdown release notes to HTML
RELEASE_NOTES_HTML=$(echo "$RELEASE_NOTES" | python3 -c "
import sys, re, html
md = sys.stdin.read().strip()
lines = []
in_list = False
for line in md.split('\n'):
stripped = line.strip()
if stripped.startswith('### '):
if in_list: lines.append(''); in_list = False
lines.append(f'
')
if in_list: lines.append('')
print('\n'.join(lines))
")
NEW_ITEM=" Version ${VERSION}${PUBDATE}${VERSION}${VERSION}14.0"
APPCAST_FILE="docs/appcast.xml"
if [ -f "$APPCAST_FILE" ]; then
# Insert the new item after en, before existing items
python3 << PYEOF
appcast = open("$APPCAST_FILE").read()
marker = "en"
idx = appcast.find(marker)
if idx == -1:
raise SystemExit("Error: could not find tag in appcast.xml")
end = idx + len(marker)
new_item = """
$NEW_ITEM"""
result = appcast[:end] + new_item + appcast[end:]
open("$APPCAST_FILE", "w").write(result)
PYEOF
else
cat > "$APPCAST_FILE" << APPCAST_EOF
Cull Updates
https://taciturnaxolotl.github.io/cull/appcast.xml
Most recent updates to Cullen
${NEW_ITEM}
APPCAST_EOF
fi
echo "Appcast updated for version ${VERSION}"