Files
hex-mines/publish-gitea-release.sh
DawnsorrowandCursor 8b6cc0bedc
Deploy / Build Kotlin/Wasm (push) Canceled after 0s
Build Android APK / Android (push) Canceled after 0s
Build Desktop app / Build Desktop app (push) Canceled after 0s
Update Gitea publish script for v0.2.0 releases.
Co-authored-by: Cursor <[email protected]>
2026-07-29 08:15:46 -05:00

150 lines
4.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Create Dawnsorrow/hex-mines on Gitea (if needed), push main, create a
# release, and upload the debug APK.
#
# Requires: GITEA_TOKEN (repo write), curl, python3, git
# Optional: HEX_MINES_VERSION (default 0.2.0)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
OWNER="${GITEA_OWNER:-Dawnsorrow}"
REPO="${GITEA_REPO:-hex-mines}"
BASE="${GITEA_BASE_URL:-https://git.hisora.dev}"
BASE="${BASE%/}"
VERSION="${HEX_MINES_VERSION:-0.2.0}"
TAG="v${VERSION}"
TITLE="Hex Mines ${TAG}"
APK="${1:-${ROOT}/dist/HexMines-${VERSION}-debug.apk}"
if [[ -z "${GITEA_TOKEN:-}" ]]; then
echo "Set GITEA_TOKEN (Gitea personal access token with repo write)." >&2
exit 1
fi
if [[ ! -f "$APK" ]]; then
echo "Missing APK: $APK" >&2
echo "Build first: ./build-debug-apk.sh && mkdir -p dist && cp app/build/outputs/apk/debug/app-debug.apk dist/HexMines-${VERSION}-debug.apk" >&2
exit 1
fi
API="${BASE}/api/v1"
AUTH=(-H "Authorization: token ${GITEA_TOKEN}")
echo "Ensuring repo ${OWNER}/${REPO} exists ..."
HTTP=$(curl -sS -o /tmp/hm-repo.json -w "%{http_code}" \
"${AUTH[@]}" \
"${API}/repos/${OWNER}/${REPO}" || true)
if [[ "$HTTP" == "404" ]]; then
HTTP=$(curl -sS -o /tmp/hm-repo.json -w "%{http_code}" \
"${AUTH[@]}" \
-H "Content-Type: application/json" \
-X POST "${API}/user/repos" \
-d "$(python3 - <<PY
import json
print(json.dumps({
"name": "${REPO}",
"description": "Hexagonal minesweeper fork of StefanOltmann/mines (AGPL-3.0)",
"private": False,
"auto_init": False,
}))
PY
)")
if [[ "$HTTP" != "201" ]]; then
echo "Failed to create repo: HTTP $HTTP" >&2
cat /tmp/hm-repo.json >&2
exit 1
fi
echo "Created ${OWNER}/${REPO}"
elif [[ "$HTTP" != "200" ]]; then
echo "Failed to fetch repo: HTTP $HTTP" >&2
cat /tmp/hm-repo.json >&2
exit 1
fi
CLONE_URL=$(python3 -c 'import json; print(json.load(open("/tmp/hm-repo.json"))["clone_url"])')
# Prefer token HTTPS push URL
PUSH_URL="${BASE}/${OWNER}/${REPO}.git"
PUSH_URL_AUTH="https://oauth2:${GITEA_TOKEN}@${BASE#https://}/${OWNER}/${REPO}.git"
cd "$ROOT"
if git remote get-url origin >/dev/null 2>&1; then
git remote set-url origin "$PUSH_URL"
else
git remote add origin "$PUSH_URL"
fi
echo "Pushing main and tag ${TAG} ..."
git push "$PUSH_URL_AUTH" HEAD:main
git branch --set-upstream-to=origin/main main 2>/dev/null || true
# Create / move tag locally
git tag -f "$TAG"
git push -f "$PUSH_URL_AUTH" "refs/tags/${TAG}"
NOTE=$(cat <<EOF
## Hex Mines ${TAG}
Hexagonal minesweeper fork of [StefanOltmann/mines](https://github.com/StefanOltmann/mines) (AGPL-3.0).
### Highlights
- Flat-top hex tiles (6 neighbors)
- Layout modes: **Rows** (width × height) and **Hexagon** (side length)
- Configurable mine count slider
- Settings icon sizing fix for usable sliders
### Install
Download \`HexMines-${VERSION}-debug.apk\` and install on Android (debug-signed).
\`\`\`bash
adb install -r HexMines-${VERSION}-debug.apk
\`\`\`
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} ..."
HTTP=$(curl -sS -o /tmp/hm-release.json -w "%{http_code}" \
"${AUTH[@]}" \
-H "Content-Type: application/json" \
-X POST "${API}/repos/${OWNER}/${REPO}/releases" \
-d "$CREATE_BODY")
if [[ "$HTTP" == "409" || "$HTTP" == "400" ]]; then
echo "Release may already exist (HTTP $HTTP); fetching..."
curl -sS "${AUTH[@]}" \
"${API}/repos/${OWNER}/${REPO}/releases/tags/${TAG}" \
-o /tmp/hm-release.json
elif [[ "$HTTP" != "200" && "$HTTP" != "201" ]]; then
echo "Failed to create release: HTTP $HTTP" >&2
cat /tmp/hm-release.json >&2
exit 1
fi
RELEASE_ID=$(python3 -c 'import json; print(json.load(open("/tmp/hm-release.json"))["id"])')
echo "Release id=${RELEASE_ID}"
NAME="$(basename "$APK")"
echo "Uploading ${NAME} ..."
curl -sS -f \
"${AUTH[@]}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${APK}" \
"${API}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=${NAME}" \
-o /tmp/hm-asset.json
echo "Uploaded: $(python3 -c 'import json; d=json.load(open("/tmp/hm-asset.json")); print(d.get("browser_download_url") or d.get("name"))')"
echo "Done: ${BASE}/${OWNER}/${REPO}/releases/tag/${TAG}"