Skip to main content

๐Ÿ—๏ธ Integrating the Early CLI for Repository Coverage

The Early Repository CLI enables one-shot or scheduled test generation for individual files or entire folders โ€” ideal for boosting legacy coverage, validating a single module, or running scheduled cleanup jobs.


๐Ÿ”ง Setup Overviewโ€‹

1. Install the CLIโ€‹

npm install -g @earlyai/cli

2. Configure Required Inputsโ€‹

Use environment variables or CLI flags:

  • API_KEY โ€” Early API key

  • TOKEN โ€” SCM token

  • TARGET_DIRECTORY โ€” Path to scan (a single file or a directory, e.g., src/utils/math.ts or src/)

  • REF_NAME โ€” Branch name

  • Optional: AUTO_COMMIT, MAX_CONCURRENCY, NODE_OPTIONS, etc.

  • Token Permissions

  • SCM Support

  • Memory Tuning


3. Run the CLIโ€‹

early generate-for-project

๐Ÿงช GitHub Actions Exampleโ€‹

name: early-folder-coverage

on:
workflow_dispatch:
schedule:
- cron: "0 9 * * 1"

jobs:
folder-coverage:
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

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

- run: npm install
- run: npm install -g @earlyai/cli

- name: Generate tests
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.REPO_TOKEN }}
TARGET_DIRECTORY: src/
REF_NAME: ${{ github.ref_name }}
NODE_OPTIONS: --max-old-space-size=5120
run: early generate-for-project

๐Ÿงช Jenkins Exampleโ€‹

pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat-token')
NPM_TOKEN = credentials('github-npm-token')
TARGET_DIRECTORY = 'src/services'
REF_NAME = 'main'
NODE_OPTIONS = '--max-old-space-size=5120'
}
stages {
stage('Install Node.js') {
steps {
sh 'curl -fsSL https://deb.nodesource.com/setup_20.x | bash -'
sh 'apt-get install -y nodejs'
}
}
stage('Authenticate NPM') {
steps {
sh '''
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
'''
}
}
stage('Install CLI') {
steps {
sh 'npm install -g @earlyai/cli'
}
}
stage('Generate Folder Tests') {
steps {
sh 'early generate-for-project'
}
}
}
}

โœ… Success Criteriaโ€‹

  • New test files appear in the target folder
  • Logs include coverage analysis and test generation
  • Pipeline exits cleanly with no errors
  • Coverage improves for previously low-tested areas


๐Ÿงต Next Stepsโ€‹