#!/usr/bin/env bash # CI: .env GC_MOBILE_APP_VERSION 또는 build.gradle 기준 patch bump + versionCode++ set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" WORK_TREE="${WORK_TREE:-$ROOT}" GRADLE="${GRADLE:-$ROOT/app/android/app/build.gradle}" ENV_FILE="${ENV_FILE:-$WORK_TREE/.env}" if [[ ! -f "$GRADLE" ]]; then echo "build.gradle 없음: $GRADLE" >&2 exit 1 fi ENV_VER="" if [[ -f "$ENV_FILE" ]]; then ENV_VER="$(grep '^GC_MOBILE_APP_VERSION=' "$ENV_FILE" 2>/dev/null | cut -d= -f2- | tr -d '\r' || true)" fi node -e " const fs = require('fs'); const gradlePath = process.argv[1]; const envVersion = (process.argv[2] || '').trim(); let content = fs.readFileSync(gradlePath, 'utf8'); const vc = content.match(/versionCode\\s+(\\d+)/); const vn = content.match(/versionName\\s+\"([^\"]+)\"/); if (!vc || !vn) { console.error('versionCode/versionName 파싱 실패'); process.exit(1); } let versionCode = parseInt(vc[1], 10); let base = envVersion || vn[1]; const parts = base.split('.').map(n => parseInt(n, 10) || 0); while (parts.length < 2) parts.push(0); if (parts.length === 2) { parts[1] += 1; } else { while (parts.length < 3) parts.push(0); parts[2] += 1; } const versionName = parts.join('.'); versionCode += 1; content = content.replace(/versionCode\\s+\\d+/, 'versionCode ' + versionCode); content = content.replace(/versionName\\s+\"[^\"]+\"/, 'versionName \"' + versionName + '\"'); fs.writeFileSync(gradlePath, content); console.log(versionName); " "$GRADLE" "$ENV_VER"