#!/bin/bash set -e prop() { grep "${1}" gradle.properties | cut -d'=' -f2 | sed 's/\r//' } [ -z "$API_URL" ] && { echo "Error: API_URL not set"; exit 1; } [ -z "$API_KEY" ] && { echo "Error: API_KEY not set"; exit 1; } [ -z "$PROJECT_KEY" ] && { echo "Error: PROJECT_KEY not set"; exit 1; } MC_VERSION=$(prop mcVersion) [ -z "$MC_VERSION" ] && { echo "Error: mcVersion not found in gradle.properties"; exit 1; } VERSION_BRANCH=${VERSION_BRANCH:-"ver/$MC_VERSION"} if [ "$(prop experimental)" = "true" ]; then CHANNEL="BETA" else CHANNEL="STABLE" fi LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [ -n "$LAST_TAG" ]; then COMMIT_COUNT=$(git log --oneline "$VERSION_BRANCH" ^"$LAST_TAG" 2>/dev/null | wc -l | tr -d ' ') else COMMIT_COUNT=$(git log --oneline "$VERSION_BRANCH" 2>/dev/null | wc -l | tr -d ' ') fi if [ "$COMMIT_COUNT" -gt 0 ]; then COMMITS_JSON="[" FIRST=true while IFS= read -r sha && IFS= read -r message && IFS= read -r time; do if [ "$FIRST" = true ]; then FIRST=false else COMMITS_JSON="$COMMITS_JSON," fi message=$(echo "$message" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\t/\\t/g' | tr -d '\n\r') COMMITS_JSON="$COMMITS_JSON{\"sha\":\"$sha\",\"message\":\"$message\",\"time\":\"$time\"}" done < <(git log --pretty='%H%n%s%n%cI' "$VERSION_BRANCH" -"$COMMIT_COUNT") COMMITS_JSON="$COMMITS_JSON]" else COMMITS_JSON="[]" fi METADATA=$(cat <