Last active
June 16, 2023 05:22
-
-
Save bastionkid/028cf0e7390f45d37a7a979aaa32eb56 to your computer and use it in GitHub Desktop.
Size Metrics workflow with only build job
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: Size Metrics | |
| # cancel in-progress workflow if new commits are pushed to same head branch | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | |
| cancel-in-progress: true | |
| on: | |
| pull_request: | |
| branches: [ "master", "main", "release/*", "feature/*" ] | |
| jobs: | |
| build: | |
| name: Build apk | |
| runs-on: ubuntu-latest | |
| outputs: | |
| base_short_sha: ${{ steps.base-short-sha.outputs.base_short_sha }} | |
| head_short_sha: ${{ steps.head-short-sha.outputs.head_short_sha }} | |
| steps: | |
| # Step 1 | |
| - name: Checkout base (PR target) branch | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.base_ref }} | |
| # Step 2 | |
| # this step is optional if you don't use JDK 17 as ubuntu-latest runner already | |
| # has java setup which defaults to JDK 11 | |
| - name: Setup Java | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| # Step 3 | |
| # this step is optional and should be added in case you get "Failed to install the following | |
| # Android SDK packages as some licences have not been accepted" error | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v2 | |
| # Step 4 | |
| # setup cache so that every build trigger doesn't require downloading all the | |
| # dependencies used in project again and again saving tonnes of time | |
| - name: Setup Gradle & Android SDK Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| /usr/local/lib/android/sdk/build-tools | |
| /usr/local/lib/android/sdk/system-images | |
| key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} | |
| # Step 5 | |
| - name: Generate shorter github.sha for base branch | |
| id: base-short-sha | |
| run: | | |
| chmod +x ./.github/scripts/commit_short_sha.sh | |
| short_sha=$(./.github/scripts/commit_short_sha.sh) | |
| echo "base_short_sha=${short_sha}" >> "$GITHUB_ENV" | |
| echo "base_short_sha=${short_sha}" >> "$GITHUB_OUTPUT" | |
| # Step 6 | |
| - name: Build release APK for base branch and rename it to match base-short-sha result | |
| run: | | |
| ./gradlew assembleRelease -PtargetDensity=xxhdpi -PtargetAbi=arm64-v8a -PresConfig=en -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile | |
| mv app/build/outputs/apk/release/app-xxhdpiArm64-v8a-release-unsigned.apk app/build/outputs/apk/release/${{ env.base_short_sha }}.apk | |
| # Step 7 | |
| - name: Upload APK | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: ${{ env.base_short_sha }}.apk | |
| path: app/build/outputs/apk/release/${{ env.base_short_sha }}.apk | |
| # Step 8 | |
| - name: Checkout head branch | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| # Step 9 | |
| - name: Generate shorter github.sha for head branch | |
| id: head-short-sha | |
| run: | | |
| chmod +x ./.github/scripts/commit_short_sha.sh | |
| short_sha=$(./.github/scripts/commit_short_sha.sh) | |
| echo "head_short_sha=${short_sha}" >> "$GITHUB_ENV" | |
| echo "head_short_sha=${short_sha}" >> "$GITHUB_OUTPUT" | |
| # Step 10 | |
| - name: Merge base (PR target) branch | |
| run: | | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "Akash Khunt" | |
| git merge origin/${{ github.base_ref }} | |
| # Step 11 | |
| - name: Build release APK for head branch and rename it to match head-short-sha result | |
| run: | | |
| ./gradlew assembleRelease -PtargetDensity=xxhdpi -PtargetAbi=arm64-v8a -PresConfig=en -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile | |
| mv app/build/outputs/apk/release/app-xxhdpiArm64-v8a-release-unsigned.apk app/build/outputs/apk/release/${{ env.head_short_sha }}.apk | |
| # Step 12 | |
| - name: Upload APK | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: ${{ env.head_short_sha }}.apk | |
| path: app/build/outputs/apk/release/${{ env.head_short_sha }}.apk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment