Skip to content

Instantly share code, notes, and snippets.

@aiyu-ayaan
Created February 17, 2023 12:13
Show Gist options
  • Save aiyu-ayaan/80d8b415b8d3cf44621265cc8759e603 to your computer and use it in GitHub Desktop.
Save aiyu-ayaan/80d8b415b8d3cf44621265cc8759e603 to your computer and use it in GitHub Desktop.
Make Release Build Using GitHub Action

Steps

1. The first step includes decoding the Key

openssl base64 < Keys.jks | tr -d 'n' | tee signing.txt

Note commands only works on Linux/MacOs if you have windows use Git bash.

After you run this command as a result it will give a text file which includes a encripted version of for keys.

2. Adding Secrets

  • Navigate to your repo settings -> Secrets and Variables -> Action

  • Add this content of txt file into github secrets. Here is the example image

  • Then Provide the details for the key in 3 more variable include Store's Password,ALias,ALias's Password.Here is the example image

  • After these step, the page should look like this :- image

3. Create a director in your projects root directory :-

.github/workflows/Build & Release.yml

name: Build and Release 🚀

on:
  push:
    branches:
      - master
    tags:
        - v*
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # Step 1: Decode Keystore
      - name: Decode Keystore
        id: decode_keystore
        uses: timheuer/base64-to-file@v1
        with:
          fileName: 'keystore/keystore.jks'
          encodedString: ${{ secrets.KEYSTORE }}

      # Step 2: Checkout the repository
      - uses: actions/checkout@v2

      # Step 3: Set up JDK 11
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
          distribution: 'temurin'
          cache: gradle

     # Step 4: Add Keystore to Project
      - name: Copy Keystore to Project
        run: |
          mkdir -p ./app/keystore
          cp ${{ steps.decode_keystore.outputs.filePath }} './app/keystore/keystore.jks'
          echo ${{ steps.decode_keystore.outputs.filePath }}
          ls -la ./app

      # Step 5: Make gradlew executable
      - name: Make gradlew executable
        run: chmod +x ./gradlew

      # Step 6: Build Release APK
      - name: Build Release APK
        run: ./gradlew :app:assembleRelease --stacktrace :app:bundleRelease --stacktrace
        env:
          SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
          SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
          SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}

      # Step 7: Upload APK and AAB artifacts
      - name: Upload APK
        uses: actions/upload-artifact@v2
        with:
          name: apk
          path: app/build/outputs/apk/release/app-release.apk
      - name: Upload AAB
        uses: actions/upload-artifact@v2
        with:
          name: aab
          path: app/build/outputs/bundle/release/app-release.aab

Here's an overview of the changes I made to your workflow file:

  • In the on section, the workflow is triggered when a tag matching the pattern v* is pushed to the repository or when a commit is pushed to the master branch.

  • The build job runs on an ubuntu-latest runner.

  • In Copy Keystore to Project step, I added a ls -la ./app command to list the contents of the app directory.

  • In the steps section, I added a comment for each step to explain what it does.

  • The Build Release APK and Build Release AAB steps build the APK and AAB artifacts.

  • The Upload APK and Upload AAB steps upload the APK and AAB artifacts to the workflow run, which can be used in later steps or downloaded from the GitHub Actions UI.

4. After doing all the above steps the last step include some changes on app level build.gradle file.

signingConfigs {
        release {
            storeFile file('keystore/keystore.jks')
            storePassword System.getenv("SIGNING_STORE_PASSWORD")
            keyAlias System.getenv("SIGNING_KEY_ALIAS")
            keyPassword System.getenv("SIGNING_KEY_PASSWORD")
        }
    }

Than assign this config to release block

buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

5. After pushing code to github, Action will trigger which will trigger your action.

image

And file should apper at the bottom of that page image

Here is the repo-link used in this project

If you just change your root project name to some other name you can check out my BIT-App which include multimodule setup and different root module name..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment