Dear Developers, In this article I will show you how to automate the test execution and build of your Android application while using the new github feature : “GitHubAction”
But first, we need to know what is “continuous integration”, “continuous deployment”, and “GitHub Actions”.
Certainly, you’ve heard about ongoing integration and deployment. These are two “functionalities” that relate to a broader subject which is DevOps.
According to Wikipedia, Continuous integration, also known as CI, is “a set of practices used in software engineering that consists of checking every time the source code is modified that the result of the modifications does not produce a regression in the developed application. The concept was first mentioned by Grady Booch1 and generally refers to the practice of extreme programming. The main goal of this practice is to detect integration problems as early as possible in the development process. In addition, it allows to automate the execution of the test suites and to see the evolution of the software development”.
The following figure summarizes the functionality of continuous integration.
In contrast, continuous deployment, or CD is “a software development strategy where any code validation that passes the automated test cycle is automatically transferred to the production environment, thus propelling the changes to the software users”. According to LeMagIT.
Therefore, CI/CDs essentially help to realize the project faster by automating the “build”, the test and the “release”. This is shown in the figure below.
And in order for developers to automate all this, they often use tools such as Jenkins, Travis CI, CircleCI… And lately, the newest addition to GitHub is called GitHub Actions.
GitHub Actions
It can be presented as the Oreo production plant, where there is an assembly line that goes through several machines creating the biscuits, adding chocolate, cream… in order to have the packet well wrapped with Oreo pieces. In our case, and for an Android project, chocolate and cream are the test and build. And the packaged cookie is the deliverable which is the APK file.
So let’s get to work. And of course, you need to have an account on GitHub.
After choosing your repo on GitHub, click on the Actions menu at the top.
GitHub Actions gives you the ability to easily install CI/CD on your project, so it creates you the file “.github/workflows/android.yml”
As mentioned in the android.yml file, at each “push”, GitHub Actions automatically starts building your project using the latest version of ubuntu. We’re going to modify this file to automate the unit tests and the generation of an APK for each push on the repo.
Unit tests
The following piece of code will launch at each push on the master branch, the unit tests with the command “bash ./gradlew test — stacktrace”
name: Android CI/CDon: push: branches: - 'master'jobs: test: name: Run Unit Tests runs-on: ubuntu-latest steps: - uses: actions/[email protected] - name: set up JDK 1.8 uses: actions/[email protected] with: java-version: 1.8 - name: Unit tests run: bash ./gradlew test --stacktrace
The APK generation
We have finished with the unit tests, and we are now approaching the generation of the deliverable for an Android project, the APK. We add in the jobs section the following code, which generates the APK file “app-debug.apk” and places it in “app/build/outputs/apk/debug”. And just like the unit tests, this processing is done on the latest version of ubuntu and using Java 8.
Nous utilisons des cookies pour vous garantir la meilleure expérience sur notre site web. Si vous continuez à utiliser ce site, nous supposerons que vous en êtes satisfait.Ok