Files
Incido/scripts/ci/backfill-release-notes.sh
Incido Developer 7b6187f99a ci(release): attach per-version notes from PREVIOUS_HISTORY.md to releases
Per-version user-facing changelog moved out of the README table into
PREVIOUS_HISTORY.md (newest-first sections, Development Plan §11.1).
On tag push the workflow now harvests the matching section via
scripts/ci/release-notes.py and uses it as the release description,
uploading an Incido-<version>-changes.md beside the APKs; a missing
section falls back to the plain default description. CONTRIBUTING §5
documents the new release-notes maintenance step.
2026-09-17 15:43:20 +12:00

55 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# One-off helper: attach PREVIOUS_HISTORY.md notes to EXISTING Gitea
# releases that were published before the automatic pipeline existed.
#
# TOKEN=<gitea-token-with-release-write> ./backfill-release-notes.sh [version ...]
#
# With no arguments it walks every section of PREVIOUS_HISTORY.md and
# silently skips versions that have no release entry / no section.
# Idempotent: replaces both the description and the changes-file asset.
set -euo pipefail
API="${GITEA_API:-https://git.trevena.info/api/v1/repos/nick/incido}"
: "${TOKEN:?Set TOKEN to a Gitea token with release write access}"
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
NOTES_PY="$ROOT/scripts/ci/release-notes.py"
if [ "$#" -gt 0 ]; then
VERSIONS=("$@")
else
mapfile -t VERSIONS < <(grep -oE '^## v[0-9]+(\.[0-9]+)+' "$ROOT/PREVIOUS_HISTORY.md" | sed 's/^## v//')
fi
for V in "${VERSIONS[@]}"; do
TAG="v$V"
RID=$(curl -s "$API/releases/tags/$TAG" \
-H "Authorization: token $TOKEN" \
| python3 -c "import sys,json; print(json.load(sys.stdin).get('id','') or '')")
if [ -z "$RID" ]; then echo "skip $TAG (no release entry)"; continue; fi
NOTES="/tmp/Incido-$V-changes.md"
if ! python3 "$NOTES_PY" "$V" --out "$NOTES"; then
echo "skip $TAG (no PREVIOUS_HISTORY.md section)"; continue
fi
# Refresh the description.
REL_NOTES_FILE="$NOTES" python3 -c "import json,os; print(json.dumps({'body': open(os.environ['REL_NOTES_FILE'],encoding='utf-8').read()}))" \
> /tmp/body_patch.json
curl -s -X PATCH "$API/releases/$RID" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d @/tmp/body_patch.json > /dev/null
# Replace a stale changes-file asset, then upload the fresh one.
curl -s "$API/releases/$RID/assets" -H "Authorization: token $TOKEN" \
| REL_ASSET_NAME="Incido-$V-changes.md" python3 -c "import sys,json,os; [print(a['id']) for a in json.load(sys.stdin) if a['name']==os.environ['REL_ASSET_NAME']]" \
| while read -r AID; do
curl -s -X DELETE "$API/releases/$RID/assets/$AID" -H "Authorization: token $TOKEN" > /dev/null
done
curl -s -f -X POST "$API/releases/$RID/assets?name=Incido-$V-changes.md" \
-H "Authorization: token $TOKEN" \
-F "attachment=@$NOTES" --max-time 600 > /dev/null \
|| echo "WARN $TAG: description patched, but the changes-file upload failed"
echo "done $TAG"
done