- README: add 'What's different from OpenGD77' (incl. the new SK2 mute) and a dedicated 'Flashing' section (DFU steps, per-model flash.sh, donor note). - scripts/forgejo-release.sh: build/attach a single platform or all, reuse an existing release, replace same-named assets, and warn if freetrxVersion.h doesn't match the tag. - TOOLS.md: document the platform build argument. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74 lines
3.6 KiB
Bash
74 lines
3.6 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# Build and publish a FreeTRX release on Forgejo, attaching the firmware binaries.
|
|
#
|
|
# Requires a Forgejo API token in FORGEJO_TOKEN
|
|
# (Forgejo -> Settings -> Applications -> Generate New Token, scope: write:repository).
|
|
# Release notes are taken from the matching "## <version>" section of CHANGELOG.md.
|
|
# If the release already exists it is reused; assets of the same name are replaced.
|
|
#
|
|
# Usage: FORGEJO_TOKEN=xxx scripts/forgejo-release.sh <tag> [platform ...]
|
|
# platform: MDUV380 | DM1701 | all (default: all)
|
|
# Examples:
|
|
# scripts/forgejo-release.sh v0.1.0 # build + attach both binaries
|
|
# scripts/forgejo-release.sh v0.1.0 MDUV380 # just the MD-UV380 binary
|
|
#
|
|
set -euo pipefail
|
|
|
|
TAG="${1:?usage: FORGEJO_TOKEN=... $0 <tag> [MDUV380|DM1701|all]}"; shift || true
|
|
VER="${TAG#v}"
|
|
API="https://git.dk1da.de/api/v1/repos/DK1DA/FreeTRX"
|
|
: "${FORGEJO_TOKEN:?set FORGEJO_TOKEN (Forgejo -> Settings -> Applications, scope write:repository)}"
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
# Resolve requested platforms (default / "all" -> both).
|
|
PLATFORMS=("$@")
|
|
if [ ${#PLATFORMS[@]} -eq 0 ] || [ "${PLATFORMS[0]}" = "all" ]; then
|
|
PLATFORMS=(MDUV380 DM1701)
|
|
fi
|
|
bin_for() { case "$1" in MDUV380) echo OpenMDUV380 ;; DM1701) echo OpenDM1701 ;; *) return 1 ;; esac; }
|
|
|
|
# Sanity check: the on-screen version should match the tag.
|
|
FW_VER="$(grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' MDUV380_firmware/application/include/freetrxVersion.h | head -1 | tr -d '"')"
|
|
[ "$FW_VER" = "$VER" ] || echo "WARNING: freetrxVersion.h is $FW_VER but tag is $VER — bump it before releasing?"
|
|
|
|
# Build each platform and stage its binary (clean builds overwrite build/).
|
|
STAGE="$(mktemp -d)"; trap 'rm -rf "$STAGE"' EXIT
|
|
for P in "${PLATFORMS[@]}"; do
|
|
OUT="$(bin_for "$P")" || { echo "Unknown platform '$P' (use MDUV380, DM1701 or all)"; exit 1; }
|
|
echo "==> Building $P"
|
|
./build-firmware.sh "$P" >/dev/null
|
|
cp "MDUV380_firmware/build/${OUT}.bin" "$STAGE/${OUT}.bin"
|
|
done
|
|
|
|
# Release notes = the CHANGELOG section for this version.
|
|
NOTES="$(awk -v v="## ${VER}" '$0==v{f=1} f&&/^## /&&$0!=v{exit} f{print}' CHANGELOG.md)"
|
|
[ -n "$NOTES" ] || NOTES="FreeTRX ${TAG}"
|
|
|
|
# Create the release, or reuse it if it already exists.
|
|
ID="$(curl -sS "$API/releases/tags/$TAG" -H "Authorization: token $FORGEJO_TOKEN" | python3 -c '
|
|
import json,sys
|
|
try:
|
|
d=json.load(sys.stdin); print(d.get("id","") if isinstance(d,dict) else "")
|
|
except Exception:
|
|
print("")')"
|
|
if [ -z "$ID" ]; then
|
|
BODY="$(python3 -c 'import json,sys; print(json.dumps({"tag_name":sys.argv[1],"name":"FreeTRX "+sys.argv[1],"body":sys.argv[2],"draft":False,"prerelease":False}))' "$TAG" "$NOTES")"
|
|
ID="$(curl -fsS -X POST "$API/releases" -H "Authorization: token $FORGEJO_TOKEN" -H "Content-Type: application/json" -d "$BODY" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')"
|
|
echo "==> Created release $TAG (id=$ID)"
|
|
else
|
|
echo "==> Reusing existing release $TAG (id=$ID)"
|
|
fi
|
|
|
|
# Attach each staged binary, replacing an existing asset of the same name.
|
|
ASSETS="$(curl -fsS "$API/releases/$ID/assets" -H "Authorization: token $FORGEJO_TOKEN")"
|
|
for f in "$STAGE"/*.bin; do
|
|
name="$(basename "$f")"
|
|
aid="$(printf '%s' "$ASSETS" | python3 -c 'import json,sys; n=sys.argv[1]; print(next((str(a["id"]) for a in json.load(sys.stdin) if a.get("name")==n),""))' "$name")"
|
|
[ -z "$aid" ] || curl -fsS -X DELETE "$API/releases/$ID/assets/$aid" -H "Authorization: token $FORGEJO_TOKEN" >/dev/null
|
|
curl -fsS -X POST "$API/releases/$ID/assets?name=$name" -H "Authorization: token $FORGEJO_TOKEN" -F "attachment=@$f" >/dev/null
|
|
echo "==> Attached $name"
|
|
done
|
|
|
|
echo "==> Done -> https://git.dk1da.de/DK1DA/FreeTRX/releases/tag/$TAG"
|