Session-gated MinIO save sync with AppImage GUI, CLI edit/session flow, and Gitea release helper. Co-authored-by: Cursor <[email protected]>
102 lines
2.9 KiB
Bash
Executable File
102 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Create a Gitea release and upload AppImage/APK assets.
|
|
# Requires: GITEA_TOKEN, curl, python3
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
OWNER="${GITEA_OWNER:-Dawnsorrow}"
|
|
REPO="${GITEA_REPO_OVERRIDE:-SyncGames}"
|
|
BASE="${GITEA_BASE_URL:-https://git.hisora.dev}"
|
|
BASE="${BASE%/}"
|
|
VERSION="$(python3 -c "import tomllib; print(tomllib.load(open('${ROOT}/agent/pyproject.toml','rb'))['project']['version'])")"
|
|
TAG="v${VERSION}"
|
|
TITLE="SyncGames ${TAG}"
|
|
|
|
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
|
echo "Set GITEA_TOKEN (Gitea personal access token with repo write)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
APPIMAGE="${1:-${ROOT}/dist/SyncGames-${VERSION}-x86_64.AppImage}"
|
|
APK="${2:-${ROOT}/dist/SyncGames-${VERSION}-debug.apk}"
|
|
|
|
if [[ ! -f "$APPIMAGE" ]]; then
|
|
echo "Missing AppImage: $APPIMAGE" >&2
|
|
echo "Build first: (cd agent && ./packaging/build-appimage.sh) && cp agent/dist/*.AppImage dist/" >&2
|
|
exit 1
|
|
fi
|
|
|
|
API="${BASE}/api/v1/repos/${OWNER}/${REPO}"
|
|
|
|
NOTE=$(cat <<EOF
|
|
## SyncGames ${TAG}
|
|
|
|
Linux AppImage for session-gated save sync.
|
|
|
|
### Install
|
|
\`\`\`bash
|
|
chmod +x SyncGames-${VERSION}-x86_64.AppImage
|
|
./SyncGames-${VERSION}-x86_64.AppImage
|
|
\`\`\`
|
|
|
|
Configure MinIO endpoint under **Setup**, edit game paths under **Games**, then **Start** / **End** sessions.
|
|
EOF
|
|
)
|
|
|
|
CREATE_BODY=$(TAG="$TAG" TITLE="$TITLE" NOTE="$NOTE" python3 - <<'PY'
|
|
import json, os
|
|
print(json.dumps({
|
|
"tag_name": os.environ["TAG"],
|
|
"target_commitish": "main",
|
|
"name": os.environ["TITLE"],
|
|
"body": os.environ["NOTE"],
|
|
"draft": False,
|
|
"prerelease": False,
|
|
}))
|
|
PY
|
|
)
|
|
|
|
echo "Creating release ${TAG} on ${OWNER}/${REPO} ..."
|
|
HTTP=$(curl -sS -o /tmp/sg-release.json -w "%{http_code}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-X POST "${API}/releases" \
|
|
-d "$CREATE_BODY")
|
|
|
|
if [[ "$HTTP" == "409" ]] || [[ "$HTTP" == "400" ]]; then
|
|
echo "Release may already exist (HTTP $HTTP); fetching..."
|
|
curl -sS \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${API}/releases/tags/${TAG}" -o /tmp/sg-release.json
|
|
elif [[ "$HTTP" != "200" && "$HTTP" != "201" ]]; then
|
|
echo "Failed to create release: HTTP $HTTP" >&2
|
|
cat /tmp/sg-release.json >&2
|
|
exit 1
|
|
fi
|
|
|
|
RELEASE_ID=$(python3 -c 'import json; print(json.load(open("/tmp/sg-release.json"))["id"])')
|
|
echo "Release id=${RELEASE_ID}"
|
|
|
|
upload() {
|
|
local file="$1"
|
|
local name
|
|
name="$(basename "$file")"
|
|
echo "Uploading ${name} ..."
|
|
curl -sS -f \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"${file}" \
|
|
"${API}/releases/${RELEASE_ID}/assets?name=${name}" \
|
|
-o /tmp/sg-asset.json
|
|
echo " → $(python3 -c 'import json; d=json.load(open("/tmp/sg-asset.json")); print(d.get("browser_download_url") or d.get("name"))')"
|
|
}
|
|
|
|
upload "$APPIMAGE"
|
|
if [[ -f "$APK" ]]; then
|
|
upload "$APK"
|
|
else
|
|
echo "Skipping APK (not found at $APK)"
|
|
fi
|
|
|
|
echo "Done: ${BASE}/${OWNER}/${REPO}/releases/tag/${TAG}"
|