Implementing CI with GitHub Actions Workflow

cleobnvntra

Cleo Buenaventura

Posted on November 17, 2024

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.

💖 💪 🙅 🚩
cleobnvntra
Cleo Buenaventura

Posted on November 17, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related