DEV Community

Krinskumar Vaghasia
Krinskumar Vaghasia

Posted on

Adding CI tests for my open source.

So last week we added tests in my open source project. So this week we will be running these tests on every PR and commit we make and make sure that the new changes to be merged are not breaking anything. So how did we do this.

Github Actions

GitHub actions provides us smooth compatibility to run these using a yaml file that will be stored in the .github/workflows file. Added content in the file was not very difficult for me because I did a similar feature in one my contributions for hacktoberfest.

So the content of my yaml files are as below:

name: PR Lint

on:
  pull_request:
    branches:
      - main
      - develop
      - feature/*
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run test
Enter fullscreen mode Exit fullscreen mode

I tested this by making commits and also a PR and it worked in each instance.

Partner contribution

Now it was my turn to test my classmates's CI pipeline and make sure their setup is correct and complete. So I raised this PR. Besides the CI part, it was a learning curve for me because I had never made tests on python before. I kinda copied the syntax of what they had for the tests that were already there. I was able to see that my tests were passing when I raised the PR. The green check when a CI passes is always satisfying. I used Jest which is a popular javascript testing framework whereas they used something called pytest.

Conclusion

I think CI is very cool and makes our life easier. Now we dont have to download every branch and test is locally before merge the PR. That part is handled by github. This way reviewers can focus more on the main changes that were made in the PR. While I was researching about CI and github actions, I found out that we can add more cool stuff in our workflow like linting and deploying which would be very cool.

Top comments (0)