workflow improvement #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build APK | |
| on: | |
| push: | |
| branches: [main, master] | |
| tags: ['v*'] | |
| pull_request: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| inputs: | |
| build_type: | |
| description: 'Build type' | |
| required: true | |
| default: 'debug' | |
| type: choice | |
| options: | |
| - debug | |
| - release | |
| - both | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| # ── Debug build ────────────────────────────────────────────────── | |
| - name: Build debug APK | |
| if: github.event_name != 'workflow_dispatch' || github.event.inputs.build_type == 'debug' || github.event.inputs.build_type == 'both' | |
| run: ./gradlew assembleDebug --no-daemon | |
| - name: Upload debug APK | |
| if: github.event_name != 'workflow_dispatch' || github.event.inputs.build_type == 'debug' || github.event.inputs.build_type == 'both' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-debug | |
| path: app/build/outputs/apk/debug/app-debug.apk | |
| # ── Release build (tags or manual trigger, signed if secrets configured) ──── | |
| - name: Decode keystore | |
| if: (startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_type == 'release' || github.event.inputs.build_type == 'both') && env.KEYSTORE_BASE64 != '' | |
| env: | |
| KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
| run: echo "$KEYSTORE_BASE64" | base64 -d > release.keystore | |
| - name: Create keystore.properties | |
| if: (startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_type == 'release' || github.event.inputs.build_type == 'both') && env.KEYSTORE_BASE64 != '' | |
| env: | |
| KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
| KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
| KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
| KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| run: | | |
| cat > keystore.properties <<EOF | |
| storeFile=release.keystore | |
| storePassword=$KEYSTORE_PASSWORD | |
| keyAlias=$KEY_ALIAS | |
| keyPassword=$KEY_PASSWORD | |
| EOF | |
| - name: Build release APK | |
| if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_type == 'release' || github.event.inputs.build_type == 'both' | |
| run: ./gradlew assembleRelease --no-daemon | |
| - name: Upload release APK | |
| if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_type == 'release' || github.event.inputs.build_type == 'both' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-release-unsigned | |
| path: app/build/outputs/apk/release/app-release-unsigned.apk | |
| - name: Upload signed release APK | |
| if: (startsWith(github.ref, 'refs/tags/v') || github.event.inputs.build_type == 'release' || github.event.inputs.build_type == 'both') && env.KEYSTORE_BASE64 != '' | |
| env: | |
| KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-release-signed | |
| path: app/build/outputs/apk/release/app-release.apk |