continuous integration

What is CI (continuous integration)

Continuous integration refers to the build and unit testing stages of the software release process.
Every revision that is committed triggers an automated build and test.

CI

Travis CI + Github + Firebase + Angular 2

  1. Firebase init in project
  2. Writing code in local repo
  3. Pushing to Github repo
  4. Building code production in Travis CI
  5. Deploying production code to Firebase hosting

Firebase init

Before using Google Firebase, need to apply for
firebase account.

There are many features which Firebase provides for us, such as Authentication,
Database, Storage, Hosting…

In this blog, only need to use Hosting feature, which is free.

Do the Firebase initialization in the existing project directory

1
2
3
npm install --save firebase-tools
firebase init

Following the firebase init instruction to config your project,
for my case, I’m building an Angular2 project, so I choose dist as my public
directory.

After the initialization, need an access token for CI as environment variable.
Using with CI Systems

then do a deploy test:

1
firebase deploy

Using Travis CI

Greate documentation the complete beginner here

  • Connecting Github account to Travis CI
  • Choosing Github project repo to async
  • Setting Firebase Token as the environment variable in Travis
  • Writing a travis.yml config file in your project directory
    Customizing the Build

In order to deploy project from Travis, inside the travis.yml, add:

1
2
after_success:
- firebase deploy --token ${FIREBASE_TOKEN}

write script to build your project:

1
2
3
script:
- npm install
- npm run build:prod

Push change to Github, build prod on Travis CI, Deploy to Firebase

Done!

Everything is automated!

Awesome! 😎