forlooptanzania / ride-my-way

Car pooling app (of developers) by developers for developers in Tanzania
22 stars 6 forks source link

Getting started with Travis CI #41

Open lupyana opened 5 years ago

lupyana commented 5 years ago

Getting started with Travis

What / Who Is Travis? Why do I need it?

Have you ever written code for an app, It works. Then you added more code to do more things. The app gets more complex and bigger as time goes. Imagine you have like 100 functionalities in your app. You want to check them all. How are you gonna do it.?

Meet travis

Your own personal butler to test your code for you. hehehehe But seriously what is travis ? Well travis is a service that deals with two things continuous integration (CI) and continuous deployment (CD).

We will focus on CI, for now The idea behind continuous integration is that CI will automatically run your tests ( unit tests, etc ) and other checks for you.

Why should you care?

You are not a caveman. If you have the time and patience to go through all 100 functionalities, knock yourself out. If you are lazy, smart and a bad ass, you will use CI. cavemen

Travis CI to the rescue

As the name suggests,CI stands for Continuous Integration which is an integrated tests that runs continuously on every time when someone pushes a commit (or mostly when opening a Pull Request). It helps us to automate the testing process. But this doesn't stop you from doing your tests localy.

Setup

The warmup

By now you have noticed that I have mentioned tests a couple of times. Yes tests are a pre requisite to this. You need to have atleast a few tests setup to proceed.

Ready set go!

Travis requires instruction to be told what to do. We achieve this using a travis.yml file.

This is where it gets interesting

The .travis.yml file is a configuration file. it contains key and value pairs that have a certain meaning. Here is how it looks like but not limited to.

language: node_js
node_js:
  - "version number"
script:
  - "do something"

This is like the bare minimum you need. More config can be found here

So what does this mean?

How i did it

language: node_js
node_js:
  - "8"
script:
  - cd backend && yarn install && yarn test

What is happening here?

Moment of truth

See travis docs