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