Reader small image

You're reading from  Mastering Kotlin for Android 14

Product typeBook
Published inApr 2024
Reading LevelIntermediate
PublisherPackt
ISBN-139781837631711
Edition1st Edition
Languages
Right arrow
Author (1)
Harun Wangereka
Harun Wangereka
author image
Harun Wangereka

Harun Wangereka is a Google Developer Expert for Android and an Android engineer with over seven years of experience and currently working at Apollo Agriculture. Harun is passionate about Android development, never tired of learning, building the tech community, and helping other developers upscale their skills. He is a co-organizer at Droidcon Kenya and a former Kotlin Kenya and Android254 co-organizer. Through these communities, he has been able to impact thousands of developers. He is also an Android author at Kodeco where he has written 8 articles, published a book; Saving Data on Android, Second Edition, and is also a video course instructor. He has given numerous sessions on Android and Kotlin across different communities worldwide.
Read more about Harun Wangereka

Right arrow

Continuous Integration and Continuous Deployment

After we complete the development and first deployment of our app, we must think of how to make the process smoother for consecutive deployments, and that’s where Continuous integration/Continuous delivery (CI/CD) comes in.

In this chapter, we will learn how to use GitHub Actions to automate some of the manual tasks, such as deploying new builds to the Google Play Store. We will learn how to run tests on CI/CD pipelines and push builds to the Play Store using GitHub Actions.

In this chapter, we’re going to cover the following main topics:

  • Setting up GitHub Actions
  • Running lint checks and tests on GitHub Actions
  • Deploying to Play Store using GitHub Actions

Technical requirements

To follow the instructions in this chapter, you will need to have Android Studio Hedgehog or later (https://developer.android.com/studio) downloaded.

You can use the previous chapter’s code to follow the instructions in this chapter. You can find the code for this chapter at https://github.com/PacktPublishing/Mastering-Kotlin-for-Android/tree/main/chapterfourteen.

Setting up GitHub Actions

Before we can understand GitHub Actions, we need to understand what CI/CD is. This is a process that allows us to automate the building, testing, and deployment of our code to production. CI/CD not only automates these processes but also integrates them into a single coherent pipeline. This ensures that code changes are more reliable and stable when deployed. The definition should emphasize the role of CI/CD in facilitating frequent and reliable updates. This is an especially important process as it aims to improve the speed, efficiency, and reliability of how we deliver our software.

Benefits of CI/CD

Let’s go through some of the benefits of CI/CD:

  • Fast release cycles: CI/CD allows us to release our software faster and more frequently. This is because we are automating the process of building, testing, and deploying our code.
  • Increased collaboration: Since a lot of the processes are automated, we can focus on the code and the features...

Running lint checks and tests on GitHub Actions

In Chapter 11, we learned how to run lint checks on our project using shell commands on the terminal. We have also learned how to write tests for our code base. In this section, we are going to run the format, lint checks, and tests on our newly created actions and we will do all of this step by step:

  1. First, we will add the ktlintCheck step:
    - name: Run ktlintCheck
      run: ./gradlew ktlintCheck
      working-directory: ./chapterfourteen

    In this code, we have added a step called Run ktlintCheck. This step will run the ktlintCheck command, which will check whether our code is formatted correctly. This step fails if our code is not formatted correctly.

  2. Next, we add the detekt step:
    - name: Run detekt
      run: ./gradlew detekt
      working-directory: ./chapterfourteen

    In this step, we run the detekt command, which will run the detekt checks on the code that we set up earlier in Chapter 11. This step fails...

Deploying to Play Store using GitHub Actions

In Chapter 13, we learned how to deploy our app to Google Play Store using Google Play Console. However, in that chapter, we did it manually. In this chapter, we are going to learn how to deploy our app to Google Play Store using GitHub Actions. We are going to use the Google Play Publisher action to deploy our app to Google Play Store. This action is available in GitHub Marketplace.

Before we can write our workflow, we need to do some setup. We need to create a service account on our Google Play Store account. We can do this by following these steps:

  1. Configure the service account in Google Cloud Platform by following these steps:
    1. Navigate to https://cloud.google.com/gcp.
    2. Navigate to IAM and admin | Service accounts | Create service account.
    3. Pick a name and add appropriate permissions, for example, owner permissions.
    4. Open the newly created service account, click on the Keys tab, and add a new JSON type key.
    5. When the key is successfully...

Summary

In this chapter, we learned how to use GitHub Actions to automate some manual tasks, such as deploying new builds to the Play Store. Additionally, we learned how to run lint checks and tests on CI/CD pipelines and push builds to Google Play Store using GitHub Actions.

In the next chapter, we will learn about techniques to improve our apps by adding analytics, using Firebase Crashlytics, and using cloud messaging to increase user engagement in our apps. Additionally, we will learn some tips and tricks for securing our apps.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Kotlin for Android 14
Published in: Apr 2024Publisher: PacktISBN-13: 9781837631711
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Harun Wangereka

Harun Wangereka is a Google Developer Expert for Android and an Android engineer with over seven years of experience and currently working at Apollo Agriculture. Harun is passionate about Android development, never tired of learning, building the tech community, and helping other developers upscale their skills. He is a co-organizer at Droidcon Kenya and a former Kotlin Kenya and Android254 co-organizer. Through these communities, he has been able to impact thousands of developers. He is also an Android author at Kodeco where he has written 8 articles, published a book; Saving Data on Android, Second Edition, and is also a video course instructor. He has given numerous sessions on Android and Kotlin across different communities worldwide.
Read more about Harun Wangereka