ci: simplify latest.json generation with pure Python
This commit is contained in:
@@ -91,124 +91,79 @@ jobs:
|
|||||||
- name: Generate and upload latest.json
|
- name: Generate and upload latest.json
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
|
|
||||||
run: |
|
run: |
|
||||||
RELEASE_TAG="${{ github.ref_name }}"
|
|
||||||
VERSION=$(echo "$RELEASE_TAG" | sed 's/^v//')
|
|
||||||
REPO="${{ github.repository }}"
|
|
||||||
BASE_URL="https://github.com/${REPO}/releases/download/${RELEASE_TAG}"
|
|
||||||
|
|
||||||
# Fetch all release assets
|
|
||||||
ASSETS_JSON=$(gh release view "$RELEASE_TAG" --repo "$REPO" --json assets)
|
|
||||||
|
|
||||||
# Helper: find asset name matching pattern
|
|
||||||
find_asset() {
|
|
||||||
echo "$ASSETS_JSON" | python3 -c "
|
|
||||||
import sys, json
|
|
||||||
data = json.load(sys.stdin)
|
|
||||||
for asset in data['assets']:
|
|
||||||
if '$1' in asset['name']:
|
|
||||||
print(asset['name'])
|
|
||||||
break
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Helper: read sig file content from release assets
|
|
||||||
get_sig_content() {
|
|
||||||
local sig_name="$1"
|
|
||||||
local tmp_dir=$(mktemp -d)
|
|
||||||
gh release download "$RELEASE_TAG" --repo "$REPO" -p "$sig_name" -D "$tmp_dir" 2>/dev/null
|
|
||||||
if [ -f "$tmp_dir/$sig_name" ]; then
|
|
||||||
cat "$tmp_dir/$sig_name"
|
|
||||||
fi
|
|
||||||
rm -rf "$tmp_dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find key assets
|
|
||||||
APPIMAGE=$(find_asset "AppImage$")
|
|
||||||
NSIS_SETUP=$(find_asset "nsis-setup.exe")
|
|
||||||
MACOS_APP_TAR=$(find_asset "universal.app.tar.gz")
|
|
||||||
|
|
||||||
# Read signatures
|
|
||||||
APPIMAGE_SIG_NAME=$(find_asset "AppImage.sig$")
|
|
||||||
NSIS_SIG_NAME=$(find_asset "nsis.zip.sig$")
|
|
||||||
MACOS_SIG_NAME=$(find_asset "app.tar.gz.sig$")
|
|
||||||
|
|
||||||
echo "Found assets:"
|
|
||||||
echo " AppImage: $APPIMAGE"
|
|
||||||
echo " NSIS: $NSIS_SETUP"
|
|
||||||
echo " macOS: $MACOS_APP_TAR"
|
|
||||||
echo " AppImage sig: $APPIMAGE_SIG_NAME"
|
|
||||||
echo " NSIS sig: $NSIS_SIG_NAME"
|
|
||||||
echo " macOS sig: $MACOS_SIG_NAME"
|
|
||||||
|
|
||||||
# Build latest.json
|
|
||||||
python3 << 'PYEOF'
|
python3 << 'PYEOF'
|
||||||
import json, subprocess, os, sys
|
import json, subprocess, os, sys, tempfile
|
||||||
|
|
||||||
version = os.environ['VERSION']
|
TAG = os.environ.get("GITHUB_REF_NAME", "")
|
||||||
base_url = os.environ['BASE_URL']
|
REPO = os.environ.get("GITHUB_REPOSITORY", "")
|
||||||
|
VERSION = TAG.lstrip("v")
|
||||||
|
BASE_URL = f"https://github.com/{REPO}/releases/download/{TAG}"
|
||||||
|
|
||||||
def get_sig(name):
|
def run(cmd):
|
||||||
if not name:
|
return subprocess.check_output(cmd, shell=True, text=True).strip()
|
||||||
return ""
|
|
||||||
tmp_dir = subprocess.check_output(['mktemp', '-d']).decode().strip()
|
def find_asset(pattern):
|
||||||
try:
|
data = json.loads(run(f'gh release view "{TAG}" --repo "{REPO}" --json assets'))
|
||||||
subprocess.run([
|
for a in data["assets"]:
|
||||||
'gh', 'release', 'download', os.environ['RELEASE_TAG'],
|
if pattern in a["name"]:
|
||||||
'--repo', os.environ['REPO'],
|
return a["name"]
|
||||||
'-p', name, '-D', tmp_dir
|
return None
|
||||||
], capture_output=True, check=False)
|
|
||||||
sig_path = os.path.join(tmp_dir, name)
|
def download_asset(name):
|
||||||
if os.path.exists(sig_path):
|
with tempfile.TemporaryDirectory() as d:
|
||||||
with open(sig_path) as f:
|
subprocess.run(
|
||||||
|
f'gh release download "{TAG}" --repo "{REPO}" -p "{name}" -D "{d}"',
|
||||||
|
shell=True, capture_output=True
|
||||||
|
)
|
||||||
|
path = os.path.join(d, name)
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path) as f:
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
finally:
|
|
||||||
subprocess.run(['rm', '-rf', tmp_dir])
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
platforms = {}
|
platforms = {}
|
||||||
|
|
||||||
appimage = os.environ.get('APPIMAGE', '')
|
# Linux AppImage
|
||||||
appimage_sig = get_sig(os.environ.get('APPIMAGE_SIG_NAME', ''))
|
appimage = find_asset(".AppImage")
|
||||||
|
appimage_sig = find_asset(".AppImage.sig")
|
||||||
if appimage and appimage_sig:
|
if appimage and appimage_sig:
|
||||||
platforms['linux-x86_64'] = {
|
sig = download_asset(appimage_sig)
|
||||||
'signature': appimage_sig,
|
if sig:
|
||||||
'url': f'{base_url}/{appimage}'
|
platforms["linux-x86_64"] = {"signature": sig, "url": f"{BASE_URL}/{appimage}"}
|
||||||
}
|
|
||||||
|
|
||||||
nsis = os.environ.get('NSIS_SETUP', '')
|
# Windows NSIS
|
||||||
nsis_sig = get_sig(os.environ.get('NSIS_SIG_NAME', ''))
|
nsis = find_asset("-setup.exe")
|
||||||
|
nsis_sig = find_asset("nsis.zip.sig")
|
||||||
if nsis and nsis_sig:
|
if nsis and nsis_sig:
|
||||||
platforms['windows-x86_64'] = {
|
sig = download_asset(nsis_sig)
|
||||||
'signature': nsis_sig,
|
if sig:
|
||||||
'url': f'{base_url}/{nsis}'
|
platforms["windows-x86_64"] = {"signature": sig, "url": f"{BASE_URL}/{nsis}"}
|
||||||
}
|
|
||||||
|
|
||||||
macos = os.environ.get('MACOS_APP_TAR', '')
|
# macOS universal
|
||||||
macos_sig = get_sig(os.environ.get('MACOS_SIG_NAME', ''))
|
macos = find_asset("app.tar.gz")
|
||||||
|
macos_sig = find_asset("app.tar.gz.sig")
|
||||||
if macos and macos_sig:
|
if macos and macos_sig:
|
||||||
platforms['darwin-x86_64'] = {
|
sig = download_asset(macos_sig)
|
||||||
'signature': macos_sig,
|
if sig:
|
||||||
'url': f'{base_url}/{macos}'
|
platforms["darwin-x86_64"] = {"signature": sig, "url": f"{BASE_URL}/{macos}"}
|
||||||
}
|
platforms["darwin-aarch64"] = {"signature": sig, "url": f"{BASE_URL}/{macos}"}
|
||||||
platforms['darwin-aarch64'] = {
|
|
||||||
'signature': macos_sig,
|
|
||||||
'url': f'{base_url}/{macos}'
|
|
||||||
}
|
|
||||||
|
|
||||||
latest = {
|
latest = {
|
||||||
'version': version,
|
"version": VERSION,
|
||||||
'notes': 'See the assets below to download and install.',
|
"notes": "See the assets below to download and install.",
|
||||||
'pub_date': subprocess.check_output(['date', '-u', '+%Y-%m-%dT%H:%M:%SZ']).decode().strip(),
|
"pub_date": run("date -u +%Y-%m-%dT%H:%M:%SZ"),
|
||||||
'platforms': platforms
|
"platforms": platforms,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('latest.json', 'w') as f:
|
with open("latest.json", "w") as f:
|
||||||
json.dump(latest, f, indent=2)
|
json.dump(latest, f, indent=2)
|
||||||
|
|
||||||
print(json.dumps(latest, indent=2))
|
print(json.dumps(latest, indent=2))
|
||||||
PYEOF
|
|
||||||
|
|
||||||
# Upload latest.json
|
subprocess.run(
|
||||||
gh release upload "$RELEASE_TAG" latest.json --clobber --repo "$REPO"
|
f'gh release upload "{TAG}" latest.json --clobber --repo "{REPO}"',
|
||||||
|
shell=True, check=True
|
||||||
|
)
|
||||||
|
print("latest.json uploaded successfully.")
|
||||||
|
PYEOF
|
||||||
|
|||||||
Reference in New Issue
Block a user