From 46fd6458977c7cfc3cfaa22b01472b835f179e73 Mon Sep 17 00:00:00 2001 From: adityankannan-tw <109274996+adityankannan-tw@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:21:44 +0530 Subject: [PATCH] Add a job to upload apk to Github Actions (#836) * feat(INJI-333): Add a job to upload apk to Github actions in internal build * fix(INJI-333): Add a job to upload to Github actions --- .github/workflows/android-internal-build.yml | 108 +++++++++++++++++-- android/app/build.gradle | 4 +- 2 files changed, 103 insertions(+), 9 deletions(-) diff --git a/.github/workflows/android-internal-build.yml b/.github/workflows/android-internal-build.yml index aafb3ce8..bbf90619 100644 --- a/.github/workflows/android-internal-build.yml +++ b/.github/workflows/android-internal-build.yml @@ -1,4 +1,5 @@ name: Android Internal Build +run-name: ${{ github.event.inputs.buildname }} env: mimotoBackendServiceDefaultUrl: https://api.sandbox.mosip.net @@ -7,6 +8,11 @@ env: on: workflow_dispatch: inputs: + buildname: + description: 'Build App For' + required: true + default: 'Sprint-x/Collab/release-x.x.x' + type: string mimotoBackendServiceUrl: description: 'Mimoto backend service URL' required: true @@ -47,7 +53,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: '16.x' - + - name: Cache local npm repository uses: actions/cache@v3.0.11 with: @@ -74,7 +80,7 @@ jobs: run: | # Strip git ref prefix from version echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV + echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - name: Setup branch and GPG public key run: | @@ -105,11 +111,11 @@ jobs: cd android/app export RELEASE_KEYSTORE_ALIAS=androidreleasekey export RELEASE_KEYSTORE_PASSWORD=$RELEASE_KEYSTORE_PASSWORD - env: + env: RELEASE_KEYSTORE_PASSWORD: '${{secrets.INJI_ANDROID_RELEASE_STOREPASS}}' - name: Create Google Play Config file - run : | + run: | cd android echo "$INJI_ANDROID_PLAY_STORE_CONFIG_JSON" > play_config.json.b64 base64 -d -i play_config.json.b64 > play_config.json @@ -117,15 +123,103 @@ jobs: INJI_ANDROID_PLAY_STORE_CONFIG_JSON: ${{ secrets.INJI_ANDROID_PLAY_STORE_CONFIG_JSON }} - name: Run Build - run: | + run: | cd android/scripts ./internal-build.sh env: MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} - APPLICATION_THEME: ${{ github.event.inputs.theme }} + APPLICATION_THEME: ${{ github.event.inputs.theme }} RELEASE_KEYSTORE_ALIAS: androidreleasekey RELEASE_KEYSTORE_PASSWORD: '${{secrets.INJI_ANDROID_RELEASE_STOREPASS}}' SLACK_URL: '${{ secrets.SLACK_WEBHOOK_DEVOPS }}' PLAY_CONSOLE_RELEASE_DESCRIPTION: ${{ github.event.inputs.buildDescription }} - CREDENTIAL_REGISTRY_EDIT: ${{ github.event.inputs.registry_edit }} \ No newline at end of file + CREDENTIAL_REGISTRY_EDIT: ${{ github.event.inputs.registry_edit }} + + upload-to-actions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.1.0 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + + - name: Cache local npm repository + uses: actions/cache@v3.0.11 + with: + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + path: ~/.npm + + - name: Cache local gradle repository + uses: actions/cache@v3.0.11 + with: + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + path: | + ~/.gradle/caches + ~/.gradle/wrapper + + - name: Install npm dependencies + run: | + npm i + + - name: Create .env.local file + run: | + echo "${{ secrets.ENV_FILE }}" > .env.local > android/local.properties + + - name: Setup branch and env + run: | + # Strip git ref prefix from version + echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV + echo "GPG_TTY=$(tty)" >> $GITHUB_ENV + + - name: Setup branch and GPG public key + run: | + # Strip git ref prefix from version + echo ${{ env.BRANCH_NAME }} + echo ${{ env.GPG_TTY }} + + sudo apt-get --yes install gnupg2 + gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg + gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg + + - name: Setup Firebase + run: | + cd android + if [ ! -z "$FIREBASE_SECRET" ] && [ -f app/google-services.json.gpg ];then rm -f app/google-services.json;gpg2 --quiet --batch --passphrase=$FIREBASE_SECRET --pinentry-mode loopback --decrypt --output app/google-services.json app/mosip-google-services.json.gpg;fi + env: + FIREBASE_SECRET: ${{ secrets.GPG_SECRET }} + + - name: Generate keystore + run: | + echo "$ANDROID_KEYSTORE_FILE" > release.keystore.b64 + base64 -d -i release.keystore.b64 > android/app/release.keystore + env: + ANDROID_KEYSTORE_FILE: ${{ secrets.INJI_ANDROID_RELEASE_KEYSTORE }} + + - name: Create Google Play Config file + run: | + cd android + echo "$INJI_ANDROID_PLAY_STORE_CONFIG_JSON" > play_config.json.b64 + base64 -d -i play_config.json.b64 > play_config.json + env: + INJI_ANDROID_PLAY_STORE_CONFIG_JSON: ${{ secrets.INJI_ANDROID_PLAY_STORE_CONFIG_JSON }} + + - name: Run Build for upload + run: | + npx jetify + cd android + ./gradlew :app:assembleMosipRelease + env: + MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} + ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} + APPLICATION_THEME: ${{ github.event.inputs.theme }} + RELEASE_KEYSTORE_ALIAS: androidreleasekey + RELEASE_KEYSTORE_PASSWORD: '${{secrets.INJI_ANDROID_RELEASE_STOREPASS}}' + CREDENTIAL_REGISTRY_EDIT: ${{ github.event.inputs.registry_edit }} + + - name: Upload Artifact + uses: actions/upload-artifact@v3.1.1 + with: + name: ${{ github.event.inputs.buildname }} + path: android/app/build/outputs/apk/mosip/release/ + retention-days: 10 diff --git a/android/app/build.gradle b/android/app/build.gradle index 377bf9d8..a4d620c6 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -90,7 +90,7 @@ def reactNativeArchitectures() { androidGitVersion { baseCode 0 codeFormat 'MXXNXXPXX' - format '% tag %%commit_%%branch%' + format '%tag_%%commit_%%branch%' } android { @@ -197,7 +197,7 @@ android { variant.outputs.all { output -> def datetime = new Date().format('yyyyMMdd_HHmm') def architecture = output.getFilter(com.android.build.OutputFile.ABI) ?: "universal" - outputFileName = "${defaultConfig.applicationId}-${variant.versionName}_${datetime}_${architecture}.apk" + outputFileName = "Inji_${variant.versionName}_${datetime}_${architecture}.apk" } } }