From 785f99f0ef2e92bccb03275ce649c43fd5073387 Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Tue, 31 Dec 2024 16:16:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=89=E7=8E=AF=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=93=BE=E6=8E=A5=E8=A7=84=E5=88=99=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20(=E8=A1=A5=E5=85=85=E8=B7=B3=E8=BD=AC=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=8A=E4=BC=A0=E7=9A=84=E8=84=9A=E6=9C=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/upload_route_doc.sh | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 scripts/upload_route_doc.sh diff --git a/scripts/upload_route_doc.sh b/scripts/upload_route_doc.sh new file mode 100755 index 0000000000..ada888ce3a --- /dev/null +++ b/scripts/upload_route_doc.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# @author juntao + +# --- Configuration --- +SEARCH_DIR="app/build/generated/ksp/" +JSON_FILE_NAME="router-map-of-app.json" +UPLOAD_URL="https://app-api.ghzs6.com/app_router_map" +TOKEN="672b30260e33cf5e1540ff31" +VERSION=$(awk -v FS="versionName = " 'NF>1{print $2}' dependencies.gradle | sed "s/\"//g") +# --- End Configuration --- + +# Do the build stuff to create a new JSON file +./gradlew clean +./gradlew assemblePublishCnRelease -PENABLE_ROUTE_DOC=true + +# Find the JSON file +JSON_FILE=$(find "$SEARCH_DIR" -type f -path "*/resources/com/gh/gamecenter/route/docs/*" -name "$JSON_FILE_NAME" -print -quit) + +# Check if jq is installed +if ! command -v jq &> /dev/null; then + echo "jq is not installed. Attempting to install..." + + # Try to determine the operating system + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Assume Debian/Ubuntu + if command -v apt-get &> /dev/null; then + sudo apt-get update + sudo apt-get install -y jq + else + echo "Error: Could not determine package manager for Linux distribution." + exit 1 + fi + elif [[ "$OSTYPE" == "darwin"* ]]; then + # Assume macOS (using Homebrew) + if command -v brew &> /dev/null; then + brew update + brew install jq + else + echo "Error: Homebrew is not installed on macOS. Please install it from https://brew.sh/" + exit 1 + fi + else + echo "Error: Unsupported operating system: $OSTYPE" + exit 1 + fi + + # Verify jq installation + if ! command -v jq &> /dev/null; then + echo "Error: jq installation failed." + exit 1 + fi +fi + +# Check if the JSON file exists +if [ ! -f "$JSON_FILE" ]; then + echo "Error: JSON file not found: $JSON_FILE" + exit 1 +fi + +# Use jq to construct the required JSON structure +NEW_JSON=$(jq -n \ + --arg version "$VERSION" \ + --argjson router_map "$(cat "$JSON_FILE")" \ + '{version: $version, router_map: $router_map}') + +# Upload the new JSON using curl +curl -X POST \ + -H "Content-Type: application/json" \ + -H "TOKEN: $TOKEN" \ + -d "$NEW_JSON" \ + "$UPLOAD_URL" \ No newline at end of file