Merge pull request #223 from Hepolise/dependabot/gradle/main/gradle-w… #537
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 Release App Bundle | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| build-type: | |
| type: choice | |
| description: Build Type | |
| options: | |
| - debug | |
| - release | |
| workflow_call: | |
| inputs: | |
| build-type: | |
| required: false | |
| type: string | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| - dev | |
| - test | |
| env: | |
| BUILD_TYPE: ${{ inputs.build-type || 'debug' }} | |
| APK_DIR: app/build/outputs/apk | |
| APK_NAME: VolumeKeyTrackControlModule | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Cache Gradle files | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| gradle-${{ runner.os }}- | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Generate version | |
| run: ./gradlew getVersion | |
| - name: Set environment variables | |
| run: | | |
| echo "VERSION=$(cat app/build/version.txt)" >> $GITHUB_ENV | |
| if [[ "${{ env.BUILD_TYPE }}" == 'debug' ]]; then | |
| echo "ASSEMBLE_TYPE=assembleDebug" >> "$GITHUB_ENV" | |
| else | |
| echo "ASSEMBLE_TYPE=assembleRelease" >> "$GITHUB_ENV" | |
| fi | |
| if [[ -n "${{ secrets.KEYSTORE }}" ]]; then | |
| echo "SIGNING_ENABLED=true" >> "$GITHUB_ENV" | |
| else | |
| echo "SIGNING_ENABLED=false" >> "$GITHUB_ENV" | |
| fi | |
| - name: Print env variables | |
| run: | | |
| echo 'BUILD_TYPE: ${{ env.BUILD_TYPE }}' | |
| echo 'ASSEMBLE_TYPE: ${{ env.ASSEMBLE_TYPE }}' | |
| echo 'VERSION: ${{ env.VERSION }}' | |
| echo 'SIGNING_ENABLED: ${{ env.SIGNING_ENABLED }}' | |
| - name: Build APK | |
| run: ./gradlew app:${{ env.ASSEMBLE_TYPE }} --build-cache | |
| - name: Rename release apk | |
| if: ${{ env.BUILD_TYPE == 'release' }} | |
| run: mv ${{ env.APK_DIR }}/${{ env.BUILD_TYPE }}/app-release-unsigned.apk ${{ env.APK_DIR }}/${{ env.BUILD_TYPE }}/app-${{ env.BUILD_TYPE }}.apk | |
| - name: Sign app APK | |
| if: env.SIGNING_ENABLED == 'true' | |
| uses: kevin-david/zipalign-sign-android-release@main | |
| id: sign_app | |
| with: | |
| releaseDirectory: ${{ env.APK_DIR }}/${{ env.BUILD_TYPE }} | |
| signingKeyBase64: ${{ secrets.KEYSTORE }} | |
| alias: ${{ secrets.KEY_ALIAS }} | |
| keyStorePassword: ${{ secrets.KEYSTORE_PASSWORD }} | |
| keyPassword: ${{ secrets.KEY_PASSWORD }} | |
| - name: Rename | |
| run: | | |
| APK_DIR="${{ env.APK_DIR }}/${{ env.BUILD_TYPE }}" | |
| if [ -f "$APK_DIR/app-${{ env.BUILD_TYPE }}-signed.apk" ]; then | |
| mv "$APK_DIR/app-${{ env.BUILD_TYPE }}-signed.apk" "${{ env.APK_NAME }}-${{ env.BUILD_TYPE }}-${{ env.VERSION }}.apk" | |
| else | |
| mv "$APK_DIR/app-${{ env.BUILD_TYPE }}.apk" "${{ env.APK_NAME }}-${{ env.BUILD_TYPE }}-${{ env.VERSION }}.apk" | |
| fi | |
| - name: Upload | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: Build Artifacts | |
| path: ${{ env.APK_NAME }}-${{ env.BUILD_TYPE }}-${{ env.VERSION }}.apk |