Keep built APKs out of git; add Gitea release publish script.
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -17,3 +17,4 @@ xcuserdata
|
||||
/app/build-dir
|
||||
/app/repo
|
||||
/repo
|
||||
dist/
|
||||
|
||||
Vendored
BIN
Binary file not shown.
@@ -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 - <<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 -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 <<EOF
|
||||
## Hex Mines ${TAG}
|
||||
|
||||
First public build of the hexagonal minesweeper fork.
|
||||
|
||||
### Highlights
|
||||
- Flat-top hex tiles (6 neighbors)
|
||||
- Configurable board width / height
|
||||
- Configurable mine count slider
|
||||
- Based on [StefanOltmann/mines](https://github.com/StefanOltmann/mines) (AGPL-3.0)
|
||||
|
||||
### 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}"
|
||||
Reference in New Issue
Block a user