DEV Community

Maxim Nosov ✪
Maxim Nosov ✪

Posted on

Continuous integration pipeline

Overview

This week I've been working on setting github CI(Continuous integration) workflow, as well as wrote tests for another project.

Workflow set up

To set up workflow I added nodeJS.yml file that runs on any push or PR to main branch.

nodeJS.yml file:

name: Node.js CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x, 16.x, 18.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test

Enter fullscreen mode Exit fullscreen mode

The structure of the file may look complex at first glance, but it turned out it's very easy-to-read.

Writing tests to another project

It was very enjoyable process: talking with maintainer, making the suggestions in the code that he asks.

For me, I was very lucky to have a great partner, who has a very clean and concise project with appropriate code. It didn't take much time to understand how the code works.

For my PR I did basic tests checking the functions for unexpected output.

I got experience writing tests for another project, fixing the code, while maintainer got experience reviewing my code.

Tests, test and tests

As I see, it's never enough of writing tests, but we can and we should cover the basics of testing to prevent our tool from unexpected behavior.

It's very important to collaborate with your peers, so they can test your project. They might find some issues, that you could never find on your own :)

Continuous integration is a must

CI saves us a lot of time. For example, if someone makes a PR to the project, he can see that his code didn't pass the tests. Hence, he could immediately go and make necessary changes in the code.

Automation

It's a great practice to automate repetitive things. With the help of github CI workflow we could save our time, write the code once and let it do the work for us.

Top comments (0)