Skip to main content

โš™๏ธ Integrating the Commit CLI Agent in Your CI/CD Pipeline

This guide walks you through integrating the Early Commit CLI Agent into push-based CI workflows such as GitHub Actions, Jenkins, or CircleCI.

For when and why to use this agent, see When to Use Which Agent โ†’


๐Ÿ› ๏ธ Step-by-Step Setupโ€‹

1. Install the CLIโ€‹

Install the CLI globally in your job:

npm install -g @earlyai/cli

โ†’ See NPM Authentication โ†’


2. Authenticate with Source Controlโ€‹

Make sure your TOKEN and NPM_TOKEN have the right permissions.

โ†’ See:


3. Set Required Environment Variablesโ€‹

Your CI pipeline must provide:

VariableDescription
API_KEYEarly-provided API key
TOKENSource control token (GitHub, Bitbucket)
REF_NAMEBranch name (e.g., main)
COMMIT_HASHSHA of the commit to analyze

โ†’ See Configuration Options


4. Call the CLIโ€‹

Use the following command in your job:

early generate-commit

This will:

  • Analyze changed files from the commit
  • Generate AI-based unit tests
  • Auto-commit the result (if configured)

๐Ÿงช Example: GitHub Actionsโ€‹

name: early-catch

permissions:
contents: write
packages: read

on:
push:
branches:
- main

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout target repo
uses: actions/checkout@v4

- name: Setup Node.js (v20)
uses: actions/setup-node@v4
with:
node-version: 20

- name: Authenticate NPM
run: |
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc

- name: Install CLI
run: npm install -g @earlyai/cli

- name: Generate tests with EarlyAI
env:
API_KEY: ${{ secrets.EARLY_SECRET_TOKEN }}
TOKEN: ${{ secrets.REPO_TOKEN }}
REF_NAME: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
NODE_OPTIONS: --max-old-space-size=5120
run: early generate-commit

๐Ÿงช Example: Jenkinsโ€‹

pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat-token')
REF_NAME = 'main'
COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
NODE_OPTIONS = '--max-old-space-size=5120'
}
stages {
stage('Install CLI') {
steps {
sh '''
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
npm install -g @earlyai/cli
'''
}
}
stage('Generate Tests') {
steps {
sh 'early generate-commit'
}
}
}
}

๐Ÿ’ก Tipsโ€‹


โœ… Success Criteriaโ€‹

  • Test files appear in the commit
  • Logs show generation summary
  • CI job completes without errors

๐Ÿงต Next Stepsโ€‹