Files
magpie/.github/workflows/release.yml
T
yetone c4f7ba9d3a update: only a release whose SHA256SUMS carries the release key's signature is installed (danny0dong on X)
The updater took a file and its SHA-256 from the same feed answer, so
whoever could change /api/latest could swap both; only the Mac app also
checked its signing team. Now release CI (yetone/magpie-releases) signs
"magpie release <version>\n" + SHA256SUMS with an ed25519 key held as that
repo's UPDATE_SIGNING_KEY secret and publishes SHA256SUMS.sig (release
assets: 16 -> 17). The site worker carries the list and signature in the
feed; internal/update/signed.go checks them against the public key built
into the binary, takes each file's hash from the signed list and refuses a
missing or bad signature or a feed hash that differs. Versions from
0.1.3862 require it; older ones and binaries older than the key update as
before. MAGPIE_UPDATE_FEED lifts the requirement for local test servers.
mirror-release waits for 17 assets; docs/reference.md and code-standards
say 17 and describe the transition.

Run: go test internal/update, internal/cli, internal/gui -run Update|WhatsNew
(ok); node --test site/*.test.mjs (116 ok); gofmt; go vet darwin, linux
nogui, windows on internal/update. Broken by hand: signature check skipped
(tamper and other-key tests red), feed-hash comparison skipped (swapped
hash and feed tests red), worker not attaching signed (worker test red).
The embedded key is checked against a sample signed by the real key with
openssl, as CI does. Signing script run against a throwaway key.
Not tried: a real signed release before this tag; install.sh does not
verify the signature.
2026-11-12 16:43:23 +08:00

207 lines
10 KiB
YAML

name: Release
# Pushing a v* tag hands off to yetone/magpie-releases, which builds, signs,
# notarises and publishes magpie there; that repo is where people download
# from, and the signing secrets live only there. Once its release has every
# asset, the same release is copied here, so this repo's Releases page has
# the installers too (PapainTea on X). Self-update, install.sh and the site
# still read magpie-releases only.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 0.1.0 — no v prefix; the v tag must exist)'
required: true
type: string
jobs:
trigger-release:
runs-on: ubuntu-latest
# room for the dispatch to wait out the owner's API rate limit (65 min)
timeout-minutes: 75
outputs:
version: ${{ steps.version.outputs.version }}
ref: ${{ steps.version.outputs.ref }}
steps:
- name: Get version
id: version
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
REF="$GITHUB_REF_NAME"
VERSION="${REF#v}"
else
VERSION="$INPUT_VERSION"
REF="v$INPUT_VERSION"
fi
# a newline or quote would add outputs or break the JSON below
[[ "$VERSION" =~ ^[0-9][0-9A-Za-z.+-]*$ ]] || { echo "bad version: $VERSION" >&2; exit 1; }
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "ref=$REF" >> $GITHUB_OUTPUT
echo "Triggering release for version: $VERSION (ref: $REF)"
- name: Trigger release workflow in magpie-releases
env:
# PAT with contents write on yetone/magpie-releases. It is the
# owner's, so it shares the 5,000/hr core limit with every `gh`
# the owner runs: v0.1.3561 to v0.1.3573 failed here with "API
# rate limit exceeded" and never got a release. A rate-limited
# answer waits for the reset and tries again, up to 65 minutes.
TOKEN: ${{ secrets.RELEASES_REPO_TOKEN }}
API_URL: ${{ github.api_url }}
REF: ${{ steps.version.outputs.ref }}
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
payload=$(jq -nc --arg ref "$REF" --arg version "$VERSION" \
'{event_type: "release", client_payload: {ref: $ref, version: $version}}')
url="$API_URL/repos/yetone/magpie-releases/dispatches"
tmp=$(mktemp -d)
deadline=$(( $(date +%s) + ${DISPATCH_MAX_WAIT:-3900} ))
header() { awk -v k="$1" -F': *' 'tolower($1) == k { v = $2 } END { sub(/\r$/, "", v); print v }' "$tmp/headers"; }
for try in $(seq 1 100); do
code=$(curl -sS -o "$tmp/body" -D "$tmp/headers" -w '%{http_code}' -X POST \
-H "Authorization: Bearer $TOKEN" \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
--data "$payload" "$url") || { echo "::error::dispatch request failed (curl exit $?)"; exit 1; }
if [[ "$code" == 2* ]]; then
echo "Dispatched release for $REF (HTTP $code, try $try)"
exit 0
fi
retry_after=$(header retry-after)
remaining=$(header x-ratelimit-remaining)
reset=$(header x-ratelimit-reset)
limited=
if [[ "$code" == 403 || "$code" == 429 ]]; then
if [[ -n "$retry_after" || "$remaining" == 0 ]] || grep -qi 'rate limit' "$tmp/body"; then
limited=1
fi
fi
if [[ -z "$limited" ]]; then
echo "::error::dispatch failed with HTTP $code"
cat "$tmp/body"; echo
exit 1
fi
now=$(date +%s)
if [[ "$retry_after" =~ ^[0-9]+$ ]]; then
until=$(( now + retry_after ))
elif [[ "$reset" =~ ^[0-9]+$ ]] && (( reset > now )); then
until=$reset
else
until=$(( now + 60 )) # a secondary limit may give neither
fi
until=$(( until + 5 ))
if (( until > deadline )); then
echo "::error::rate limited (HTTP $code) until $(date -u -d "@$until" 2>/dev/null || echo "$until"), past the wait allowed"
cat "$tmp/body"; echo
exit 1
fi
echo "::warning::rate limited (HTTP $code, try $try); waiting $(( until - now ))s for the limit to reset"
sleep $(( until - now ))
done
echo "::error::dispatch still rate limited after $try tries"
exit 1
- name: Output status
run: echo "Watch the build at https://github.com/yetone/magpie-releases/actions"
mirror-release:
needs: trigger-release
runs-on: ubuntu-latest
# magpie-releases' macOS jobs can wait an hour or more for a hosted
# runner when several tags queue: v0.1.2262 published 62 minutes after
# its tag, two minutes after a 60-minute wait here gave up, and it was
# never copied here (#4488)
timeout-minutes: 330
permissions:
contents: write
issues: write # to say a release went out without Chinese notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REF: ${{ needs.trigger-release.outputs.ref }}
ASSETS: 17 # what every release carries; a smaller count is still uploading
steps:
- name: Wait for magpie-releases to publish every asset
run: |
for i in $(seq 1 600); do
n=$(gh release view "$REF" -R yetone/magpie-releases --json assets -q '.assets | length' 2>/dev/null || echo 0)
echo "attempt $i: $n of $ASSETS assets"
[ "$n" -ge "$ASSETS" ] && exit 0
sleep 30
done
echo "magpie-releases never published $REF with $ASSETS assets" >&2
exit 1
- name: Copy the release here
run: |
set -euo pipefail
mkdir -p dist
gh release download "$REF" -R yetone/magpie-releases -D dist
gh release view "$REF" -R yetone/magpie-releases --json body -q .body > notes.md
printf '\n\n---\nThe same release, and the feed magpie updates from: https://github.com/yetone/magpie-releases/releases/tag/%s\n' "$REF" >> notes.md
# GitHub marks the release published last Latest unless told
# otherwise. v0.1.3360's mac signing failed and its rerun was
# copied here after 3361 and 3362, so it took the mark (11-09):
# a release is Latest only when no published one here is higher,
# and the highest has the mark once this one is out.
newest() {
gh release list -R "$GITHUB_REPOSITORY" -L 100 --exclude-drafts --exclude-pre-releases --json tagName -q '.[].tagName' |
{ grep -E '^v[0-9]+(\.[0-9]+)*$' || true; } | sort -V | tail -1
}
top=$(newest)
if [ -z "$top" ] || [ "$(printf '%s\n%s\n' "$top" "$REF" | sort -V | tail -1)" = "$REF" ]; then
latest=true
else
latest=false
echo "$top is newer: $REF is copied without the Latest mark"
fi
if gh release view "$REF" -R "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release edit "$REF" -R "$GITHUB_REPOSITORY" --notes-file notes.md --latest="$latest"
gh release upload "$REF" dist/* -R "$GITHUB_REPOSITORY" --clobber
else
gh release create "$REF" dist/* -R "$GITHUB_REPOSITORY" --verify-tag --title "magpie $REF" --notes-file notes.md --latest="$latest"
fi
n=$(gh release view "$REF" -R "$GITHUB_REPOSITORY" --json assets -q '.assets | length')
echo "$REF has $n assets here"
[ "$n" -ge "$ASSETS" ]
# two copies at once can each decide before the other is out
top=$(newest)
now=$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" -q .tag_name 2>/dev/null || true)
if [ -n "$top" ] && [ "$now" != "$top" ]; then
echo "Latest here was ${now:-none}: giving the mark to $top"
gh release edit "$top" -R "$GITHUB_REPOSITORY" --latest >/dev/null
fi
# The Chinese notes are written by magpie-releases' DeepSeek call, and
# when that call fails the release goes out in English alone: a spent
# balance did so for v0.1.1233 to v0.1.1242, and Chinese apps showed
# English for a day until a user said so (#2122). Its warning is in a
# log nobody reads, so a release without them is said here, on one
# open issue. magpie-releases' notes.yml writes them again each hour
# once DeepSeek answers (it didn't for v0.1.2634 to 2646, a spent
# balance again), and notes-mirror.yml copies them here.
- name: Say when the notes have no Chinese
env:
GH_REPO: ${{ github.repository }}
run: |
set -uo pipefail
if grep -qF '<!-- lang:zh -->' notes.md; then
echo "$REF has Chinese notes"
exit 0
fi
title="Release notes without Chinese"
msg="$REF went out with English notes alone: magpie-releases' release run got no Chinese from DeepSeek. Its reason is the \`DeepSeek wrote no Chinese notes\` warning in that run's Generate changelog step (https://github.com/yetone/magpie-releases/actions); \`insufficient_balance_error\` means the DEEPSEEK_API_KEY account needs a top-up. Until then apps set to Chinese show its commit subjects (#2122). magpie-releases' notes.yml writes the notes again each hour once DeepSeek answers, and notes-mirror.yml copies them here; notes written by hand below a \`<!-- lang:zh -->\` marker are kept."
n=$(gh issue list --state open --search "\"$title\" in:title" --json number,title -q ".[] | select(.title == \"$title\") | .number" | head -1) || n=""
if [ -n "$n" ]; then
gh issue comment "$n" --body "$msg" || echo "::warning::could not comment on #$n: $msg"
else
gh issue create --title "$title" --body "$msg" || echo "::warning::could not file an issue: $msg"
fi