name: Build and Release to F-Droid on: push: tags: - '*' workflow_dispatch: jobs: build-and-deploy: runs-on: docker steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Java uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: '17' - name: Install jq run: | set -e SUDO="" if command -v sudo >/dev/null 2>&1; then SUDO="sudo" fi if command -v apt-get >/dev/null 2>&1; then $SUDO apt-get update $SUDO apt-get install -y jq elif command -v apk >/dev/null 2>&1; then $SUDO apk add --no-cache jq elif command -v dnf >/dev/null 2>&1; then $SUDO dnf install -y jq elif command -v yum >/dev/null 2>&1; then $SUDO yum install -y jq else echo "Could not find a supported package manager to install jq" exit 1 fi - name: Setup Flutter uses: subosito/flutter-action@v2 with: channel: 'stable' - name: Trust Flutter SDK git directory run: | set -e FLUTTER_BIN_DIR="$(dirname "$(command -v flutter)")" FLUTTER_SDK_DIR="$(cd "$FLUTTER_BIN_DIR/.." && pwd -P)" git config --global --add safe.directory "$FLUTTER_SDK_DIR" if [ -n "${FLUTTER_ROOT:-}" ]; then git config --global --add safe.directory "$FLUTTER_ROOT" fi # Runner-specific fallback observed in failing logs git config --global --add safe.directory /opt/hostedtoolcache/flutter/stable-3.41.4-x64 || true - name: Install dependencies run: flutter pub get # ADD THIS NEW STEP - name: Setup Android Keystore env: KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} KEY_ALIAS: ${{ secrets.KEY_ALIAS }} run: | # Decode the base64 string back into the binary .jks file echo "$KEYSTORE_BASE64" | base64 --decode > android/app/upload-keystore.jks # Create the key.properties file that build.gradle expects echo "storePassword=$KEY_PASSWORD" > android/key.properties echo "keyPassword=$KEY_PASSWORD" >> android/key.properties echo "keyAlias=$KEY_ALIAS" >> android/key.properties echo "storeFile=upload-keystore.jks" >> android/key.properties - name: Build APK run: flutter build apk --release - name: Setup F-Droid Server Tools run: | sudo apt-get update sudo apt-get install -y fdroidserver sshpass - name: Initialize or fetch F-Droid Repository env: HOST: ${{ secrets.HETZNER_HOST }} USER: ${{ secrets.HETZNER_USER }} PASS: ${{ secrets.HETZNER_PASS }} run: | mkdir -p fdroid cd fdroid # Try to download the existing repo/ folder from Hetzner to keep older versions and the keystore # If it fails (first time), we just initialize a new one sshpass -p "$PASS" scp -o StrictHostKeyChecking=no -r $USER@$HOST:dev/fdroid/repo . || fdroid init - name: Copy new APK to repo run: | # The app-release.apk name should ideally include the version number # so it doesn't overwrite older versions in the repo. VERSION_TAG=${GITHUB_REF#refs/tags/} # gets 'v1.0.0' cp build/app/outputs/flutter-apk/app-release.apk fdroid/repo/my_flutter_app_${VERSION_TAG}.apk - name: Generate F-Droid Index run: | cd fdroid fdroid update -c - name: Upload Repo to Hetzner env: HOST: ${{ secrets.HETZNER_HOST }} USER: ${{ secrets.HETZNER_USER }} PASS: ${{ secrets.HETZNER_PASS }} run: | # Use rsync to efficiently upload only the changed files (the new APK and updated index files) sshpass -p "$PASS" rsync -avz -e "ssh -o StrictHostKeyChecking=no" fdroid/repo/ $USER@$HOST:dev/fdroid/repo/