Perfectus: CircleCI Integration

Victor Apoyan
4 min readAug 16, 2020

CircleCI is a modern continuous integration and continuous delivery (CI/CD) platform. Let’s integrate it in the Perfectus application.

Overview

  • Get Started
  • Environment Variables
  • Generating a Status Badge

Get Started

In order to start building Perfectus, first, we need to Sign Up, this can be done either with GitHub, GitLab, or Bitbucket accounts.

If you are using GitHub, then you can choose which repositories you what to build: All or Public. After selecting the type of repository you will be asked to authenticate yourself with the GitHub account.

After you are successfully Signed Up, you will see all your repositories (or the only public, depending on what have you selected while Sign Up) and from the list, you can press on the “Set Up Project” button for the repository which you want to build.

Now you need to select the language (in Perfectus case it will be Android)

After selecting the language a default config.yml file will be generated

In the section steps, you can specify the tasks which you want to execute for your build. You can download the file from the CircleCI and put it in your project, then you need to click the “Use Existing Config” button. Or you can click on the “Add Config” button which will create a separate branch called “circleci-project-setup” and push the config.yml file there.

I have created tools/circle-ci branch where you can find the config.yml file.

In my case, I have put config.yml to the .circleci folder which is located in the root directory. After this step, everything that will be pushed will trigger the build on the CirecleCI side. If you have a simple “Hello World!” Android project, these steps should be enough to start building it.

Environment Variables

But these steps are not enough for Perfectus application, as it’s using Firebase services and needs “google-services.json” file, which is not committed as it contains private secret keys. So what to do?

The solution is using Environment Variables provided by CircleCI

Environment variables let you add sensitive data (e.g. API keys) to your jobs rather than placing them in the repository. The value of the variables cannot be read or edited in the app once they are set.

In order to add environment variables, open the Project and press on the “Project Settings” button, and then select the “Environment Variables” tab.

But in Perfectus case “google-services.json” is not a string key, it’s a file.

To solve this we need to do the following:

  • Encode “google-services.json” file in base64. You can use online decoders
  • Add an environment variable (in my case name is GOOGLE_SERVICES)
  • Decode the variable and create “google-services.json” file on the run, buy adding the following step to the config.yml

Push your changes and wait for the build starting on the CirecleCI side.

Congratulations, you have Green Build.

Generating a status badge

Let’s add a status badge to the project, so it’s showing in the GitHub current build status.

Open the README.md file of your project and add the following line

The template is look like

Here I am adding the badge to develop branch by specifying /tree/develop after the project name. If you omit this part, then the badge will show build status for all branches.

Conclusion

I think CircleCI is a great tool, it always to have a continues build for free and configuring any server. All you need is just few clicks and you have all what you need.

--

--