|
| 1 | +name: Android Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master, main, feat/capacitor-integration] |
| 6 | + pull_request: |
| 7 | + branches: [master, main] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-android: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Setup Bun |
| 24 | + uses: oven-sh/setup-bun@v1 |
| 25 | + with: |
| 26 | + bun-version: latest |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: bun install |
| 30 | + |
| 31 | + - name: Create placeholder build directory for Capacitor sync |
| 32 | + run: mkdir -p build |
| 33 | + |
| 34 | + - name: Setup Java |
| 35 | + uses: actions/setup-java@v4 |
| 36 | + with: |
| 37 | + java-version: '21' |
| 38 | + distribution: 'temurin' |
| 39 | + |
| 40 | + - name: Setup Android SDK |
| 41 | + uses: android-actions/setup-android@v3 |
| 42 | + |
| 43 | + - name: Install Android SDK build tools & platform |
| 44 | + run: | |
| 45 | + yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses |
| 46 | + $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \ |
| 47 | + "platforms;android-36" \ |
| 48 | + "build-tools;36.0.0" \ |
| 49 | + "platform-tools" |
| 50 | +
|
| 51 | + - name: Sync Capacitor with web build |
| 52 | + run: npx cap sync |
| 53 | + |
| 54 | + - name: Build Android APK (debug) |
| 55 | + run: | |
| 56 | + cd android |
| 57 | + chmod +x gradlew |
| 58 | + ./gradlew assembleDebug |
| 59 | +
|
| 60 | + - name: Extract version from build.gradle |
| 61 | + id: version |
| 62 | + run: | |
| 63 | + VERSION_NAME=$(grep versionName android/app/build.gradle | awk '{print $2}' | tr -d '"') |
| 64 | + VERSION_CODE=$(grep versionCode android/app/build.gradle | awk '{print $2}') |
| 65 | + echo "version_name=$VERSION_NAME" >> "$GITHUB_OUTPUT" |
| 66 | + echo "version_code=$VERSION_CODE" >> "$GITHUB_OUTPUT" |
| 67 | + echo "App version: $VERSION_NAME (code $VERSION_CODE)" |
| 68 | +
|
| 69 | + - name: Rename APK |
| 70 | + run: | |
| 71 | + VERSION="${{ steps.version.outputs.version_name }}" |
| 72 | + mkdir -p android/app/build/outputs/apk/debug |
| 73 | + if [ -f android/app/build/outputs/apk/debug/app-debug.apk ]; then |
| 74 | + mv android/app/build/outputs/apk/debug/app-debug.apk \ |
| 75 | + "android/app/build/outputs/apk/debug/Svelte-MiniApps-v${VERSION}-debug.apk" |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Upload APK artifact |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: Svelte-MiniApps-v${{ steps.version.outputs.version_name }}-debug |
| 82 | + path: android/app/build/outputs/apk/debug/Svelte-MiniApps-*.apk |
| 83 | + if-no-files-found: error |
| 84 | + retention-days: 14 |
| 85 | + |
| 86 | + - name: Create GitHub Release |
| 87 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ github.token }} |
| 90 | + run: | |
| 91 | + VERSION="${{ steps.version.outputs.version_name }}" |
| 92 | + TAG="v${VERSION}-b${GITHUB_RUN_NUMBER}" |
| 93 | + APK_PATH="android/app/build/outputs/apk/debug/Svelte-MiniApps-v${VERSION}-debug.apk" |
| 94 | +
|
| 95 | + echo "Creating release: $TAG" |
| 96 | +
|
| 97 | + # Create or update the release |
| 98 | + if gh release view "$TAG" --json name &>/dev/null; then |
| 99 | + echo "Release $TAG exists — uploading asset" |
| 100 | + gh release upload "$TAG" "$APK_PATH" --clobber |
| 101 | + else |
| 102 | + echo "Creating new release $TAG" |
| 103 | + gh release create "$TAG" \ |
| 104 | + --title "Svelte MiniApps v${VERSION}" \ |
| 105 | + --notes "Automated Android debug build from commit ${GITHUB_SHA:0:7}" \ |
| 106 | + --generate-notes \ |
| 107 | + "$APK_PATH" |
| 108 | + fi |
0 commit comments