/TravisCI-ePortfolio

Travis CI E-Portfolio for SE class 2021

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

Build Status

Travis CI ePortfolio

Travis CI Logo

Tabel of Content

  1. Introduction
  2. Continuous Integration
  3. Travis CI
    1. What is Travis CI?
    2. Features
    3. Disadvantages
  4. Getting Started
  5. .travis.yaml
  6. About this example
    1. Local Usage
    2. Badges
  7. More

Introduction

Testing your work and not wildly adding new functionality is an important aspect of successfully developing software. Otherwise, you and your software will end up in "integration hell". And look just like these design fails, where the integration was not well thought out:

drawing

Testing your software is essential but costs a lot of time and therefore money. A lot of repetitive tasks have to be done. For example, the code must be compiled, bundled and the tests must be executed. And if you are working in a team you can't rely on the other developers. Likely someone will eventually forget the testing before pushing their commit. That's why you would have to test after every single new pull. And this is where Travis CI as a Continuous Integration provider comes into play.

Continuous Integration

Continuous integration (CI) describes the process of continuously merging small components and features to form an application. The goal is to increase software quality, through early detection of errors. For this purpose every single commit the software is built, automated tests are performed and software metrics are created to measure software quality (e.g. code coverage). This entire process is triggered automatically by checking into the version management system. After just a few minutes the developer receives feedback as to whether the quality requirements have been achieved or not. Continuous Delivery (CD) is a further development of CI. Here the software will even be delivered immediately to the customer.

Advantages:

  • Problems/Errors are quickly noticed
  • Permanent availability of an working demo
  • Shorter check-in intervals are generally advantageous, as this reduces the amount of merging effort required.

Travis CI

1. What is Travis CI?

Travis CI is a cloud hosted CI service that is useable with GitHub. It is easy to set up and free to use for public projects. About a million projects are already being verified with Travis CI and also in future Travics CI promises to remain free of charge.

In the picture below you can see a sample Travis CI worker. After a commit is pushed to GitHub, Travis CI triggers a new build on their servers. The necessary dependencies are loaded and the software is built. After this, Travis CI executes some predefined tests. If the build passes: Hooray!

Travis CI is also capable of deploying your code and notifying your team.

worker

2. Features

  • Open Source
  • Easy setup & configuration
  • Support for +21 languages
  • Deployment on multiple cloud services (AWS, Heroku...)
  • Encrypted environment variables
  • Parallel builds on multiple platforms
  • Clean virtual machines after every build
  • CLI client
  • Fast and reliable
  • Free to use for public GitHub projects

3. Disadvantages:

  • No support for own infrastructure
  • No high security
  • No build pipelines
  • Debit Card for authentication required

Getting Started

  1. Sign in on travis-ci.com (You can use your GitHub-Account)
  2. Authorize Travis CI

  1. Activate GitHub Apps Integration

  1. Install Travis CI on all repositories or only on selected ones

  1. Now you need to select a plan. In order to prevent misuse, Travis CI will need your debit card information even for the free plan

  2. Create a .travis.yaml in the root folder of your project. More information is provided below

  3. Now you simply push a commit to trigger a build and testing of your application via Travis CI

.travis.yaml

The .travis.yaml (or .yml) is the heart piece of your CI setup. This is where most of the configuration is done.

For example Travis CI needs to know the programming language of our application:

language: go

And the version:

language: node_js
node_js:
  - "4"

Pick the operating system of your machine:

os: osx

os: linux
dist: trusty

Declare custom commands:

before_install:
  - sudo apt-get update -q
  - sudo apt-get install gcc-4.8 -y

script: make test
before_script: make pretest
after_script:  make clean

before_script:
  - npm customTest

Set environment variables:

env:
  - "user=master"
  - "password=supersecure"

Via the travis CLI-tool, you can setup encrypted variables:

env:
  global:
    - secure: eslojc6DH5yMcfFjUiHpDYVLqxD+aDWsdNSi3CKavoZA44E...

You can use Docker: 🐳

services:
  - docker

before_install:
  - docker pull ubuntu:20.04

Run multiple jobs:

jobs:
  include:
    - name: "Lint"
      install: npm ci
      script: npm run lint

    - name: "Unit tests"
      install: npm ci
      script: npm run test:ci

    - name: "Build docker image"
      services:
        - docker
      install: skip
      script: docker build -t project:test .

Setup notifications:

notifications:
  email:
    - sebastian@gmail.com

In order to enhance your software quality, you can also integrate tools like Coveralls, DeepSource and 3rd Party Apps.

About this example

This is a very basic node.js project that uses vows as testing framework. In this project we just have a small function that is checked for correct output.

Local Usage

Make sure you're in the root directory.

$ npm i
$ npm test

As you can see below, we did not need to define these commands in the .travis.yml, since Travis can run these by default.

language: node_js
node_js:
  - node
  - "lts/*"
cache: npm

Badges

Here is a status icon showing the state of this main branch. This badge is provided by Travis CI and as you can see, the build is passing:

Build Status

More

For more information have a look on the documentation of Travis CI.