diff --git a/.gitignore b/.gitignore index 34d72b4..59b011a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ xcuserdata /app/build-dir /app/repo /repo +dist/ diff --git a/dist/HexMines-0.1.0-debug.apk b/dist/HexMines-0.1.0-debug.apk deleted file mode 100644 index 83fcc32..0000000 Binary files a/dist/HexMines-0.1.0-debug.apk and /dev/null differ diff --git a/publish-gitea-release.sh b/publish-gitea-release.sh new file mode 100644 index 0000000..c75ba31 --- /dev/null +++ b/publish-gitea-release.sh @@ -0,0 +1,147 @@ +#!/usr/bin/env bash +# Create Dawnsorrow/hex-mines on Gitea (if needed), push main, create v0.1.0 +# release, and upload the debug APK. +# +# Requires: GITEA_TOKEN (repo write), curl, python3, git +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.1.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 - <&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 -u "$PUSH_URL_AUTH" HEAD:main + +# Create / move tag locally +git tag -f "$TAG" +git push -f "$PUSH_URL_AUTH" "refs/tags/${TAG}" + +NOTE=$(cat <&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}"