How to build and publish your React Native Android applications using GitLab CI

I'm currently setting up CI for my company and think it'd be a good idea to share (the results of) the hoops I went through :)

Objective

The tutorial would allow a person with a React Native project to:

  • add CI (builds, tests) + CD (publishing to Play Store) with a simple .gitlab-ci.yml (making use of existing container in Container Registry) or
  • fork container-building repos to have a customised setup (again, with CR)

What is your audience?

  • React Native developers with no specific requirements to experience: those who'd like to easily set up a CI/CD pipeline to automate and foolproof their deployment process
  • Developers or devops who want to have a customized build / test / rollout process for their RN apps, with no lock-in and option to self-host

What are the requirements?

No specific hardware or software requirements beyond those necessary to use GitLab.

"Scientific novelty"

  • React Native
  • [wip] Publishing to Play Store

In comparison to the blog post (blog-posts#28 (closed)):

  • Builds Docker image

In comparison to https://github.com/jangrewe/gitlab-ci-android:

  • Makes use of Container Registry

Currently functional

As stated earlier, I'm already working on implementation of this, and here's what currently works:

Future work

  • Multiple keys / multiple build jobs (various flavors)
  • Verify GPG signature before executing anything on runner

Proposal

Structure

Intro

Continuous Integration – a practice of automatically building and testing software on every push or merge (and before every merge) – allows you to quickly catch bugs or breakages; Continuous Delivery goes further with the concept by automatically deploying “good” builds to staging (or, in our case, to Google Play alpha track).

This post will guide you on setting up an effective CI/CD system for React Native Android apps on Gitlab CI with the power of Docker. You’ll be able to make the most of it if you’re already familiar with creating RN apps and git.

CI

1. Build debug flavour from clean repo
2. Build release
2.1 Build locally
2.1.1 Set up release keys
2.2 Build on CI
2.2.1 Set up deploy keys
2.2.2 CI env vars
2.2.3 Set up SSH, download keystore
3. Version with git

Somewhere: tests.

CD

4. Create initial entry for app on Play
5. Set up Play keys 
6. Auto publish
6.1 Locally
6.2 From CI
7. Automate filling Play metadata
8. Publish to different tracks depending on branch / tag

Conclusion

"You now know how to CI RN"

Example project

https://gitlab.com/wldhx/reactNativeGitlabCIAndroidCDTest. A secrets repository was also created but is not public for obvious reasons.

Edited by wldhx