CI/CD is one of the most important practices of XP. Having set this up since the beginning can help in identify and fix issues earlier and faster time to market. Here at Saeloun, we make sure it gets set up since the start of the project.
Let us start setting up a CI/CD for
Expo react-native application.
First, we will set up the CI process
so it gets run on each of the branches we create
and then we will set up the CD process specific to the develop
or main
branch
because we need to create builds for the latest changes that
get merged to develop
or main
.
Continuous Integration
- As we are using
Github Actions,
we need to create a
ci.yml
file inside the.github/workflows
folder at the root of the project. - Add the name of the workflow and the action on which we need to trigger the workflow.
- As Workflows are composed of Jobs
we need to add a Job with the name
lint-and-test
as we will be linting the code and running the test cases. Also, we need to specify the type of machine that will process a job in our workflow.
- As Job is composed of a series of steps,
we need to add steps to cache and install the node modules,
and finally run the lint and test cases.
So, this is what our final
ci.yml
file will look like.
Once we add this file and push the code, Github Actions will run the workflow and we can see the results on Github Actions Tab.
Continuos Deployment
To start with Continuos Deployment, we need to first create an EXPO_TOKEN
from expo.dev
and add it to the GitHub project’s settings
so that Expo allows GitHub Actions to create a build.
- Navigate to https://expo.dev/settings/access-tokens.
- Click “Create” to create a new access token.
- Copy the token generated.
- Navigate to https://github.com/your-username/your-repo-name/settings/secrets/actions, replacing “your-username” and “your-repo-name” with your project’s info.
- Click “New repository secret”
- Make the secret’s name “EXPO_TOKEN”, then paste the access token in as the value.
Once this is done,
create the eas.json
file in the project root.
This file specifies different profiles
which can be used to create builds for different environments
for example in our case
we created a preview
profile for development builds.
It also specifies the type of packaging we need to use,
credentialsSource
to sign the build,
and the distribution
channel.
In our case, credentialsSource
is set to remote
which means Expo will automatically
create the credentials to sign the app.
Now we are ready to create a GitHub Actions workflow to create a build.
- Create a
cd.yml
file inside the.github/workflows
folder at the root of the project. - Add the name of the workflow and action along with the branch name on which we need to trigger the workflow.
- Add the jobs
build
withubuntu-latest
as a runner machine. - Add a step to fetch
EXPO_TOKEN
from the project’s settings. - Add a step to set ENV.
- Add a step to install the expo.
- Add the steps to cache and install the node modules.
- Finally, add a step to create a build.
Here is what our final build.yml
looks like:-
As it can be seen from the Publish build command
we are creating an android build using the preview
profile as mentioned above.
Now, once we push this file to develop branch, GitHub Actions will run this workflow and trigger the build to be created on the Expo platform. Once the build is created, we can always download it from Expo builds dashboard.