← All slides 1 / 31

Intro to Continuous Integration (CI)

  Or how to automate the boring parts?

Slide image

About Me 👨‍💻

- @rohit_gohri

- rohit-gohri

🕕 🕙 🕛 🕞

What Is Continuous Integration?

Why should you care?

  Well, have you seen or heard any of these?

Slide image

Slide image

So, why should you care?

  • Single Source of Truth
  • Enforce Rules
  • Faster/Better Code Reviews

Prerequisites for CI

  • Automated Setup/Containerization
  • Testability
  • Reproducibility
  • Culture

Tools of the Trade 🧰

Slide image

Comparison

| | | | Slide image | Slide image | Slide image | Slide image

| |----------------------------------|-|-|----------------|-------------------------|----------------|--------------------| | Free Tier | | | 2,000 min/month | 2,000 min/month | - | 1 concurrent build | | Type | | | SaaS | SaaS/Self Hosted | Self Hosted | SaaS | | Run | | | Commands + Actions | Docker* | Plugins | Commands | | Integrations | | | Github | Gitlab + Any Git server | Any Git server | Github* |

Pipelines & YAML

Demo

https://github.com/rohit-gohri/hello-world-ci
   

Slide image

<span>&nbsp;&nbsp;&nbsp;</span>

Let's see some pipeline results

How did this happen?

Let's look at one example config: .github/workflows/nodejs.yml

nodejs.yml — Github Actions

Code step 1 of 6: nodejs.yml — Github Actions
name: Node CI

on:
- pull_request
- push

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1

    - name: Use Node.js 12.x
      uses: actions/setup-node@v1
      with:
        node-version: 12.x

    - name: Install node_modules
      run: |
        npm ci

    - name: Lint the code
      run: |
        npm run lint

    - name: Run tests
      run: |
        npm test
      env:
        NODE_ENV: test

    - name: Build site
      run: |
        npm run build

Let's add a new stage

report-coverage: npx codecov

Old File — Github Actions

Code step 1 of 2: Old File — Github Actions
    - name: Run tests
      run: |
        npm test
      env:
        NODE_ENV: test

    - name: Build site
      run: |
        npm run build

Old File

    - name: Run tests
      run: |
        npm test
      env:
        NODE_ENV: test

    - name: Build site
      run: |
        npm run build

With coverage

    - name: Run tests (with coverage)
      run: |
        npm test -- --coverage
      env:
        NODE_ENV: test
    
    - name: Upload coverage
      run: npx codecov
      env:
        CODECOV_TOKEN:  ${{ secrets.CODECOV_TOKEN }} 

    - name: Build site
      run: |
        npm run build

Slide image

Some Advanced Usage Patterns

Publishing an npm module

On every release

On every tag — Github Actions

Code step 1 of 2: On every tag — Github Actions
on:
  push:
    tags:
      - 'v*'

Publishing docs to Github Pages

On every release

Build Docs — Drone.io

Code step 1 of 2: Build Docs — Drone.io
- name: docs
  image: node:12
  commands:
  - yarn docs
  when:
    event:
    - tag

Code Deployments

Using PM2's deploy feature

Deploy the Code — Gitlab CI

deploy:
  stage: deploy
  script:
    - pm2 deploy dev

Trigger Other Pipelines

Perform integration tests across API and frontend

Trigger Downstream Pipelines — Gitlab CI

trigger-consumer:
  stage: downstream
  trigger: user/api-consumer
      
trigger-frontend:
  stage: downstream
  trigger: 
    project: user/project-frontend
    branch: dev

Links

Made With

Mdx-Deck: https://github.com/jxnblk/mdx-deck/

Code Surfer: https://github.com/pomber/code-surfer

Links

🖼 Presentation

https://rohit.page/slides/ci

💻 Repository

https://github.com/rohit-gohri/hello-world-ci

- @rohit_gohri

- rohit-gohri

The End

🥳