Logo

dev-resources.site

for different kinds of informations.

Implementing CI with GitHub Actions Workflow

Published at
11/17/2024
Categories
github
githubactions
opensource
jest
Author
cleobnvntra
Author
11 person written this
cleobnvntra
open
Implementing CI with GitHub Actions Workflow

For this week's activity, I am tasked to further improve my project GENEREADME, by adding unit tests and implementing Continuous Integration through GitHub Actions workflow.

GitHub logo cleobnvntra / genereadme

GENEREADME is a command-line tool that takes in a source code file and generates a README.md file that explains the code in the file by utilizing an LLM.

Contrubutions

Contributions to GENEREADME are welcome! Please checkout CONTRIBUTING.md for guidelines on setting up the environment, how to run and test the tool, and submitting changes.

GENEREADME

GENEREADME is a command-line tool that takes in a file, processes it, and generates a README file with an explanation or documentation of the contents of the file. The tool utilizes OpenAI chat completion to analyze the file and generate content.

genereadme demo

Usage

The tool currently supports Groq and OpenRouter, which uses Groq by default. A valid API key for the appropriate provider must be provided.

Provide a valid API key either by creating a .env file or through the -a or --api-key flag when using the command:

API_KEY=API_KEY

or

genereadme <files> -a API_KEY
genereadme <files> --api-key API_KEY

Install the dependencies:

npm install -g

Run the tool with the existing sample files or start using your own:

genereadme <files&gt
genereadme examples/sum.js
genereadme examples/createUser.js
…

GitHub Actions Workflow

I primarily used the Node.js setup for my GitHub Actions, which generates a .yml.

name: Node.js CI

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

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x, 20.x, 22.x]

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

This will run the test whenever changes are either pushed or merged by pull requests to the main branch.

Contributing to OptimizeIt

For this task, I am also required to make a contribution to another project by adding more possible tests. I chose to contribute to OptimizeIt.
Since this project also uses jest for unit testing, and nock for mocking, it wasn't as difficult adding another test. However, the main challenge is that my partner has already written A LOT of test cases, having a 98% overall coverage. So I had to look for something that is either not tested or any lines that weren't covered, to which I ended up going for the latter.

The impact of Continuous Integration

Setting up CI for GENEREADME has been transformative. By automating tests for every push or pull request, it ensures that new changes don’t break existing functionality. For GENEREADME, this means maintaining stability across multiple Node.js versions and saving time on manual testing. CI enhances collaboration, enforces best practices, and builds confidence in the project’s quality, making it an essential addition for sustainable development.

jest Article's
30 articles in total
Favicon
Why You Hate Test Coverage
Favicon
Mockando Constantes em Testes com Jest: Um Exemplo Prático
Favicon
Taming the CI Beast: Optimizing a Massive Next.js Application (Part 1)
Favicon
Testing a GraphQL Application with Jest and SuperTest
Favicon
[Boost]
Favicon
How to write unit test in react?
Favicon
4. Testing (async) searchParams with Jest in Next 15
Favicon
3. How to setup Jest in a Next 15 project (+ eslint for testing)
Favicon
Sharding Jest tests. Harder than it should be?
Favicon
Migration from Jest to Vitest: A Real-World Experience with 2900+ Tests
Favicon
Mastering Jest: A Guide to Efficient JavaScript Testing
Favicon
Guide - Setting Up Jest for Unit Testing in a TypeScript React Project
Favicon
Testes Unitários com Jest
Favicon
5. Mocking usePathName, useSearchParams and useRouter with Jest in Next 15
Favicon
🛠️ Writing Reliable Code from the Ground Up !
Favicon
How To Test Your JavaScript Application With Jest Framework?
Favicon
Mocking with Jest and typescript - a cheatsheet
Favicon
Mastering Testing in React with Jest and React Testing Library
Favicon
Exploring Snapshot Testing in Jest: Pros and Cons
Favicon
Implementing CI with GitHub Actions Workflow
Favicon
How to write jest test cases for react component?
Favicon
Testing LLM Applications: Misadventures in Mocking SDKs vs Direct HTTP Requests
Favicon
Creating tests in real database with NestJS, TypeORM and PostgreSQL
Favicon
Let’s Make Jest Run Much Faster
Favicon
Testing and Debugging: Basic Tools and Techniques for Effective Full-Stack Tests
Favicon
Comparing Jest, React Testing Library, and Playwright: Testing Approaches for React Applications
Favicon
Error in Jest integration with Vue js
Favicon
Declarative Programming
Favicon
Maximize a Performance dos Seus Testes com Jest e Vitest
Favicon
Introduction to Jest: Unit Testing, Mocking, and Asynchronous Code

Featured ones: