|
| 1 | +name: Android Release to Firebase App Distribution |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + ## Required Inputs |
| 7 | + TEST_GRADLE_TASKS: |
| 8 | + description: "A Gradle task(s) for executing unit tests, for example `testReleaseUnitTest` or `testDevEnterpriseUnitTest`" |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + BUNDLE_GRADLE_TASK: |
| 12 | + description: "A Gradle task for assembling app bundle, for example `bundleEnterprise`" |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + UPLOAD_GRADLE_TASK: |
| 16 | + description: "A Gradle task for uploading APK, for example `appDistributionUploadEnterprise`" |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + SIGNING_KEYSTORE_PATH: |
| 20 | + description: "Path to keystore for signing of universal APK. Example: `keystore/debug.jks' or 'androidApp/signing/debug.keystore'." |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + APP_DISTRIBUTION_GROUPS: |
| 24 | + description: "Comma-separated list of app distribution group IDs" |
| 25 | + required: true |
| 26 | + type: string |
| 27 | + |
| 28 | + ## Optional Inputs |
| 29 | + VERSION_NAME: |
| 30 | + description: "Version name. Example: '1.X.X-snapshot'" |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + default: '1.X.X-snapshot' |
| 34 | + BUILD_NUMBER_OFFSET: |
| 35 | + description: "Build number offset. This number will be added to GITHUB_RUN_NUMBER and can be used to make corrections to build numbers." |
| 36 | + required: false |
| 37 | + type: number |
| 38 | + default: 0 |
| 39 | + KMP_FLAVOR: |
| 40 | + description: "KMP Build flavor. This is optional and only required by KMP projects and can be ignored on pure Android projects" |
| 41 | + required: false |
| 42 | + type: string |
| 43 | + default: 'test' |
| 44 | + SECRET_PROPERTIES_FILE: |
| 45 | + description: "A path to file that fill be populated with contents of 'SECRET_PROPERTIES' secret. This file can be picked up by Secrets Gradle plugin to embed secrets into BuildConfig." |
| 46 | + required: false |
| 47 | + type: string |
| 48 | + default: secrets.properties |
| 49 | + TIMEOUT_MINUTES: |
| 50 | + description: "Job timeout in minutes" |
| 51 | + required: false |
| 52 | + type: number |
| 53 | + default: 30 |
| 54 | + JAVA_VERSION: |
| 55 | + description: "Java version to use" |
| 56 | + required: false |
| 57 | + type: string |
| 58 | + default: '17' |
| 59 | + JAVA_DISTRIBUTION: |
| 60 | + description: "Java distribution to use" |
| 61 | + required: false |
| 62 | + type: string |
| 63 | + default: 'zulu' |
| 64 | + |
| 65 | + secrets: |
| 66 | + SIGNING_KEYSTORE_PASSWORD: |
| 67 | + description: "Password to provided keystore" |
| 68 | + required: true |
| 69 | + SIGNING_KEY_ALIAS: |
| 70 | + description: "Alias of the signing key in the provided keystore" |
| 71 | + required: true |
| 72 | + SIGNING_KEY_PASSWORD: |
| 73 | + description: "Password to the key in the provided keystore" |
| 74 | + required: true |
| 75 | + APP_DISTRIBUTION_SERVICE_ACCOUNT: |
| 76 | + required: true |
| 77 | + description: "JSON key of service account with permissions to upload build to Firebase App Distribution" |
| 78 | + SECRET_PROPERTIES: |
| 79 | + required: false |
| 80 | + description: "Custom string that contains key-value properties as secrets. Contents of this secret will be placed into file specified by 'SECRET_PROPERTIES_FILE' input." |
| 81 | + |
| 82 | +jobs: |
| 83 | + build: |
| 84 | + name: Enterprise Build |
| 85 | + runs-on: [ ubuntu-latest ] |
| 86 | + timeout-minutes: ${{ inputs.TIMEOUT_MINUTES }} |
| 87 | + env: |
| 88 | + FIREBASE_CREDENTIALS_FILE: firebase_credentials.json |
| 89 | + BUNDLETOOL_URL: https://github.com/google/bundletool/releases/download/1.17.2/bundletool-all-1.17.2.jar |
| 90 | + EXCLUDE_AAB_FILTER: .*intermediate |
| 91 | + steps: |
| 92 | + - name: Checkout |
| 93 | + uses: actions/checkout@v4 |
| 94 | + - name: Setup Java |
| 95 | + uses: actions/setup-java@v4 |
| 96 | + with: |
| 97 | + java-version: ${{ inputs.JAVA_VERSION }} |
| 98 | + distribution: ${{ inputs.JAVA_DISTRIBUTION }} |
| 99 | + - name: Setup Gradle |
| 100 | + uses: gradle/actions/setup-gradle@v4 |
| 101 | + - name: Prepare Environment |
| 102 | + run: | |
| 103 | + { |
| 104 | + echo "ANDROID_BUILD_NUMBER=$((GITHUB_RUN_NUMBER + ${{ inputs.BUILD_NUMBER_OFFSET}} ))"; |
| 105 | + echo "ANDROID_VERSION_NAME=${{ inputs.VERSION_NAME }}"; |
| 106 | + echo "KMP_FLAVOR=${{ inputs.KMP_FLAVOR }}" |
| 107 | + } >> "$GITHUB_ENV" |
| 108 | + |
| 109 | + echo '${{ secrets.SECRET_PROPERTIES }}' > ${{ inputs.SECRET_PROPERTIES_FILE }} |
| 110 | + echo '${{ secrets.APP_DISTRIBUTION_SERVICE_ACCOUNT }}' > "$FIREBASE_CREDENTIALS_FILE" |
| 111 | + - name: Run Unit tests |
| 112 | + shell: bash |
| 113 | + run: ./gradlew --continue ${{ inputs.TEST_GRADLE_TASKS }} |
| 114 | + - name: Generate Artifacts (AAB and APK) |
| 115 | + id: artifacts |
| 116 | + env: |
| 117 | + ANDROID_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }} |
| 118 | + ANDROID_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} |
| 119 | + ANDROID_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} |
| 120 | + shell: bash |
| 121 | + run: | |
| 122 | + ./gradlew ${{ inputs.BUNDLE_GRADLE_TASK }} -P buildkonfig.flavor="$KMP_FLAVOR" |
| 123 | + BUNDLE_FILE=$(find . -name '*.aab' | grep -v '.*intermediate') |
| 124 | + |
| 125 | + wget -O bundletool.jar ${{ env.BUNDLETOOL_URL }} |
| 126 | + java -jar bundletool.jar build-apks \ |
| 127 | + --bundle "$BUNDLE_FILE" \ |
| 128 | + --output universal.apks \ |
| 129 | + --mode universal \ |
| 130 | + --ks ${{ inputs.SIGNING_KEYSTORE_PATH }} \ |
| 131 | + --ks-pass pass:${{ secrets.SIGNING_KEYSTORE_PASSWORD }} \ |
| 132 | + --ks-key-alias ${{ secrets.SIGNING_KEY_ALIAS }} \ |
| 133 | + --key-pass pass:${{ secrets.SIGNING_KEY_PASSWORD }} |
| 134 | + unzip universal.apks -d universal_apk |
| 135 | + UNIVERSAL_APK_FILE=$(find universal_apk/ -name '*.apk') |
| 136 | + |
| 137 | + echo "bundle_file=$BUNDLE_FILE" >> "$GITHUB_OUTPUT" |
| 138 | + echo "universal_apk_file=$UNIVERSAL_APK_FILE" >> "$GITHUB_OUTPUT" |
| 139 | + - name: Upload to Firebase App Distribution |
| 140 | + shell: bash |
| 141 | + run: | |
| 142 | + ./gradlew ${{ inputs.UPLOAD_GRADLE_TASK }} \ |
| 143 | + --serviceCredentialsFile="$FIREBASE_CREDENTIALS_FILE" \ |
| 144 | + --groups="${{ inputs.APP_DISTRIBUTION_GROUPS }}" \ |
| 145 | + --artifactType="APK" \ |
| 146 | + --artifactPath="${{ steps.artifacts.outputs.universal_apk_file }}" |
0 commit comments