CI-CD pipeline for Android via Github workflow
Continuous Integration/Continuous Delivery Automates building operations in order to bridge the gap between development and operations
It’s sometimes necessary to provide an Android APK to a client or to another team member, for example, the QA team. APKs are created, and then you upload some cloud services in order to download others.
Your plan to provide just an APK appears to be a long task. Wouldn’t it be great if it happened automatically?
The following is a method for creating a pipeline in which GitHub builds an APK when your code is pushed to your branch.
For more about Github workflow actions.
Step One: create a folder and YAML file
- In the Root folder of your project — create a .github folder
- As well as create another folder inside workflows
- Inside the workflows folder — create an app-job-on-push.yaml file
Step Two: write an action to perform an operation for creating a build of your project.
Here branches: will be your branch name (main, master), and based on the java version you have to set java-version as well.
name: android-paging-coroutine
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew build
- name: Build APK
run: ./gradlew :app:assembleDebug
- uses: actions/upload-artifact@v2
with:
name: Package
path: app/build/outputs/apk/debug/
Step Three: execution permission — before pushing code to your branch
You need to update the execution permission for gradlew file.
- You can do this by using Git Bash or Terminal, CMD as well.
Locally: chmod +x gradlew
Git:
git update-index --chmod=+x gradlew
git add .
git commit -m "Changing permission of gradlew"
git pushYou should see:
mode change 100644 => 100755 gradlew
2. When you push your code to the branch, you will see the workflow run actions as shown below
The workflow will automatically build the project and produce an output artifact package that contains APK files.
Once the job is completed, you will be able to download your package.
Those who need the APK can now access just that workflow package link.
BUT — this will create a build every time when you push your code to a branch.
Alternatively — we can give a manual action as well. that will allow us to build APKs whenever we want.
- To accomplish this, you must create a manual job in your YAML file as follows, which will dispatch your workflow when you manually run it.
name: android-paging-coroutine
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch'
required: true
default: 'master'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: "${{ github.event.inputs.branch }}"
submodules: 'true'
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew build
- name: Build APK
run: ./gradlew :app:assembleDebug
- uses: actions/upload-artifact@v2
with:
name: Package
path: app/build/outputs/apk/debug/
#path: app/build/outputs/
#path: [MODULE]/build/outputs/
retention-days: 2
Retention-days will delete your build in the numbers of the days you set
→ Once you have pushed to the branch, find the action tab. There will be another workflow that will not run unless it is manually started by you.
Hope you find it usefull 🤝