diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml deleted file mode 100644 index bc0cd7a..0000000 --- a/.github/workflows/android-ci.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Deploy - -on: - workflow_dispatch: - -permissions: - contents: write - -jobs: - deploy: - name: Build & Deploy to VPS - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 17 - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: Versionsnummer ermitteln und erhoehen - id: version - run: | - CURRENT_CODE=$(grep 'versionCode' app/build.gradle.kts | grep -oP '\d+' | head -1) - NEW_CODE=$((CURRENT_CODE + 1)) - VERSION_NAME=$(grep 'versionName' app/build.gradle.kts | grep -oP '"[0-9]+\.[0-9]+"' | tr -d '"' | head -1) - sed -i "s/versionCode = ${CURRENT_CODE}/versionCode = ${NEW_CODE}/" app/build.gradle.kts - echo "new_code=${NEW_CODE}" >> $GITHUB_OUTPUT - echo "version_name=${VERSION_NAME}" >> $GITHUB_OUTPUT - echo "Neue Version: v${VERSION_NAME} (${NEW_CODE})" - - - name: APK bauen - run: ./gradlew assembleDebug - - - name: APK auf VPS deployen - env: - BOLLWERK_ADMIN_TOKEN: ${{ secrets.BOLLWERK_ADMIN_TOKEN }} - VPS_SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }} - run: | - VERSION_CODE="${{ steps.version.outputs.new_code }}" - VERSION_NAME="${{ steps.version.outputs.version_name }}" - - mkdir -p ~/.ssh - echo "$VPS_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H 195.246.231.210 >> ~/.ssh/known_hosts - - scp app/build/outputs/apk/debug/app-debug.apk \ - root@195.246.231.210:/opt/bollwerk/data/app-latest.apk - - curl -sf -X POST https://bollwerk.online/api/admin/version \ - -H "Authorization: Bearer $BOLLWERK_ADMIN_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"versionCode\": ${VERSION_CODE}, \"versionName\": \"${VERSION_NAME}\"}" - - echo "Deployed: v${VERSION_NAME} (${VERSION_CODE})" - - - name: Version-Bump committen - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add app/build.gradle.kts - git commit -m "chore: auto version bump -> ${{ steps.version.outputs.version_name }} (${{ steps.version.outputs.new_code }}) [skip ci]" - git push diff --git a/deploy.ps1 b/deploy.ps1 new file mode 100644 index 0000000..83ef639 --- /dev/null +++ b/deploy.ps1 @@ -0,0 +1,133 @@ +<# +.SYNOPSIS + Bollwerk App in einem Schritt deployen. +.DESCRIPTION + Führt den vollständigen Release-Workflow aus: + 1. versionCode automatisch erhöhen (versionName optional setzen) + 2. APK bauen (./gradlew assembleDebug) + 3. APK per SCP auf VPS hochladen + 4. Server-Version per API aktualisieren (kein Container-Neustart) + 5. Version-Bump committen und pushen +.PARAMETER VersionName + Neue versionName (z.B. "1.8"). Wenn weggelassen, bleibt die aktuelle. +.PARAMETER SkipBuild + Gradle-Build überspringen (wenn APK bereits gebaut). +.PARAMETER SkipPush + Git-Push überspringen (nur lokaler Commit). +.EXAMPLE + .\deploy.ps1 + .\deploy.ps1 -VersionName "2.0" + .\deploy.ps1 -SkipBuild +#> +param( + [string] $VersionName, + [switch] $SkipBuild, + [switch] $SkipPush +) + +$ErrorActionPreference = "Stop" +$VPS = "root@195.246.231.210" +$RemoteDir = "/opt/bollwerk" +$ServerUrl = "https://bollwerk.online" +$BuildGradle = "app/build.gradle.kts" +$ApkPath = "app/build/outputs/apk/debug/app-debug.apk" + +# --- Admin-Token --- +$AdminToken = $env:BOLLWERK_ADMIN_TOKEN +if (-not $AdminToken) { + Write-Error @" +BOLLWERK_ADMIN_TOKEN nicht gesetzt. +Bitte einmalig in der Session setzen: + `$env:BOLLWERK_ADMIN_TOKEN = 'tRIdxACDDjJDOXRd0WDnIN2f' +"@ + exit 1 +} + +# --- Version lesen --- +$content = Get-Content $BuildGradle -Raw +$currentCode = [int]([regex]::Match($content, 'versionCode\s*=\s*(\d+)').Groups[1].Value) +$currentName = [regex]::Match($content, 'versionName\s*=\s*"([^"]+)"').Groups[1].Value +$newCode = $currentCode + 1 +$newName = if ($VersionName) { $VersionName } else { $currentName } + +Write-Host "" +Write-Host "╔══════════════════════════════════════╗" -ForegroundColor Cyan +Write-Host "║ Bollwerk Deploy ║" -ForegroundColor Cyan +Write-Host "╚══════════════════════════════════════╝" -ForegroundColor Cyan +Write-Host " Version: $currentName ($currentCode) → $newName ($newCode)" -ForegroundColor White +Write-Host "" + +# --- build.gradle.kts patchen --- +$updated = $content -replace "versionCode\s*=\s*$currentCode", "versionCode = $newCode" +if ($VersionName) { + $updated = $updated -replace 'versionName\s*=\s*"[^"]+"', "versionName = `"$newName`"" +} +[System.IO.File]::WriteAllText((Resolve-Path $BuildGradle).Path, $updated) +Write-Host "[✓] build.gradle.kts aktualisiert" -ForegroundColor Green + +# --- Build --- +if (-not $SkipBuild) { + Write-Host "" + Write-Host "[1/4] APK bauen..." -ForegroundColor Yellow + & ./gradlew assembleDebug + if ($LASTEXITCODE -ne 0) { Write-Error "Build fehlgeschlagen."; exit 1 } + Write-Host "[✓] APK gebaut" -ForegroundColor Green +} else { + Write-Host "[1/4] Build übersprungen (-SkipBuild)" -ForegroundColor DarkYellow +} + +if (-not (Test-Path $ApkPath)) { + Write-Error "APK nicht gefunden: $ApkPath" + exit 1 +} + +# --- SSH-Agent prüfen --- +$null = ssh-add -l 2>&1 +if ($LASTEXITCODE -ne 0) { + Write-Error "SSH-Agent hat keinen Key. Bitte 'ssh-add' ausführen." + exit 1 +} + +# --- APK hochladen --- +Write-Host "" +Write-Host "[2/4] APK hochladen → VPS..." -ForegroundColor Yellow +ssh $VPS "mkdir -p $RemoteDir/data" 2>&1 | Out-Null +scp $ApkPath "${VPS}:${RemoteDir}/data/app-latest.apk" +if ($LASTEXITCODE -ne 0) { Write-Error "APK-Upload fehlgeschlagen."; exit 1 } +Write-Host "[✓] APK hochgeladen" -ForegroundColor Green + +# --- Server-Version setzen --- +Write-Host "" +Write-Host "[3/4] Server-Version aktualisieren..." -ForegroundColor Yellow +$body = @{ versionCode = $newCode; versionName = $newName } | ConvertTo-Json -Compress +try { + $resp = Invoke-WebRequest -Uri "$ServerUrl/api/admin/version" ` + -Method POST ` + -Headers @{ "Authorization" = "Bearer $AdminToken"; "Content-Type" = "application/json" } ` + -Body $body ` + -UseBasicParsing + Write-Host "[✓] Version gesetzt: $newName ($newCode)" -ForegroundColor Green +} catch { + Write-Error "Version-Update fehlgeschlagen: $_" + exit 1 +} + +# --- Git Commit + Push --- +Write-Host "" +Write-Host "[4/4] Committen..." -ForegroundColor Yellow +git add $BuildGradle +git commit -m "chore: release v$newName ($newCode)" +if (-not $SkipPush) { + git push + Write-Host "[✓] Gepusht" -ForegroundColor Green +} + +# --- Fertig --- +Write-Host "" +Write-Host "╔══════════════════════════════════════╗" -ForegroundColor Green +Write-Host "║ Deploy abgeschlossen ✓ ║" -ForegroundColor Green +Write-Host "╚══════════════════════════════════════╝" -ForegroundColor Green +Write-Host " App-Version : $newName ($newCode)" +Write-Host " Homepage : $ServerUrl/" +Write-Host " APK-Download: $ServerUrl/static/app-latest.apk" +Write-Host ""