In the story we will see how to create a workflow for Android Lint using GitHub Actions.
Before moving to the workflow I want to quickly go over GitHub Actions and Android Lint.
During Android or any development you might have come across different CI/CD frameworks that you can use to automate the processes or delivery pipelines e.g build, test and distribute. GitHub Actions provides a convenient way to create your workflows and automate your process right from your repository.
Some of the benefits that I see while working in GitHub Actions
- Github Actions are attached to your repository in Github, you don’t need to manage an extra third party platform to build and manage your CI/CD. Your code is in GitHub, your CI/CD is in GitHub.
- Github Actions give more controls to developers minimising the need of having a separate DevOps team to manage CI/CD.
- While creating workflows using GitHub Actions, It provides startup workflows to choose from for quick start, e.g for Android there is
Android CIworkflow already provided for quick help.
- Github Marketplace where almost 20K actions are already available to use which you can choose and Add/Modify into your repository right away.
- Github Actions are customisable you can achieve almost everything you want to automate.
To Read more about Github Actions, follow the the official documentations from the link.
We write and build
Tests to make sure functional requirements are met properly but It’s also equally important to inspect your code to identify structural problems in the code.
lint tool helps in identifying structural and static issues in the code which can impact efficiency and reliability of the code and possible optimisation to improve code security, correctness, performance, usability etc
Android Studio provides a built-in
lint tool which runs when you build your App but you can also manually execute it using
Code —> Inspect Code option in Android Studio or also using command line
./gradlew lint .
lint tool runs, it checks the source code against
lint.xml file available in the root folder of the project. If
lint.xml does not exist then all lint supported issues are checked. We provide
lint.xml files mentioning issues which we want
lint tool to ignore or customise
lint checks for certain issues.
You can add annotations in the code to notify
lint to check such rules during
lint inspection. e.g such annotations are
How to add
annotations and what different kinds of annotations are? You can see official documentations Improve code inspection using annotations.
Overview of how
lint processes source code.
Image Source: official documentation Improve your code with lint checks
Why should we create workflow for Android Lint?
As the team grows or we have multiple teams managing the same codebase e.g feature teams, core team etc, maintaining code quality gets complex.
If we don’t have
workflows and everyone is self responsible for running and fixing Android Lint individually or any other static analyser then things might get skip on day to day basis due to priorities or other related dependencies or human error or some other reason etc
When code is committed to the repository you can write a
workflow which will run on every commit, enabling continuous integration to build and test the code making sure it does not break anything and does not introduce new errors. You can write multiple
workflows for different cases e.g one for build and test, the other for deployment, the other for Android lint checks etc.
workflows enables Continuous Integrations(CI) where everyone can commit frequently to the shared repository as the code will get checked on every commit (or as per need) ensuring code quality, also it makes easier to merge changes, enabling members of the team to focus more on writing code rather than fixing merge conflicts or debugging errors etc.
Below we will see how to create a workflow for Android Lint using Github Actions.
Android Lint workflow using Github Actions
workflow which will run
lint code inspector on every pull request created on
main branch and when code is pushed to
.github folder and then
workflows folder inside like that
We write Github workflows in
yml file, creating an empty
android-lint.yml file inside
Then set the name of the
workflow as below.
We want to run
workflow when code is
pushed or a
pull request is created from
It defines a job named
android-lint and configures it to run on
ubuntu-latest, that means it will run on linux runner hosted by Github.
Next to create steps inside the job, first we have to checkout the code using Github action
actions/checkout@v3 as below.
It will run Android Linter as soon as we create a pull request for
main branch or when code is pushed to
android-lint.yml file is below.
|name: Android Lint
|run-name: Running Android Lint
|- uses: actions/checkout@v3
|- name: set up JDK 17
|- name: Run Lint
|run: ./gradlew lint