Skip to content

Commit

Permalink
update android.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
dzakdzaks committed Feb 26, 2023
1 parent 174dbf3 commit 1ca740e
Showing 1 changed file with 142 additions and 70 deletions.
212 changes: 142 additions & 70 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,160 @@
name: Android Build and Deployment Pipeline
name: Build # name of the workflow

on:
push:
branches:
- 'main'

workflow_dispatch:
inputs:
app_id:
description: 'The application Id of the current build'
required: true
branch:
description: 'The branch from which we have to build'
required: true

jobs:
build:
name: Setup Environment and build
push: # specifies events to trigger the workflow
branches: [ main ] # branches that trigger the workflow- SPECIFY YOUR BRANCH NAME

jobs: # groups the jobs to be executed in this workflow

build: # defines a job called build
name: 🔨 Build # [optional] name of the job
runs-on: ubuntu-latest # the job will be executed on ubuntu runner. Other include: Microsoft Windows & MacOS runners
steps: # groups together all the steps that run in build job

# Checks out code from the VCS to the runner
- name: Checkout code # [optional] specifies the name of the step
uses: actions/checkout@v2 # specifies which action and version to execute ie. checkout@v2

# Setup JDK Version 11 in the runner
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'

# Allow permissions to make gradle executable - This can removed by adding the gradlew file permission
# directly into the repository using `git update-index --chmod=+x gradlew`
# - name: Make gradle executable
# run: chmod +x ./gradlew

# Execute gradle build command with stacktrace flag
- name: Build with gradle
run: ./gradlew build --stacktrace # Execute gradle script to build project

lint-check: # defines another job called lint
name: 🔍 Lint
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Lint check
run: ./gradlew lint # Execute gradle script to perform lint check

- name: Generate lint report
uses: actions/upload-artifact@v2 # Uses upload-artifact@v2 action to upload lint report artifact
with: # Define extra parameters
name: lint_report.html # Name of the artifact to be uploaded
path: app/build/reports/lint-results-debug.html # Specifies the path where the artifact to be uploaded is located

unit-tests: #Defines another job called unit tests
name: 🧪 Unit Tests
needs: [ lint-check ] # This job's execution is dependant on whether `lint-check` job completes successfully
runs-on: ubuntu-latest
steps:
- name: Checkout the code to specific branch

- name: Checkout code
uses: actions/checkout@v2

- name: Execute unit tests
run: ./gradlew test --stacktrace # Execute gradle script to execute unit tests

- name: Generate test report
uses: actions/upload-artifact@v2
with:
ref: ${{ github.event.inputs.branch }}
name: unit_tests_report.html
path: app/build/reports/tests/testDebugUnitTest/

- name: Set up JDK
uses: actions/setup-java@v2



generate-apk: # Job to generate debug apk
name: ⚙️Generate APK
needs: [build, lint-check, unit-tests]
runs-on: ubuntu-latest
steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
distribution: 'zulu'
java-version: '11'

- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Build debug apk
run: ./gradlew assembleDebug --stacktrace

- uses: actions/cache@v2
- name: Upload debug apk
uses: actions/upload-artifact@v1
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Generate app bundle
run: ./gradlew app:bundleRelease --stacktrace

- name: Sign app bundle
run: |
jarsigner -keystore app/*.jks \
-storepass ${{ secrets.KEY_STORE_PASSWORD }} -keypass ${{ secrets.KEY_PASSWORD }} \
app/build/outputs/bundle/release/app-release.aab ${{ secrets.ALIAS }}
# STEP 2 : Upload the Artifact
upload:
needs: [ build ]
name: Upload the signed artifact
name: Android-CI-CD
path: app/build/outputs/apk/debug/app-debug.apk

create-release: # Job to create a new github release and upload the generated apk
name: 🎉 Create Release
needs: [ generate-apk ]
runs-on: ubuntu-latest
steps:
- name: Upload Bundle
uses: actions/upload-artifact@v2

- name: Download APK from build
uses: actions/download-artifact@v1
with:
name: Android-CI-CD

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}

- name: Upload Release APK
id: upload_release_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: signed_app_bundle
path: app/build/outputs/bundle/release/app-release.aab


# Step 3 : Release to playstore
deploy:
needs: [ build ]
name: Create release on Playstore
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Android-CI-CD/app-debug.apk
asset_name: Android-CI-CD.apk
asset_content_type: application/zip

# firebase-deploy:
# name: 📨 Deploy to Firebase App Distribution
# needs: [ generate-apk ]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Code
# uses: actions/checkout@v1
#
# - name: Download APK from build
# uses: actions/download-artifact@v1
# with:
# name: Android-CI-CD
#
# - name: Upload Artifact to Firebase App Distribution
# uses: wzieba/[email protected]
# with:
# appId: ${{secrets.FIREBASE_APP_ID}}
# token: ${{secrets.FIREBASE_TOKEN}}
# groups: testers
# file: Android-CI-CD/app-debug.apk

playstore-deploy:
name: 🚀 Deploy to Play Store
needs: [ generate-apk ]
runs-on: ubuntu-latest
steps:
- name: Create service_account.json
run: echo '${{ secrets.SERVICE_ACCOUNT_JSON }}' > service_account.json
- name: Checkout Code
uses: actions/checkout@v1

- name: Deploy to Play Store
uses: r0adkll/[email protected]
with:
serviceAccountJson: service_account.json
packageName: ${{ github.event.inputs.app_id }}
releaseFiles: app/build/outputs/bundle/release/*.aab
track: internal
whatsNewDirectory: whatsnew/
mappingFile: app/build/outputs/mapping/release/mapping.txt
inAppUpdatePriority: 5
send-message:
name: 📢 Send Message
needs: [ create-release, firebase-deploy, playstore-deploy ]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v1

0 comments on commit 1ca740e

Please sign in to comment.